OSDN Git Service

add Redmine trunk rev 3089
[redminele/redminele.git] / redmine / app / controllers / roles_controller.rb
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   before_filter :require_admin
20
21   verify :method => :post, :only => [ :destroy, :move ],
22          :redirect_to => { :action => :list }
23
24   def index
25     list
26     render :action => 'list' unless request.xhr?
27   end
28
29   def list
30     @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
31     render :action => "list", :layout => false if request.xhr?
32   end
33
34   def new
35     # Prefills the form with 'Non member' role permissions
36     @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
37     if request.post? && @role.save
38       # workflow copy
39       if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
40         @role.workflows.copy(copy_from)
41       end
42       flash[:notice] = l(:notice_successful_create)
43       redirect_to :action => 'index'
44     end
45     @permissions = @role.setable_permissions
46     @roles = Role.find :all, :order => 'builtin, position'
47   end
48
49   def edit
50     @role = Role.find(params[:id])
51     if request.post? and @role.update_attributes(params[:role])
52       flash[:notice] = l(:notice_successful_update)
53       redirect_to :action => 'index'
54     end
55     @permissions = @role.setable_permissions
56   end
57
58   def destroy
59     @role = Role.find(params[:id])
60     @role.destroy
61     redirect_to :action => 'index'
62   rescue
63     flash[:error] = 'This role is in use and can not be deleted.'
64     redirect_to :action => 'index'
65   end
66   
67   def report    
68     @roles = Role.find(:all, :order => 'builtin, position')
69     @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
70     if request.post?
71       @roles.each do |role|
72         role.permissions = params[:permissions][role.id.to_s]
73         role.save
74       end
75       flash[:notice] = l(:notice_successful_update)
76       redirect_to :action => 'index'
77     end
78   end
79 end