2010-03-22 01:58:37 +01:00
|
|
|
class Admin::UsersController < Admin::BaseController
|
2011-06-09 22:03:27 +02:00
|
|
|
inherit_resources
|
|
|
|
|
2009-01-12 18:26:09 +01:00
|
|
|
def index
|
2016-03-04 19:03:52 +01:00
|
|
|
@users = params[:show_deleted] ? User.deleted : User.undeleted
|
2023-05-12 13:01:12 +02:00
|
|
|
@users = @users.sort_by_param(params['sort'])
|
2022-05-27 17:06:25 +02:00
|
|
|
|
2017-08-18 09:17:19 +02:00
|
|
|
@users = @users.includes(:mail_delivery_status)
|
2011-06-09 22:03:27 +02:00
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
send_data UsersCsv.new(@users).to_csv, filename: 'users.csv', type: 'text/csv' if request.format.csv?
|
2021-03-07 18:13:10 +01:00
|
|
|
|
2011-06-09 22:03:27 +02:00
|
|
|
# if somebody uses the search field:
|
2023-05-12 13:01:12 +02:00
|
|
|
@users = @users.natural_search(params[:user_name]) if params[:user_name].present?
|
2011-06-09 22:03:27 +02:00
|
|
|
|
2022-05-27 17:06:25 +02:00
|
|
|
@users = @users.page(params[:page]).per(@per_page)
|
2016-03-04 19:03:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
@user.mark_as_deleted
|
2023-05-12 13:01:12 +02:00
|
|
|
redirect_to admin_users_url, notice: t('.notice')
|
|
|
|
rescue StandardError => e
|
|
|
|
redirect_to admin_users_url, alert: t('.error', error: e.message)
|
2016-03-04 19:03:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def restore
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
@user.restore
|
2023-05-12 13:01:12 +02:00
|
|
|
redirect_to admin_users_url, notice: t('.notice')
|
|
|
|
rescue StandardError => e
|
|
|
|
redirect_to admin_users_url, alert: t('.error', error: e.message)
|
2009-01-12 18:26:09 +01:00
|
|
|
end
|
2014-10-18 17:52:06 +02:00
|
|
|
|
|
|
|
def sudo
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
login @user
|
|
|
|
redirect_to root_path, notice: I18n.t('admin.users.controller.sudo_done', user: @user.name)
|
|
|
|
end
|
2009-01-12 18:26:09 +01:00
|
|
|
end
|