1class Admin::AdminUsersController < Admin::AdminController |
|
2 before_filter :require_sysadmin |
|
3 before_filter :find_user, only: %i[edit update destroy] |
|
5 rescue_from AdminUser::CannotDeleteCurrentUser do |
|
6 redirect_to admin_admin_users_url, alert: :user_is_current_user |
|
7 end |
|
9 rescue_from AdminUser::MustBeAtLeastOneAdminUser do |
|
10 redirect_to admin_admin_users_url, alert: :user_count_is_too_low |
|
11 end |
|
13 def index |
|
14 @users = AdminUser.by_name.paginate(page: params[:page], per_page: 50) |
|
15 end |
|
17 def new |
|
18 @user = AdminUser.new |
|
19 end |
|
21 def create |
|
22 @user = AdminUser.new(admin_user_params) |
|
24 if @user.save |
|
25 redirect_to admin_admin_users_url, notice: :user_created |
|
26 else |
|
27 render :new |
|
28 end |
|
29 end |
|
31 def edit |
|
32 end |
|
34 def update |
|
35 if @user.update(admin_user_params) |
|
36 redirect_to admin_admin_users_url, notice: :user_updated |
|
37 else |
|
38 render :edit |
|
39 end |
|
40 end |
|
42 def destroy |
|
43 if @user.destroy(current_user: current_user) |
|
44 redirect_to admin_admin_users_url, notice: :user_deleted |
|
45 else |
|
46 redirect_to admin_admin_users_url, alert: :user_not_deleted |
|
47 end |
|
48 end |
|
50 protected
|
|
52 def find_user |
|
53 @user = AdminUser.find(params[:id]) |
|
54 end |
|
56 def admin_user_params |
|
57 params.
|
|
58 require(:admin_user). |
|
59 permit(:password, :password_confirmation, :first_name, |
|
60 :last_name, :role, :email, :force_password_reset, |
|
61 :account_disabled) |
|
62 end |
|
63end |