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({
14 :role => @role, :granter_id => @user.id
15 }, :without_protection => true)
16 redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name
20 UserRole.delete_all({:user_id => @this_user.id, :role => @role})
21 redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name
26 # require that the user is an administrator, or fill out a helpful error message
27 # and return them to theuser page.
28 def require_administrator
29 unless @user.administrator?
30 flash[:error] = t'user_role.filter.not_an_administrator'
31 redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name
36 # require that the given role is valid. the role is a URL
37 # parameter, so should always be present.
38 def require_valid_role
40 unless UserRole::ALL_ROLES.include?(@role)
41 flash[:error] = t('user_role.filter.not_a_role', :role => @role)
42 redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name
47 # checks that the user doesn't already have this role
49 if @this_user.has_role? @role
50 flash[:error] = t('user_role.filter.already_has_role', :role => @role)
51 redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name
56 # checks that the user already has this role
58 unless @this_user.has_role? @role
59 flash[:error] = t('user_role.filter.doesnt_have_role', :role => @role)
60 redirect_to :controller => 'user', :action => 'view', :display_name => @this_user.display_name