1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 class RolesController < ApplicationController
19 before_filter :require_admin
21 verify :method => :post, :only => [ :destroy, :move ],
22 :redirect_to => { :action => :list }
26 render :action => 'list' unless request.xhr?
30 @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
31 render :action => "list", :layout => false if request.xhr?
35 # Prefills the form with 'Non member' role permissions
36 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
37 if request.post? && @role.save
39 if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
40 @role.workflows.copy(copy_from)
42 flash[:notice] = l(:notice_successful_create)
43 redirect_to :action => 'index'
45 @permissions = @role.setable_permissions
46 @roles = Role.find :all, :order => 'builtin, position'
50 @role = Role.find(params[:id])
51 if request.post? and @role.update_attributes(params[:role])
52 flash[:notice] = l(:notice_successful_update)
53 redirect_to :action => 'index'
55 @permissions = @role.setable_permissions
59 @role = Role.find(params[:id])
61 redirect_to :action => 'index'
63 flash[:error] = 'This role is in use and can not be deleted.'
64 redirect_to :action => 'index'
68 @roles = Role.find(:all, :order => 'builtin, position')
69 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
72 role.permissions = params[:permissions][role.id.to_s]
75 flash[:notice] = l(:notice_successful_update)
76 redirect_to :action => 'index'