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