2011-10-29 16:19:11 +04:00
|
|
|
#-- encoding: UTF-8
|
2011-05-30 00:11:52 +04:00
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# Copyright (C) 2010-2011 the ChiliProject Team
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04: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-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
class RolesController < ApplicationController
|
2009-12-17 21:21:02 +03:00
|
|
|
layout 'admin'
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
before_filter :require_admin
|
|
|
|
|
|
|
|
verify :method => :post, :only => [ :destroy, :move ],
|
2010-02-15 19:41:16 +03:00
|
|
|
:redirect_to => { :action => :index }
|
2007-01-28 03:00:21 +03:00
|
|
|
|
2006-06-28 22:11:03 +04:00
|
|
|
def index
|
2007-08-29 20:52:35 +04:00
|
|
|
@role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
|
2010-02-15 19:41:16 +03:00
|
|
|
render :action => "index", :layout => false if request.xhr?
|
2006-06-28 22:11:03 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2007-12-02 15:58:07 +03:00
|
|
|
# Prefills the form with 'Non member' role permissions
|
|
|
|
@role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
|
2007-08-29 20:52:35 +04:00
|
|
|
if request.post? && @role.save
|
2008-03-15 11:27:38 +03: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 20:52:35 +04:00
|
|
|
flash[:notice] = l(:notice_successful_create)
|
2009-05-10 14:54:31 +04:00
|
|
|
redirect_to :action => 'index'
|
2011-04-29 01:39:19 +04:00
|
|
|
else
|
|
|
|
@permissions = @role.setable_permissions
|
|
|
|
@roles = Role.find :all, :order => 'builtin, position'
|
2006-06-28 22:11:03 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2007-03-12 20:59:02 +03:00
|
|
|
@role = Role.find(params[:id])
|
2006-06-28 22:11:03 +04:00
|
|
|
if request.post? and @role.update_attributes(params[:role])
|
2006-07-30 14:47:02 +04:00
|
|
|
flash[:notice] = l(:notice_successful_update)
|
2009-05-10 14:54:31 +04:00
|
|
|
redirect_to :action => 'index'
|
2011-04-29 01:39:19 +04:00
|
|
|
else
|
2011-05-30 22:52:25 +04:00
|
|
|
@permissions = @role.setable_permissions
|
2006-06-28 22:11:03 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2007-03-12 20:59:02 +03:00
|
|
|
@role = Role.find(params[:id])
|
2008-02-17 00:05:10 +03:00
|
|
|
@role.destroy
|
2009-05-10 14:54:31 +04:00
|
|
|
redirect_to :action => 'index'
|
2008-02-17 00:05:10 +03:00
|
|
|
rescue
|
2010-04-03 15:54:24 +04:00
|
|
|
flash[:error] = l(:error_can_not_remove_role)
|
2008-02-17 00:05:10 +03:00
|
|
|
redirect_to :action => 'index'
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
|
|
|
def report
|
2007-08-29 20:52:35 +04:00
|
|
|
@roles = Role.find(:all, :order => 'builtin, position')
|
|
|
|
@permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
|
2007-04-08 00:27:19 +04:00
|
|
|
if request.post?
|
|
|
|
@roles.each do |role|
|
2007-08-29 20:52:35 +04:00
|
|
|
role.permissions = params[:permissions][role.id.to_s]
|
|
|
|
role.save
|
2007-04-08 00:27:19 +04:00
|
|
|
end
|
|
|
|
flash[:notice] = l(:notice_successful_update)
|
2009-05-10 14:54:31 +04:00
|
|
|
redirect_to :action => 'index'
|
2007-04-08 00:27:19 +04:00
|
|
|
end
|
|
|
|
end
|
2006-06-28 22:11:03 +04:00
|
|
|
end
|