##// END OF EJS Templates
Reverts r10896 (#12472)....
Jean-Philippe Lang -
r10671:ca73f9905627
parent child
Show More
@@ -1,100 +1,99
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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
39 # Prefills the form with 'Non member' role permissions
41 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
40 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
42 @roles = Role.sorted.all
41 @roles = Role.sorted.all
43 end
42 end
44
43
45 def create
44 def create
46 @role = Role.new(params[:role])
45 @role = Role.new(params[:role])
47 if request.post? && @role.save
46 if request.post? && @role.save
48 # workflow copy
47 # workflow copy
49 if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
48 if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
50 @role.workflows.copy(copy_from)
49 @role.workflows.copy(copy_from)
51 end
50 end
52 flash[:notice] = l(:notice_successful_create)
51 flash[:notice] = l(:notice_successful_create)
53 redirect_to :action => 'index'
52 redirect_to :action => 'index'
54 else
53 else
55 @roles = Role.sorted.all
54 @roles = Role.sorted.all
56 render :action => 'new'
55 render :action => 'new'
57 end
56 end
58 end
57 end
59
58
60 def edit
59 def edit
61 end
60 end
62
61
63 def update
62 def update
64 if request.put? and @role.update_attributes(params[:role])
63 if request.put? and @role.update_attributes(params[:role])
65 flash[:notice] = l(:notice_successful_update)
64 flash[:notice] = l(:notice_successful_update)
66 redirect_to :action => 'index'
65 redirect_to :action => 'index'
67 else
66 else
68 render :action => 'edit'
67 render :action => 'edit'
69 end
68 end
70 end
69 end
71
70
72 def destroy
71 def destroy
73 @role.destroy
72 @role.destroy
74 redirect_to :action => 'index'
73 redirect_to :action => 'index'
75 rescue
74 rescue
76 flash[:error] = l(:error_can_not_remove_role)
75 flash[:error] = l(:error_can_not_remove_role)
77 redirect_to :action => 'index'
76 redirect_to :action => 'index'
78 end
77 end
79
78
80 def permissions
79 def permissions
81 @roles = Role.sorted.all
80 @roles = Role.sorted.all
82 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
81 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
83 if request.post?
82 if request.post?
84 @roles.each do |role|
83 @roles.each do |role|
85 role.permissions = params[:permissions][role.id.to_s]
84 role.permissions = params[:permissions][role.id.to_s]
86 role.save
85 role.save
87 end
86 end
88 flash[:notice] = l(:notice_successful_update)
87 flash[:notice] = l(:notice_successful_update)
89 redirect_to :action => 'index'
88 redirect_to :action => 'index'
90 end
89 end
91 end
90 end
92
91
93 private
92 private
94
93
95 def find_role
94 def find_role
96 @role = Role.find(params[:id])
95 @role = Role.find(params[:id])
97 rescue ActiveRecord::RecordNotFound
96 rescue ActiveRecord::RecordNotFound
98 render_404
97 render_404
99 end
98 end
100 end
99 end
General Comments 0
You need to be logged in to leave comments. Login now