Mercurial > hg > soundsoftware-site
comparison app/controllers/roles_controller.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 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. |
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 | 21 before_filter :require_admin, :except => [:index, :show] |
22 | 22 before_filter :require_admin_or_api_request, :only => [:index, :show] |
23 verify :method => :post, :only => [ :destroy ], | 23 before_filter :find_role, :only => [:show, :edit, :update, :destroy] |
24 :redirect_to => { :action => :index } | 24 accept_api_auth :index, :show |
25 | 25 |
26 def index | 26 def index |
27 @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position' | 27 respond_to do |format| |
28 render :action => "index", :layout => false if request.xhr? | 28 format.html { |
29 @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position' | |
30 render :action => "index", :layout => false if request.xhr? | |
31 } | |
32 format.api { | |
33 @roles = Role.givable.all | |
34 } | |
35 end | |
36 end | |
37 | |
38 def show | |
39 respond_to do |format| | |
40 format.api | |
41 end | |
29 end | 42 end |
30 | 43 |
31 def new | 44 def new |
32 # Prefills the form with 'Non member' role permissions | 45 # Prefills the form with 'Non member' role permissions by default |
33 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions}) | 46 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions}) |
47 if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy]) | |
48 @role.copy_from(@copy_from) | |
49 end | |
50 @roles = Role.sorted.all | |
51 end | |
52 | |
53 def create | |
54 @role = Role.new(params[:role]) | |
34 if request.post? && @role.save | 55 if request.post? && @role.save |
35 # workflow copy | 56 # workflow copy |
36 if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from])) | 57 if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from])) |
37 @role.workflows.copy(copy_from) | 58 @role.workflow_rules.copy(copy_from) |
38 end | 59 end |
39 flash[:notice] = l(:notice_successful_create) | 60 flash[:notice] = l(:notice_successful_create) |
40 redirect_to :action => 'index' | 61 redirect_to :action => 'index' |
41 else | 62 else |
42 @permissions = @role.setable_permissions | 63 @roles = Role.sorted.all |
43 @roles = Role.find :all, :order => 'builtin, position' | 64 render :action => 'new' |
44 end | 65 end |
45 end | 66 end |
46 | 67 |
47 def edit | 68 def edit |
48 @role = Role.find(params[:id]) | 69 end |
49 if request.post? and @role.update_attributes(params[:role]) | 70 |
71 def update | |
72 if request.put? and @role.update_attributes(params[:role]) | |
50 flash[:notice] = l(:notice_successful_update) | 73 flash[:notice] = l(:notice_successful_update) |
51 redirect_to :action => 'index' | 74 redirect_to :action => 'index' |
52 else | 75 else |
53 @permissions = @role.setable_permissions | 76 render :action => 'edit' |
54 end | 77 end |
55 end | 78 end |
56 | 79 |
57 def destroy | 80 def destroy |
58 @role = Role.find(params[:id]) | |
59 @role.destroy | 81 @role.destroy |
60 redirect_to :action => 'index' | 82 redirect_to :action => 'index' |
61 rescue | 83 rescue |
62 flash[:error] = l(:error_can_not_remove_role) | 84 flash[:error] = l(:error_can_not_remove_role) |
63 redirect_to :action => 'index' | 85 redirect_to :action => 'index' |
64 end | 86 end |
65 | 87 |
66 def report | 88 def permissions |
67 @roles = Role.find(:all, :order => 'builtin, position') | 89 @roles = Role.sorted.all |
68 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } | 90 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } |
69 if request.post? | 91 if request.post? |
70 @roles.each do |role| | 92 @roles.each do |role| |
71 role.permissions = params[:permissions][role.id.to_s] | 93 role.permissions = params[:permissions][role.id.to_s] |
72 role.save | 94 role.save |
73 end | 95 end |
74 flash[:notice] = l(:notice_successful_update) | 96 flash[:notice] = l(:notice_successful_update) |
75 redirect_to :action => 'index' | 97 redirect_to :action => 'index' |
76 end | 98 end |
77 end | 99 end |
100 | |
101 private | |
102 | |
103 def find_role | |
104 @role = Role.find(params[:id]) | |
105 rescue ActiveRecord::RecordNotFound | |
106 render_404 | |
107 end | |
78 end | 108 end |