1 class UserRolesController < ApplicationController
4 before_action :authorize_web
5 before_action :require_user
6 before_action :lookup_this_user
7 before_action :require_administrator
8 before_action :require_valid_role
9 before_action :not_in_role, :only => [:grant]
10 before_action :in_role, :only => [:revoke]
13 @this_user.roles.create(:role => @role, :granter_id => @user.id)
14 redirect_to :controller => "user", :action => "view", :display_name => @this_user.display_name
18 UserRole.delete_all(:user_id => @this_user.id, :role => @role)
19 redirect_to :controller => "user", :action => "view", :display_name => @this_user.display_name
25 # require that the user is an administrator, or fill out a helpful error message
26 # and return them to theuser page.
27 def require_administrator
28 unless @user.administrator?
29 flash[:error] = t "user_role.filter.not_an_administrator"
30 redirect_to :controller => "user", :action => "view", :display_name => @this_user.display_name
35 # require that the given role is valid. the role is a URL
36 # parameter, so should always be present.
37 def require_valid_role
39 unless UserRole::ALL_ROLES.include?(@role)
40 flash[:error] = t("user_role.filter.not_a_role", :role => @role)
41 redirect_to :controller => "user", :action => "view", :display_name => @this_user.display_name
46 # checks that the user doesn't already have this role
48 if @this_user.has_role? @role
49 flash[:error] = t("user_role.filter.already_has_role", :role => @role)
50 redirect_to :controller => "user", :action => "view", :display_name => @this_user.display_name
55 # checks that the user already has this role
57 unless @this_user.has_role? @role
58 flash[:error] = t("user_role.filter.doesnt_have_role", :role => @role)
59 redirect_to :controller => "user", :action => "view", :display_name => @this_user.display_name