Class: Integral::Backend::UsersController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/integral/backend/users_controller.rb

Overview

Users controller

Instance Method Summary collapse

Methods inherited from BaseController

#activities, #activity, #destroy, #duplicate, #index, #list, #new, #show

Instance Method Details

#accountObject

GET /account Show specific users account page



18
19
20
21
22
23
# File 'app/controllers/integral/backend/users_controller.rb', line 18

def 
  @resource = current_user
  add_breadcrumb @resource.name, :backend_account_path

  render :show
end

#blockObject

PUT /:id/block Block a user



78
79
80
81
82
83
84
# File 'app/controllers/integral/backend/users_controller.rb', line 78

def block
  if @resource.blocked!
    respond_successfully(notification_message('edit_success'), backend_user_path(@resource))
  else
    respond_failure(notification_message('edit_failure'), 'edit')
  end
end

#createObject

POST / User creation



27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/integral/backend/users_controller.rb', line 27

def create
  @resource = User.new(resource_params)
  @resource.define_singleton_method(:password_required?) { false }

  if @resource.valid?
    @resource = User.invite!(resource_params, current_user)
    respond_successfully(notification_message('creation_success'), backend_user_path(@resource))
  else
    respond_failure(notification_message('creation_failure'), 'new')
  end
end

#editObject

GET /:id/edit Resource edit screen



11
12
13
14
# File 'app/controllers/integral/backend/users_controller.rb', line 11

def edit
  add_breadcrumb @resource.name, :backend_user_path
  add_breadcrumb I18n.t('integral.navigation.edit'), "edit_backend_#{controller_name.singularize}_path".to_sym
end

#notificationsObject

GET /:id/notifications



53
54
55
56
# File 'app/controllers/integral/backend/users_controller.rb', line 53

def notifications
  load_more_url = notifications_backend_user_url(current_user, page: current_page+1) if current_user.notifications.count > current_page * Notification::Notification.per_page
  render json: { content: render_to_string(current_user.notifications.recent.page(current_page).decorate, cached: true), load_more_url: load_more_url }
end

#read_all_notificationsObject

PUT /:id/read_all_notifications



68
69
70
71
72
73
74
# File 'app/controllers/integral/backend/users_controller.rb', line 68

def read_all_notifications
  if current_user.notifications.unread.update_all(read_at: Time.now)
    redirect_to request.referrer
  else
    head :unprocessable_entity
  end
end

#read_notificationObject

PUT /:id/read_notification



59
60
61
62
63
64
65
# File 'app/controllers/integral/backend/users_controller.rb', line 59

def read_notification
  if current_user.notifications.find(params[:notification_id]).read!
    head :ok
  else
    head :unprocessable_entity
  end
end

#unblockObject

PUT /:id/unblock Unblock a user



88
89
90
91
92
93
94
# File 'app/controllers/integral/backend/users_controller.rb', line 88

def unblock
  if @resource.active!
    respond_successfully(notification_message('edit_success'), backend_user_path(@resource))
  else
    respond_failure(notification_message('edit_failure'), 'edit')
  end
end

#updateObject

PUT /:id Updating a user



41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/integral/backend/users_controller.rb', line 41

def update
  authorized_user_params = resource_params
  authorized_user_params.delete(:role_ids) unless policy(current_user).manager?

  if @resource.update(authorized_user_params)
    respond_successfully(notification_message('edit_success'), backend_user_path(@resource))
  else
    respond_failure(notification_message('edit_failure'), 'edit')
  end
end