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