Class: Refinery::Authentication::Devise::Admin::UsersController

Inherits:
Refinery::AdminController
  • Object
show all
Defined in:
app/controllers/refinery/authentication/devise/admin/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/refinery/authentication/devise/admin/users_controller.rb', line 21

def create
  @user = Refinery::Authentication::Devise::User.new user_params.except(:roles)
  @selected_plugin_names = params[:user][:plugins] || []
  @selected_role_names = params[:user][:roles] || []

  if @user.save
    create_successful
  else
    create_failed
  end
end

#editObject



33
34
35
# File 'app/controllers/refinery/authentication/devise/admin/users_controller.rb', line 33

def edit
  @selected_plugin_names = find_user.plugins.map(&:name)
end

#newObject



16
17
18
19
# File 'app/controllers/refinery/authentication/devise/admin/users_controller.rb', line 16

def new
  @user = Refinery::Authentication::Devise::User.new
  @selected_plugin_names = []
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/refinery/authentication/devise/admin/users_controller.rb', line 37

def update
  # Store what the user selected.
  @selected_role_names = params[:user].delete(:roles) || []
  @selected_role_names = @user.roles.select(:title).map(&:title) unless user_can_assign_roles?
  @selected_plugin_names = params[:user][:plugins]

  if user_is_locking_themselves_out?
    flash.now[:error] = t('lockout_prevented', :scope => 'refinery.authentication.devise.admin.users.update')
    render :edit and return
  end

  store_user_memento

  @user.roles = @selected_role_names.map { |r| Refinery::Authentication::Devise::Role[r.downcase] }
  if @user.update_attributes user_params.to_h
    update_successful
  else
    update_failed
  end
end