- layout 'site'
-
- before_filter :authorize_web
- before_filter :require_user
- before_filter :require_administrator
-
- def grant
- # added a random nonce here which isn't predictable, making an CSRF procedure much, much more difficult.
- if params[:nonce] and params[:nonce] == session[:nonce]
- this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
- if this_user and UserRole::ALL_ROLES.include? params[:role]
- this_user.roles.create(:role => params[:role])
- redirect_to :controller => 'user', :action => 'view', :display_name => params[:display_name]
- else
- flash[:notice] = t('user_role.grant.fail', :role => params[:role], :name => params[:display_name])
- end
- else
- @nonce = OAuth::Helper.generate_nonce
- session[:nonce] = @nonce
- end
+ include UserMethods
+
+ layout "site"
+
+ before_action :authorize_web
+
+ authorize_resource
+
+ before_action :lookup_user
+ before_action :require_valid_role
+ before_action :not_in_role, :only => :create
+ before_action :in_role, :only => :destroy
+
+ def create
+ @user.roles.create(:role => @role, :granter => current_user)
+ redirect_to user_path(@user)