Chris@0: # redMine - project management software Chris@0: # Copyright (C) 2006 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@0: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@0: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@0: class RolesController < ApplicationController Chris@0: layout 'admin' Chris@0: Chris@0: before_filter :require_admin Chris@0: Chris@0: verify :method => :post, :only => [ :destroy, :move ], Chris@0: :redirect_to => { :action => :index } Chris@0: Chris@0: def index Chris@0: @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position' Chris@0: render :action => "index", :layout => false if request.xhr? Chris@0: end Chris@0: Chris@0: def new Chris@0: # Prefills the form with 'Non member' role permissions Chris@0: @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions}) Chris@0: if request.post? && @role.save Chris@0: # workflow copy Chris@0: if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from])) Chris@0: @role.workflows.copy(copy_from) Chris@0: end Chris@0: flash[:notice] = l(:notice_successful_create) Chris@0: redirect_to :action => 'index' Chris@0: end Chris@0: @permissions = @role.setable_permissions Chris@0: @roles = Role.find :all, :order => 'builtin, position' Chris@0: end Chris@0: Chris@0: def edit Chris@0: @role = Role.find(params[:id]) Chris@0: if request.post? and @role.update_attributes(params[:role]) Chris@0: flash[:notice] = l(:notice_successful_update) Chris@0: redirect_to :action => 'index' Chris@0: end Chris@0: @permissions = @role.setable_permissions Chris@0: end Chris@0: Chris@0: def destroy Chris@0: @role = Role.find(params[:id]) Chris@0: @role.destroy Chris@0: redirect_to :action => 'index' Chris@0: rescue Chris@0: flash[:error] = l(:error_can_not_remove_role) Chris@0: redirect_to :action => 'index' Chris@0: end Chris@0: Chris@0: def report Chris@0: @roles = Role.find(:all, :order => 'builtin, position') Chris@0: @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } Chris@0: if request.post? Chris@0: @roles.each do |role| Chris@0: role.permissions = params[:permissions][role.id.to_s] Chris@0: role.save Chris@0: end Chris@0: flash[:notice] = l(:notice_successful_update) Chris@0: redirect_to :action => 'index' Chris@0: end Chris@0: end Chris@0: end