##// END OF EJS Templates
Merged r10893 into 2.1-stable (#12472)....
Jean-Philippe Lang -
r10668:6c2eec59d8fa
parent child
Show More
@@ -1,102 +1,103
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 'admin'
19 layout 'admin'
20
20
21 before_filter :require_admin, :except => :index
21 before_filter :require_admin, :except => :index
22 before_filter :require_admin_or_api_request, :only => :index
22 before_filter :require_admin_or_api_request, :only => :index
23 before_filter :find_role, :only => [:edit, :update, :destroy]
23 before_filter :find_role, :only => [:edit, :update, :destroy]
24 accept_api_auth :index
24 accept_api_auth :index
25 accept_api_auth :index, :show
25
26
26 def index
27 def index
27 respond_to do |format|
28 respond_to do |format|
28 format.html {
29 format.html {
29 @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
30 @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
30 render :action => "index", :layout => false if request.xhr?
31 render :action => "index", :layout => false if request.xhr?
31 }
32 }
32 format.api {
33 format.api {
33 @roles = Role.givable.all
34 @roles = Role.givable.all
34 }
35 }
35 end
36 end
36 end
37 end
37
38
38 def new
39 def new
39 # Prefills the form with 'Non member' role permissions by default
40 # Prefills the form with 'Non member' role permissions by default
40 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
41 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
41 if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy])
42 if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy])
42 @role.copy_from(@copy_from)
43 @role.copy_from(@copy_from)
43 end
44 end
44 @roles = Role.sorted.all
45 @roles = Role.sorted.all
45 end
46 end
46
47
47 def create
48 def create
48 @role = Role.new(params[:role])
49 @role = Role.new(params[:role])
49 if request.post? && @role.save
50 if request.post? && @role.save
50 # workflow copy
51 # workflow copy
51 if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
52 if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
52 @role.workflow_rules.copy(copy_from)
53 @role.workflow_rules.copy(copy_from)
53 end
54 end
54 flash[:notice] = l(:notice_successful_create)
55 flash[:notice] = l(:notice_successful_create)
55 redirect_to :action => 'index'
56 redirect_to :action => 'index'
56 else
57 else
57 @roles = Role.sorted.all
58 @roles = Role.sorted.all
58 render :action => 'new'
59 render :action => 'new'
59 end
60 end
60 end
61 end
61
62
62 def edit
63 def edit
63 end
64 end
64
65
65 def update
66 def update
66 if request.put? and @role.update_attributes(params[:role])
67 if request.put? and @role.update_attributes(params[:role])
67 flash[:notice] = l(:notice_successful_update)
68 flash[:notice] = l(:notice_successful_update)
68 redirect_to :action => 'index'
69 redirect_to :action => 'index'
69 else
70 else
70 render :action => 'edit'
71 render :action => 'edit'
71 end
72 end
72 end
73 end
73
74
74 def destroy
75 def destroy
75 @role.destroy
76 @role.destroy
76 redirect_to :action => 'index'
77 redirect_to :action => 'index'
77 rescue
78 rescue
78 flash[:error] = l(:error_can_not_remove_role)
79 flash[:error] = l(:error_can_not_remove_role)
79 redirect_to :action => 'index'
80 redirect_to :action => 'index'
80 end
81 end
81
82
82 def permissions
83 def permissions
83 @roles = Role.sorted.all
84 @roles = Role.sorted.all
84 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
85 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
85 if request.post?
86 if request.post?
86 @roles.each do |role|
87 @roles.each do |role|
87 role.permissions = params[:permissions][role.id.to_s]
88 role.permissions = params[:permissions][role.id.to_s]
88 role.save
89 role.save
89 end
90 end
90 flash[:notice] = l(:notice_successful_update)
91 flash[:notice] = l(:notice_successful_update)
91 redirect_to :action => 'index'
92 redirect_to :action => 'index'
92 end
93 end
93 end
94 end
94
95
95 private
96 private
96
97
97 def find_role
98 def find_role
98 @role = Role.find(params[:id])
99 @role = Role.find(params[:id])
99 rescue ActiveRecord::RecordNotFound
100 rescue ActiveRecord::RecordNotFound
100 render_404
101 render_404
101 end
102 end
102 end
103 end
General Comments 0
You need to be logged in to leave comments. Login now