##// END OF EJS Templates
Rescue and display an error message when trying to delete a role that is in use....
Jean-Philippe Lang -
r1145:d69a05a6eef9
parent child
Show More
@@ -1,112 +1,111
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 # Prefills the form with 'Non member' role permissions
36 # Prefills the form with 'Non member' role permissions
37 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
37 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
38 if request.post? && @role.save
38 if request.post? && @role.save
39 flash[:notice] = l(:notice_successful_create)
39 flash[:notice] = l(:notice_successful_create)
40 redirect_to :action => 'list'
40 redirect_to :action => 'list'
41 end
41 end
42 @permissions = @role.setable_permissions
42 @permissions = @role.setable_permissions
43 end
43 end
44
44
45 def edit
45 def edit
46 @role = Role.find(params[:id])
46 @role = Role.find(params[:id])
47 if request.post? and @role.update_attributes(params[:role])
47 if request.post? and @role.update_attributes(params[:role])
48 flash[:notice] = l(:notice_successful_update)
48 flash[:notice] = l(:notice_successful_update)
49 redirect_to :action => 'list'
49 redirect_to :action => 'list'
50 end
50 end
51 @permissions = @role.setable_permissions
51 @permissions = @role.setable_permissions
52 end
52 end
53
53
54 def destroy
54 def destroy
55 @role = Role.find(params[:id])
55 @role = Role.find(params[:id])
56 #unless @role.members.empty?
56 @role.destroy
57 # flash[:error] = 'Some members have this role. Can\'t delete it.'
58 #else
59 @role.destroy
60 #end
61 redirect_to :action => 'list'
57 redirect_to :action => 'list'
58 rescue
59 flash[:error] = 'This role is in use and can not be deleted.'
60 redirect_to :action => 'index'
62 end
61 end
63
62
64 def move
63 def move
65 @role = Role.find(params[:id])
64 @role = Role.find(params[:id])
66 case params[:position]
65 case params[:position]
67 when 'highest'
66 when 'highest'
68 @role.move_to_top
67 @role.move_to_top
69 when 'higher'
68 when 'higher'
70 @role.move_higher
69 @role.move_higher
71 when 'lower'
70 when 'lower'
72 @role.move_lower
71 @role.move_lower
73 when 'lowest'
72 when 'lowest'
74 @role.move_to_bottom
73 @role.move_to_bottom
75 end if params[:position]
74 end if params[:position]
76 redirect_to :action => 'list'
75 redirect_to :action => 'list'
77 end
76 end
78
77
79 def workflow
78 def workflow
80 @role = Role.find_by_id(params[:role_id])
79 @role = Role.find_by_id(params[:role_id])
81 @tracker = Tracker.find_by_id(params[:tracker_id])
80 @tracker = Tracker.find_by_id(params[:tracker_id])
82
81
83 if request.post?
82 if request.post?
84 Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
83 Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
85 (params[:issue_status] || []).each { |old, news|
84 (params[:issue_status] || []).each { |old, news|
86 news.each { |new|
85 news.each { |new|
87 @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
86 @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
88 }
87 }
89 }
88 }
90 if @role.save
89 if @role.save
91 flash[:notice] = l(:notice_successful_update)
90 flash[:notice] = l(:notice_successful_update)
92 redirect_to :action => 'workflow', :role_id => @role, :tracker_id => @tracker
91 redirect_to :action => 'workflow', :role_id => @role, :tracker_id => @tracker
93 end
92 end
94 end
93 end
95 @roles = Role.find(:all, :order => 'builtin, position')
94 @roles = Role.find(:all, :order => 'builtin, position')
96 @trackers = Tracker.find(:all, :order => 'position')
95 @trackers = Tracker.find(:all, :order => 'position')
97 @statuses = IssueStatus.find(:all, :order => 'position')
96 @statuses = IssueStatus.find(:all, :order => 'position')
98 end
97 end
99
98
100 def report
99 def report
101 @roles = Role.find(:all, :order => 'builtin, position')
100 @roles = Role.find(:all, :order => 'builtin, position')
102 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
101 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
103 if request.post?
102 if request.post?
104 @roles.each do |role|
103 @roles.each do |role|
105 role.permissions = params[:permissions][role.id.to_s]
104 role.permissions = params[:permissions][role.id.to_s]
106 role.save
105 role.save
107 end
106 end
108 flash[:notice] = l(:notice_successful_update)
107 flash[:notice] = l(:notice_successful_update)
109 redirect_to :action => 'list'
108 redirect_to :action => 'list'
110 end
109 end
111 end
110 end
112 end
111 end
General Comments 0
You need to be logged in to leave comments. Login now