roles_controller.rb
102 lines
| 3.0 KiB
| text/x-ruby
|
RubyLexer
|
r6749 | # Redmine - project management software | ||
|
r9453 | # Copyright (C) 2006-2012 Jean-Philippe Lang | ||
|
r330 | # | ||
# 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. | ||||
|
r6749 | # | ||
|
r330 | # 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. | ||||
|
r6749 | # | ||
|
r330 | # 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 | ||||
|
r3062 | layout 'admin' | ||
|
r6749 | |||
|
r8679 | before_filter :require_admin, :except => :index | ||
before_filter :require_admin_or_api_request, :only => :index | ||||
|
r8025 | before_filter :find_role, :only => [:edit, :update, :destroy] | ||
|
r8679 | accept_api_auth :index | ||
|
r198 | |||
|
r2 | def index | ||
|
r8679 | 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 | ||||
|
r2 | end | ||
def new | ||||
|
r10102 | # Prefills the form with 'Non member' role permissions by default | ||
|
r930 | @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions}) | ||
|
r10102 | if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy]) | ||
@role.copy_from(@copy_from) | ||||
end | ||||
|
r8093 | @roles = Role.sorted.all | ||
|
r8025 | end | ||
def create | ||||
@role = Role.new(params[:role]) | ||||
|
r663 | if request.post? && @role.save | ||
|
r1237 | # workflow copy | ||
if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from])) | ||||
|
r9794 | @role.workflow_rules.copy(copy_from) | ||
|
r1237 | end | ||
|
r663 | flash[:notice] = l(:notice_successful_create) | ||
|
r2627 | redirect_to :action => 'index' | ||
|
r5491 | else | ||
|
r8093 | @roles = Role.sorted.all | ||
|
r8025 | render :action => 'new' | ||
|
r2 | end | ||
end | ||||
def edit | ||||
|
r8025 | end | ||
def update | ||||
if request.put? and @role.update_attributes(params[:role]) | ||||
|
r15 | flash[:notice] = l(:notice_successful_update) | ||
|
r2627 | redirect_to :action => 'index' | ||
|
r5491 | else | ||
|
r8025 | render :action => 'edit' | ||
|
r2 | end | ||
end | ||||
def destroy | ||||
|
r1145 | @role.destroy | ||
|
r2627 | redirect_to :action => 'index' | ||
|
r1145 | rescue | ||
|
r3513 | flash[:error] = l(:error_can_not_remove_role) | ||
|
r1145 | redirect_to :action => 'index' | ||
|
r330 | end | ||
|
r6749 | |||
|
r8025 | def permissions | ||
|
r8093 | @roles = Role.sorted.all | ||
|
r663 | @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } | ||
|
r430 | if request.post? | ||
@roles.each do |role| | ||||
|
r663 | role.permissions = params[:permissions][role.id.to_s] | ||
role.save | ||||
|
r430 | end | ||
flash[:notice] = l(:notice_successful_update) | ||||
|
r2627 | redirect_to :action => 'index' | ||
|
r430 | end | ||
end | ||||
|
r8025 | |||
private | ||||
def find_role | ||||
@role = Role.find(params[:id]) | ||||
rescue ActiveRecord::RecordNotFound | ||||
render_404 | ||||
end | ||||
|
r2 | end | ||