comparison app/controllers/.svn/text-base/roles_controller.rb.svn-base @ 0:513646585e45

* Import Redmine trunk SVN rev 3859
author Chris Cannam
date Fri, 23 Jul 2010 15:52:44 +0100
parents
children cbce1fd3b1b7
comparison
equal deleted inserted replaced
-1:000000000000 0:513646585e45
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 class RolesController < ApplicationController
19 layout 'admin'
20
21 before_filter :require_admin
22
23 verify :method => :post, :only => [ :destroy, :move ],
24 :redirect_to => { :action => :index }
25
26 def index
27 @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
28 render :action => "index", :layout => false if request.xhr?
29 end
30
31 def new
32 # Prefills the form with 'Non member' role permissions
33 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
34 if request.post? && @role.save
35 # workflow copy
36 if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
37 @role.workflows.copy(copy_from)
38 end
39 flash[:notice] = l(:notice_successful_create)
40 redirect_to :action => 'index'
41 end
42 @permissions = @role.setable_permissions
43 @roles = Role.find :all, :order => 'builtin, position'
44 end
45
46 def edit
47 @role = Role.find(params[:id])
48 if request.post? and @role.update_attributes(params[:role])
49 flash[:notice] = l(:notice_successful_update)
50 redirect_to :action => 'index'
51 end
52 @permissions = @role.setable_permissions
53 end
54
55 def destroy
56 @role = Role.find(params[:id])
57 @role.destroy
58 redirect_to :action => 'index'
59 rescue
60 flash[:error] = l(:error_can_not_remove_role)
61 redirect_to :action => 'index'
62 end
63
64 def report
65 @roles = Role.find(:all, :order => 'builtin, position')
66 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
67 if request.post?
68 @roles.each do |role|
69 role.permissions = params[:permissions][role.id.to_s]
70 role.save
71 end
72 flash[:notice] = l(:notice_successful_update)
73 redirect_to :action => 'index'
74 end
75 end
76 end