Class: Integral::Backend::UsersController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Integral::Backend::UsersController
- Defined in:
- app/controllers/integral/backend/users_controller.rb
Overview
Users controller
Instance Method Summary collapse
-
#account ⇒ Object
GET /account Show specific users account page.
-
#block ⇒ Object
PUT /:id/block Block a user.
-
#create ⇒ Object
POST / User creation.
-
#edit ⇒ Object
GET /:id/edit Resource edit screen.
-
#notifications ⇒ Object
GET /:id/notifications.
-
#read_all_notifications ⇒ Object
PUT /:id/read_all_notifications.
-
#read_notification ⇒ Object
PUT /:id/read_notification.
-
#unblock ⇒ Object
PUT /:id/unblock Unblock a user.
-
#update ⇒ Object
PUT /:id Updating a user.
Methods inherited from BaseController
#activities, #activity, #destroy, #duplicate, #index, #list, #new, #show
Instance Method Details
#account ⇒ Object
GET /account Show specific users account page
18 19 20 21 22 23 |
# File 'app/controllers/integral/backend/users_controller.rb', line 18 def account @resource = current_user @resource.name, :backend_account_path render :show end |
#block ⇒ Object
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(('edit_success'), backend_user_path(@resource)) else respond_failure(('edit_failure'), 'edit') end end |
#create ⇒ Object
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(('creation_success'), backend_user_path(@resource)) else respond_failure(('creation_failure'), 'new') end end |
#edit ⇒ Object
GET /:id/edit Resource edit screen
11 12 13 14 |
# File 'app/controllers/integral/backend/users_controller.rb', line 11 def edit @resource.name, :backend_user_path I18n.t('integral.navigation.edit'), "edit_backend_#{controller_name.singularize}_path".to_sym end |
#notifications ⇒ Object
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_notifications ⇒ Object
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_notification ⇒ Object
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 |
#unblock ⇒ Object
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(('edit_success'), backend_user_path(@resource)) else respond_failure(('edit_failure'), 'edit') end end |
#update ⇒ Object
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 = resource_params .delete(:role_ids) unless policy(current_user).manager? if @resource.update() respond_successfully(('edit_success'), backend_user_path(@resource)) else respond_failure(('edit_failure'), 'edit') end end |