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