| 
									
										
										
										
											2011-08-31 08:43:49 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							|  |  |  | # Copyright (C) 2006-2011  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | # of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2011-08-31 08:43:49 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											2011-08-31 08:43:49 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | # along with this program; if not, write to the Free Software | 
					
						
							|  |  |  | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class RolesController < ApplicationController | 
					
						
							| 
									
										
										
										
											2009-12-17 18:21:02 +00:00
										 |  |  |   layout 'admin' | 
					
						
							| 
									
										
										
										
											2011-08-31 08:43:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-06 10:06:32 +00:00
										 |  |  |   before_filter :require_admin, :except => :index | 
					
						
							|  |  |  |   before_filter :require_admin_or_api_request, :only => :index | 
					
						
							| 
									
										
										
										
											2011-12-09 23:29:58 +00:00
										 |  |  |   before_filter :find_role, :only => [:edit, :update, :destroy] | 
					
						
							| 
									
										
										
										
											2012-02-06 10:06:32 +00:00
										 |  |  |   accept_api_auth :index | 
					
						
							| 
									
										
										
										
											2007-01-28 00:00:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |   def index | 
					
						
							| 
									
										
										
										
											2012-02-06 10:06:32 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							|  |  |  |       format.html { | 
					
						
							|  |  |  |         @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position' | 
					
						
							|  |  |  |         render :action => "index", :layout => false if request.xhr? | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       format.api { | 
					
						
							|  |  |  |         @roles = Role.givable.all | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def new | 
					
						
							| 
									
										
										
										
											2007-12-02 12:58:07 +00:00
										 |  |  |     # Prefills the form with 'Non member' role permissions | 
					
						
							|  |  |  |     @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions}) | 
					
						
							| 
									
										
										
										
											2011-12-14 22:24:20 +00:00
										 |  |  |     @roles = Role.sorted.all | 
					
						
							| 
									
										
										
										
											2011-12-09 23:29:58 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def create | 
					
						
							|  |  |  |     @role = Role.new(params[:role]) | 
					
						
							| 
									
										
										
										
											2007-08-29 16:52:35 +00:00
										 |  |  |     if request.post? && @role.save | 
					
						
							| 
									
										
										
										
											2008-03-15 08:27:38 +00:00
										 |  |  |       # workflow copy | 
					
						
							|  |  |  |       if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from])) | 
					
						
							|  |  |  |         @role.workflows.copy(copy_from) | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2007-08-29 16:52:35 +00:00
										 |  |  |       flash[:notice] = l(:notice_successful_create) | 
					
						
							| 
									
										
										
										
											2009-05-10 10:54:31 +00:00
										 |  |  |       redirect_to :action => 'index' | 
					
						
							| 
									
										
										
										
											2011-05-01 23:15:03 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2011-12-14 22:24:20 +00:00
										 |  |  |       @roles = Role.sorted.all | 
					
						
							| 
									
										
										
										
											2011-12-09 23:29:58 +00:00
										 |  |  |       render :action => 'new' | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def edit | 
					
						
							| 
									
										
										
										
											2011-12-09 23:29:58 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def update | 
					
						
							|  |  |  |     if request.put? and @role.update_attributes(params[:role]) | 
					
						
							| 
									
										
										
										
											2006-07-30 10:47:02 +00:00
										 |  |  |       flash[:notice] = l(:notice_successful_update) | 
					
						
							| 
									
										
										
										
											2009-05-10 10:54:31 +00:00
										 |  |  |       redirect_to :action => 'index' | 
					
						
							| 
									
										
										
										
											2011-05-01 23:15:03 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2011-12-09 23:29:58 +00:00
										 |  |  |       render :action => 'edit' | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def destroy | 
					
						
							| 
									
										
										
										
											2008-02-16 21:05:10 +00:00
										 |  |  |     @role.destroy | 
					
						
							| 
									
										
										
										
											2009-05-10 10:54:31 +00:00
										 |  |  |     redirect_to :action => 'index' | 
					
						
							| 
									
										
										
										
											2008-02-16 21:05:10 +00:00
										 |  |  |   rescue | 
					
						
							| 
									
										
										
										
											2010-04-03 11:54:24 +00:00
										 |  |  |     flash[:error] =  l(:error_can_not_remove_role) | 
					
						
							| 
									
										
										
										
											2008-02-16 21:05:10 +00:00
										 |  |  |     redirect_to :action => 'index' | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 08:43:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-09 23:29:58 +00:00
										 |  |  |   def permissions | 
					
						
							| 
									
										
										
										
											2011-12-14 22:24:20 +00:00
										 |  |  |     @roles = Role.sorted.all | 
					
						
							| 
									
										
										
										
											2007-08-29 16:52:35 +00:00
										 |  |  |     @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } | 
					
						
							| 
									
										
										
										
											2007-04-07 20:27:19 +00:00
										 |  |  |     if request.post? | 
					
						
							|  |  |  |       @roles.each do |role| | 
					
						
							| 
									
										
										
										
											2007-08-29 16:52:35 +00:00
										 |  |  |         role.permissions = params[:permissions][role.id.to_s] | 
					
						
							|  |  |  |         role.save | 
					
						
							| 
									
										
										
										
											2007-04-07 20:27:19 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |       flash[:notice] = l(:notice_successful_update) | 
					
						
							| 
									
										
										
										
											2009-05-10 10:54:31 +00:00
										 |  |  |       redirect_to :action => 'index' | 
					
						
							| 
									
										
										
										
											2007-04-07 20:27:19 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-12-09 23:29:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def find_role | 
					
						
							|  |  |  |     @role = Role.find(params[:id]) | 
					
						
							|  |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  | end |