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
20 before_filter :require_admin
22 verify :method => :post, :only => [ :destroy, :move ],
23 :redirect_to => { :action => :list }
27 render :action => 'list' unless request.xhr?
31 @role_pages, @roles = paginate :roles, :per_page => 10, :order => "position"
32 render :action => "list", :layout => false if request.xhr?
36 @role = Role.new(params[:role])
38 @role.permissions = Permission.find(params[:permission_ids]) if params[:permission_ids]
40 flash[:notice] = l(:notice_successful_create)
41 redirect_to :action => 'list'
44 @permissions = Permission.find(:all, :conditions => ["is_public=?", false], :order => 'sort ASC')
48 @role = Role.find(params[:id])
49 if request.post? and @role.update_attributes(params[:role])
50 @role.permissions = Permission.find(params[:permission_ids] || [])
51 Permission.allowed_to_role_expired
52 flash[:notice] = l(:notice_successful_update)
53 redirect_to :action => 'list'
55 @permissions = Permission.find(:all, :conditions => ["is_public=?", false], :order => 'sort ASC')
59 @role = Role.find(params[:id])
60 unless @role.members.empty?
61 flash[:notice] = 'Some members have this role. Can\'t delete it.'
65 redirect_to :action => 'list'
69 @role = Role.find(params[:id])
70 case params[:position]
79 end if params[:position]
80 redirect_to :action => 'list'
84 @role = Role.find_by_id(params[:role_id])
85 @tracker = Tracker.find_by_id(params[:tracker_id])
88 Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
89 (params[:issue_status] || []).each { |old, news|
91 @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
95 flash[:notice] = l(:notice_successful_update)
98 @roles = Role.find(:all, :order => 'position')
99 @trackers = Tracker.find(:all, :order => 'position')
100 @statuses = IssueStatus.find(:all, :include => :workflows, :order => 'position')