Class: UsersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/crosstie/templates/authorization/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



6
7
8
9
10
# File 'lib/crosstie/templates/authorization/users_controller.rb', line 6

def index
  authenticate_any_role! :system, :admin
  @users = User.all
  @roles = current_user.managing_roles
end

#roleObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/crosstie/templates/authorization/users_controller.rb', line 12

def role
  authenticate_any_role! :system, :admin
  @user = User.find params[:id]
  operation, role = params[:operation].to_sym, params[:role].to_sym

  raise "role operation #{operation} undefined" unless operation.to_sym.in? Role::OPERATIONS
  raise "user role #{role} undefined" unless role.to_sym.in? Role::USER_ROLES
  raise "current user not in charge of #{role}" unless role.to_sym.in? current_user.managing_roles
  @user.send operation, role
  redirect_back :root, notice: "User #{@user.name} was #{operation}ed role #{role}"
rescue => exc
  redirect_back :root, notice: exc.to_s
end