OSDN Git Service

added svn:eol-style native property on /app files
[redminele/redmine.git] / app / controllers / roles_controller.rb
1 # redMine - project management software
2 # Copyright (C) 2006  Jean-Philippe Lang
3 #
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.
8
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.
13
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.
17
18 class RolesController < ApplicationController
19   layout 'base' 
20   before_filter :require_admin
21
22   verify :method => :post, :only => [ :destroy, :move ],
23          :redirect_to => { :action => :list }
24
25   def index
26     list
27     render :action => 'list' unless request.xhr?
28   end
29
30   def list
31     @role_pages, @roles = paginate :roles, :per_page => 10, :order => "position"
32     render :action => "list", :layout => false if request.xhr?
33   end
34
35   def new
36     @role = Role.new(params[:role])
37     if request.post?
38       @role.permissions = Permission.find(params[:permission_ids]) if params[:permission_ids]
39       if @role.save
40         flash[:notice] = l(:notice_successful_create)
41         redirect_to :action => 'list'
42       end
43     end
44     @permissions = Permission.find(:all, :conditions => ["is_public=?", false], :order => 'sort ASC')
45   end
46
47   def edit
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'
54     end
55     @permissions = Permission.find(:all, :conditions => ["is_public=?", false], :order => 'sort ASC')
56   end
57
58   def destroy
59     @role = Role.find(params[:id])
60     unless @role.members.empty?
61       flash[:notice] = 'Some members have this role. Can\'t delete it.'
62     else
63       @role.destroy
64     end
65     redirect_to :action => 'list'
66   end
67   
68   def move
69     @role = Role.find(params[:id])
70     case params[:position]
71     when 'highest'
72       @role.move_to_top
73     when 'higher'
74       @role.move_higher
75     when 'lower'
76       @role.move_lower
77     when 'lowest'
78       @role.move_to_bottom
79     end if params[:position]
80     redirect_to :action => 'list'
81   end
82   
83   def workflow    
84     @role = Role.find_by_id(params[:role_id])
85     @tracker = Tracker.find_by_id(params[:tracker_id])    
86     
87     if request.post?
88       Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
89       (params[:issue_status] || []).each { |old, news| 
90         news.each { |new| 
91           @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new) 
92         }
93       }
94       if @role.save
95         flash[:notice] = l(:notice_successful_update)
96       end
97     end
98     @roles = Role.find(:all, :order => 'position')
99     @trackers = Tracker.find(:all, :order => 'position')
100     @statuses = IssueStatus.find(:all, :include => :workflows, :order => 'position')
101   end
102 end