Chris@909
|
1 # Redmine - project management software
|
Chris@1115
|
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@909
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@909
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@0
|
18 class RolesController < ApplicationController
|
Chris@0
|
19 layout 'admin'
|
Chris@909
|
20
|
Chris@1115
|
21 before_filter :require_admin, :except => [:index, :show]
|
Chris@1115
|
22 before_filter :require_admin_or_api_request, :only => [:index, :show]
|
Chris@1115
|
23 before_filter :find_role, :only => [:show, :edit, :update, :destroy]
|
Chris@1115
|
24 accept_api_auth :index, :show
|
Chris@0
|
25
|
Chris@0
|
26 def index
|
Chris@1115
|
27 respond_to do |format|
|
Chris@1115
|
28 format.html {
|
Chris@1115
|
29 @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
|
Chris@1115
|
30 render :action => "index", :layout => false if request.xhr?
|
Chris@1115
|
31 }
|
Chris@1115
|
32 format.api {
|
Chris@1115
|
33 @roles = Role.givable.all
|
Chris@1115
|
34 }
|
Chris@1115
|
35 end
|
Chris@1115
|
36 end
|
Chris@1115
|
37
|
Chris@1115
|
38 def show
|
Chris@1115
|
39 respond_to do |format|
|
Chris@1115
|
40 format.api
|
Chris@1115
|
41 end
|
Chris@0
|
42 end
|
Chris@0
|
43
|
Chris@0
|
44 def new
|
Chris@1115
|
45 # Prefills the form with 'Non member' role permissions by default
|
Chris@0
|
46 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
|
Chris@1115
|
47 if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy])
|
Chris@1115
|
48 @role.copy_from(@copy_from)
|
Chris@1115
|
49 end
|
Chris@1115
|
50 @roles = Role.sorted.all
|
Chris@1115
|
51 end
|
Chris@1115
|
52
|
Chris@1115
|
53 def create
|
Chris@1115
|
54 @role = Role.new(params[:role])
|
Chris@0
|
55 if request.post? && @role.save
|
Chris@0
|
56 # workflow copy
|
Chris@0
|
57 if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
|
Chris@1115
|
58 @role.workflow_rules.copy(copy_from)
|
Chris@0
|
59 end
|
Chris@0
|
60 flash[:notice] = l(:notice_successful_create)
|
Chris@0
|
61 redirect_to :action => 'index'
|
Chris@441
|
62 else
|
Chris@1115
|
63 @roles = Role.sorted.all
|
Chris@1115
|
64 render :action => 'new'
|
Chris@0
|
65 end
|
Chris@0
|
66 end
|
Chris@0
|
67
|
Chris@0
|
68 def edit
|
Chris@1115
|
69 end
|
Chris@1115
|
70
|
Chris@1115
|
71 def update
|
Chris@1115
|
72 if request.put? and @role.update_attributes(params[:role])
|
Chris@0
|
73 flash[:notice] = l(:notice_successful_update)
|
Chris@0
|
74 redirect_to :action => 'index'
|
Chris@441
|
75 else
|
Chris@1115
|
76 render :action => 'edit'
|
Chris@0
|
77 end
|
Chris@0
|
78 end
|
Chris@0
|
79
|
Chris@0
|
80 def destroy
|
Chris@0
|
81 @role.destroy
|
Chris@0
|
82 redirect_to :action => 'index'
|
Chris@0
|
83 rescue
|
Chris@0
|
84 flash[:error] = l(:error_can_not_remove_role)
|
Chris@0
|
85 redirect_to :action => 'index'
|
Chris@0
|
86 end
|
Chris@909
|
87
|
Chris@1115
|
88 def permissions
|
Chris@1115
|
89 @roles = Role.sorted.all
|
Chris@0
|
90 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
|
Chris@0
|
91 if request.post?
|
Chris@0
|
92 @roles.each do |role|
|
Chris@0
|
93 role.permissions = params[:permissions][role.id.to_s]
|
Chris@0
|
94 role.save
|
Chris@0
|
95 end
|
Chris@0
|
96 flash[:notice] = l(:notice_successful_update)
|
Chris@0
|
97 redirect_to :action => 'index'
|
Chris@0
|
98 end
|
Chris@0
|
99 end
|
Chris@1115
|
100
|
Chris@1115
|
101 private
|
Chris@1115
|
102
|
Chris@1115
|
103 def find_role
|
Chris@1115
|
104 @role = Role.find(params[:id])
|
Chris@1115
|
105 rescue ActiveRecord::RecordNotFound
|
Chris@1115
|
106 render_404
|
Chris@1115
|
107 end
|
Chris@0
|
108 end
|