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