Class: Admin::UsersController

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

Instance Method Summary collapse

Instance Method Details

#destroyObject



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

def destroy
  @user = User.find(params[:id])
  @user.mark_as_deleted
  redirect_to admin_users_url, notice: t('.notice')
rescue StandardError => e
  redirect_to admin_users_url, alert: t('.error', error: e.message)
end

#indexObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/admin/users_controller.rb', line 4

def index
  @users = params[:show_deleted] ? User.deleted : User.undeleted
  @users = @users.sort_by_param(params['sort'])

  @users = @users.includes(:mail_delivery_status)

  send_data UsersCsv.new(@users).to_csv, filename: 'users.csv', type: 'text/csv' if request.format.csv?

  # if somebody uses the search field:
  @users = @users.natural_search(params[:user_name]) if params[:user_name].present?

  @users = @users.page(params[:page]).per(@per_page)
end

#restoreObject



26
27
28
29
30
31
32
# File 'app/controllers/admin/users_controller.rb', line 26

def restore
  @user = User.find(params[:id])
  @user.restore
  redirect_to admin_users_url, notice: t('.notice')
rescue StandardError => e
  redirect_to admin_users_url, alert: t('.error', error: e.message)
end

#sudoObject



34
35
36
37
38
# File 'app/controllers/admin/users_controller.rb', line 34

def sudo
  @user = User.find(params[:id])
   @user
  redirect_to root_path, notice: I18n.t('admin.users.controller.sudo_done', user: @user.name)
end