1 class UserRolesController < ApplicationController
4 before_filter :authorize_web
5 before_filter :require_user
6 before_filter :require_administrator
9 # added a random nonce here which isn't predictable, making an CSRF procedure much, much more difficult.
10 if params[:nonce] and params[:nonce] == session[:nonce]
11 this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
12 if this_user and UserRole::ALL_ROLES.include? params[:role]
13 this_user.roles.create(:role => params[:role], :granter_id => @user.id)
14 redirect_to :controller => 'user', :action => 'view', :display_name => params[:display_name]
16 flash[:notice] = t('user_role.grant.fail', :role => params[:role], :name => params[:display_name])
19 @nonce = OAuth::Helper.generate_nonce
20 session[:nonce] = @nonce
25 # added a random nonce here which isn't predictable, making an CSRF procedure much, much more difficult.
26 if params[:nonce] and params[:nonce] == session[:nonce]
27 this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
28 if this_user and UserRole::ALL_ROLES.include? params[:role]
29 UserRole.delete_all({:user_id => this_user.id, :role => params[:role]})
30 redirect_to :controller => 'user', :action => 'view', :display_name => params[:display_name]
32 flash[:notice] = t('user_role.revoke.fail', :role => params[:role], :name => params[:display_name])
35 @nonce = OAuth::Helper.generate_nonce
36 session[:nonce] = @nonce
41 def require_administrator
42 redirect_to "/403.html" unless @user.administrator?