@@ -1,111 +1,112 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class RolesController < ApplicationController |
|
18 | class RolesController < ApplicationController | |
19 | layout 'base' |
|
19 | layout 'base' | |
20 | before_filter :require_admin |
|
20 | before_filter :require_admin | |
21 |
|
21 | |||
22 | verify :method => :post, :only => [ :destroy, :move ], |
|
22 | verify :method => :post, :only => [ :destroy, :move ], | |
23 | :redirect_to => { :action => :list } |
|
23 | :redirect_to => { :action => :list } | |
24 |
|
24 | |||
25 | def index |
|
25 | def index | |
26 | list |
|
26 | list | |
27 | render :action => 'list' unless request.xhr? |
|
27 | render :action => 'list' unless request.xhr? | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | def list |
|
30 | def list | |
31 | @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position' |
|
31 | @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position' | |
32 | render :action => "list", :layout => false if request.xhr? |
|
32 | render :action => "list", :layout => false if request.xhr? | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def new |
|
35 | def new | |
36 | @role = Role.new(params[:role]) |
|
36 | # Prefills the form with 'Non member' role permissions | |
|
37 | @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions}) | |||
37 | if request.post? && @role.save |
|
38 | if request.post? && @role.save | |
38 | flash[:notice] = l(:notice_successful_create) |
|
39 | flash[:notice] = l(:notice_successful_create) | |
39 | redirect_to :action => 'list' |
|
40 | redirect_to :action => 'list' | |
40 | end |
|
41 | end | |
41 | @permissions = @role.setable_permissions |
|
42 | @permissions = @role.setable_permissions | |
42 | end |
|
43 | end | |
43 |
|
44 | |||
44 | def edit |
|
45 | def edit | |
45 | @role = Role.find(params[:id]) |
|
46 | @role = Role.find(params[:id]) | |
46 | if request.post? and @role.update_attributes(params[:role]) |
|
47 | if request.post? and @role.update_attributes(params[:role]) | |
47 | flash[:notice] = l(:notice_successful_update) |
|
48 | flash[:notice] = l(:notice_successful_update) | |
48 | redirect_to :action => 'list' |
|
49 | redirect_to :action => 'list' | |
49 | end |
|
50 | end | |
50 | @permissions = @role.setable_permissions |
|
51 | @permissions = @role.setable_permissions | |
51 | end |
|
52 | end | |
52 |
|
53 | |||
53 | def destroy |
|
54 | def destroy | |
54 | @role = Role.find(params[:id]) |
|
55 | @role = Role.find(params[:id]) | |
55 | #unless @role.members.empty? |
|
56 | #unless @role.members.empty? | |
56 | # flash[:error] = 'Some members have this role. Can\'t delete it.' |
|
57 | # flash[:error] = 'Some members have this role. Can\'t delete it.' | |
57 | #else |
|
58 | #else | |
58 | @role.destroy |
|
59 | @role.destroy | |
59 | #end |
|
60 | #end | |
60 | redirect_to :action => 'list' |
|
61 | redirect_to :action => 'list' | |
61 | end |
|
62 | end | |
62 |
|
63 | |||
63 | def move |
|
64 | def move | |
64 | @role = Role.find(params[:id]) |
|
65 | @role = Role.find(params[:id]) | |
65 | case params[:position] |
|
66 | case params[:position] | |
66 | when 'highest' |
|
67 | when 'highest' | |
67 | @role.move_to_top |
|
68 | @role.move_to_top | |
68 | when 'higher' |
|
69 | when 'higher' | |
69 | @role.move_higher |
|
70 | @role.move_higher | |
70 | when 'lower' |
|
71 | when 'lower' | |
71 | @role.move_lower |
|
72 | @role.move_lower | |
72 | when 'lowest' |
|
73 | when 'lowest' | |
73 | @role.move_to_bottom |
|
74 | @role.move_to_bottom | |
74 | end if params[:position] |
|
75 | end if params[:position] | |
75 | redirect_to :action => 'list' |
|
76 | redirect_to :action => 'list' | |
76 | end |
|
77 | end | |
77 |
|
78 | |||
78 | def workflow |
|
79 | def workflow | |
79 | @role = Role.find_by_id(params[:role_id]) |
|
80 | @role = Role.find_by_id(params[:role_id]) | |
80 | @tracker = Tracker.find_by_id(params[:tracker_id]) |
|
81 | @tracker = Tracker.find_by_id(params[:tracker_id]) | |
81 |
|
82 | |||
82 | if request.post? |
|
83 | if request.post? | |
83 | Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) |
|
84 | Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) | |
84 | (params[:issue_status] || []).each { |old, news| |
|
85 | (params[:issue_status] || []).each { |old, news| | |
85 | news.each { |new| |
|
86 | news.each { |new| | |
86 | @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new) |
|
87 | @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new) | |
87 | } |
|
88 | } | |
88 | } |
|
89 | } | |
89 | if @role.save |
|
90 | if @role.save | |
90 | flash[:notice] = l(:notice_successful_update) |
|
91 | flash[:notice] = l(:notice_successful_update) | |
91 | redirect_to :action => 'workflow', :role_id => @role, :tracker_id => @tracker |
|
92 | redirect_to :action => 'workflow', :role_id => @role, :tracker_id => @tracker | |
92 | end |
|
93 | end | |
93 | end |
|
94 | end | |
94 | @roles = Role.find(:all, :order => 'builtin, position') |
|
95 | @roles = Role.find(:all, :order => 'builtin, position') | |
95 | @trackers = Tracker.find(:all, :order => 'position') |
|
96 | @trackers = Tracker.find(:all, :order => 'position') | |
96 | @statuses = IssueStatus.find(:all, :include => :workflows, :order => 'position') |
|
97 | @statuses = IssueStatus.find(:all, :include => :workflows, :order => 'position') | |
97 | end |
|
98 | end | |
98 |
|
99 | |||
99 | def report |
|
100 | def report | |
100 | @roles = Role.find(:all, :order => 'builtin, position') |
|
101 | @roles = Role.find(:all, :order => 'builtin, position') | |
101 | @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } |
|
102 | @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } | |
102 | if request.post? |
|
103 | if request.post? | |
103 | @roles.each do |role| |
|
104 | @roles.each do |role| | |
104 | role.permissions = params[:permissions][role.id.to_s] |
|
105 | role.permissions = params[:permissions][role.id.to_s] | |
105 | role.save |
|
106 | role.save | |
106 | end |
|
107 | end | |
107 | flash[:notice] = l(:notice_successful_update) |
|
108 | flash[:notice] = l(:notice_successful_update) | |
108 | redirect_to :action => 'list' |
|
109 | redirect_to :action => 'list' | |
109 | end |
|
110 | end | |
110 | end |
|
111 | end | |
111 | end |
|
112 | end |
General Comments 0
You need to be logged in to leave comments.
Login now