To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / roles_controller.rb @ 1298:4f746d8966dd
History | View | Annotate | Download (3 KB)
| 1 | 909:cbb26bc654de | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | 1295:622f24f53b42 | Chris | # Copyright (C) 2006-2013 Jean-Philippe Lang
|
| 3 | 0:513646585e45 | Chris | #
|
| 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 | 909:cbb26bc654de | Chris | #
|
| 9 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | #
|
| 14 | 0:513646585e45 | Chris | # 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 | layout 'admin'
|
||
| 20 | 909:cbb26bc654de | Chris | |
| 21 | 1115:433d4f72a19b | Chris | before_filter :require_admin, :except => [:index, :show] |
| 22 | before_filter :require_admin_or_api_request, :only => [:index, :show] |
||
| 23 | before_filter :find_role, :only => [:show, :edit, :update, :destroy] |
||
| 24 | accept_api_auth :index, :show |
||
| 25 | 0:513646585e45 | Chris | |
| 26 | def index |
||
| 27 | 1115:433d4f72a19b | Chris | respond_to do |format|
|
| 28 | format.html {
|
||
| 29 | 1295:622f24f53b42 | Chris | @role_pages, @roles = paginate Role.sorted, :per_page => 25 |
| 30 | 1115:433d4f72a19b | Chris | render :action => "index", :layout => false if request.xhr? |
| 31 | } |
||
| 32 | format.api {
|
||
| 33 | @roles = Role.givable.all |
||
| 34 | } |
||
| 35 | end
|
||
| 36 | end
|
||
| 37 | |||
| 38 | def show |
||
| 39 | respond_to do |format|
|
||
| 40 | format.api |
||
| 41 | end
|
||
| 42 | 0:513646585e45 | Chris | end
|
| 43 | |||
| 44 | def new |
||
| 45 | 1115:433d4f72a19b | Chris | # Prefills the form with 'Non member' role permissions by default
|
| 46 | 0:513646585e45 | Chris | @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions}) |
| 47 | 1115:433d4f72a19b | Chris | if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy]) |
| 48 | @role.copy_from(@copy_from) |
||
| 49 | end
|
||
| 50 | @roles = Role.sorted.all |
||
| 51 | end
|
||
| 52 | |||
| 53 | def create |
||
| 54 | @role = Role.new(params[:role]) |
||
| 55 | 0:513646585e45 | Chris | if request.post? && @role.save |
| 56 | # workflow copy
|
||
| 57 | if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from])) |
||
| 58 | 1115:433d4f72a19b | Chris | @role.workflow_rules.copy(copy_from)
|
| 59 | 0:513646585e45 | Chris | end
|
| 60 | flash[:notice] = l(:notice_successful_create) |
||
| 61 | 1295:622f24f53b42 | Chris | redirect_to roles_path |
| 62 | 441:cbce1fd3b1b7 | Chris | else
|
| 63 | 1115:433d4f72a19b | Chris | @roles = Role.sorted.all |
| 64 | render :action => 'new' |
||
| 65 | 0:513646585e45 | Chris | end
|
| 66 | end
|
||
| 67 | |||
| 68 | def edit |
||
| 69 | 1115:433d4f72a19b | Chris | end
|
| 70 | |||
| 71 | def update |
||
| 72 | if request.put? and @role.update_attributes(params[:role]) |
||
| 73 | 0:513646585e45 | Chris | flash[:notice] = l(:notice_successful_update) |
| 74 | 1295:622f24f53b42 | Chris | redirect_to roles_path |
| 75 | 441:cbce1fd3b1b7 | Chris | else
|
| 76 | 1115:433d4f72a19b | Chris | render :action => 'edit' |
| 77 | 0:513646585e45 | Chris | end
|
| 78 | end
|
||
| 79 | |||
| 80 | def destroy |
||
| 81 | @role.destroy
|
||
| 82 | 1295:622f24f53b42 | Chris | redirect_to roles_path |
| 83 | 0:513646585e45 | Chris | rescue
|
| 84 | flash[:error] = l(:error_can_not_remove_role) |
||
| 85 | 1295:622f24f53b42 | Chris | redirect_to roles_path |
| 86 | 0:513646585e45 | Chris | end
|
| 87 | 909:cbb26bc654de | Chris | |
| 88 | 1115:433d4f72a19b | Chris | def permissions |
| 89 | @roles = Role.sorted.all |
||
| 90 | 0:513646585e45 | Chris | @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } |
| 91 | if request.post?
|
||
| 92 | @roles.each do |role| |
||
| 93 | role.permissions = params[:permissions][role.id.to_s]
|
||
| 94 | role.save |
||
| 95 | end
|
||
| 96 | flash[:notice] = l(:notice_successful_update) |
||
| 97 | 1295:622f24f53b42 | Chris | redirect_to roles_path |
| 98 | 0:513646585e45 | Chris | end
|
| 99 | end
|
||
| 100 | 1115:433d4f72a19b | Chris | |
| 101 | private |
||
| 102 | |||
| 103 | def find_role |
||
| 104 | @role = Role.find(params[:id]) |
||
| 105 | rescue ActiveRecord::RecordNotFound |
||
| 106 | render_404 |
||
| 107 | end
|
||
| 108 | 0:513646585e45 | Chris | end |