1 class UserRolesController < ApplicationController
4 before_filter :authorize_web
5 before_filter :require_user
6 before_filter :lookup_this_user
7 before_filter :require_administrator
8 before_filter :require_valid_role
9 before_filter :not_in_role, :only => [:grant]
10 before_filter :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
24 # require that the user is an administrator, or fill out a helpful error message
25 # and return them to theuser page.
26 def require_administrator
27 unless @user.administrator?
28 flash[:error] = t'user_role.filter.not_an_administrator'
29 redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name
34 # require that the given role is valid. the role is a URL
35 # parameter, so should always be present.
36 def require_valid_role
38 unless UserRole::ALL_ROLES.include?(@role)
39 flash[:error] = t('user_role.filter.not_a_role', :role => @role)
40 redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name
45 # checks that the user doesn't already have this role
47 if @this_user.has_role? @role
48 flash[:error] = t('user_role.filter.already_has_role', :role => @role)
49 redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name
54 # checks that the user already has this role
56 unless @this_user.has_role? @role
57 flash[:error] = t('user_role.filter.doesnt_have_role', :role => @role)
58 redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name