You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

roles_controller.rb 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # redMine - project management software
  2. # Copyright (C) 2006 Jean-Philippe Lang
  3. #
  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. #
  9. # 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. #
  14. # 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. class RolesController < ApplicationController
  18. layout 'base'
  19. before_filter :require_admin
  20. verify :method => :post, :only => [ :destroy, :move ],
  21. :redirect_to => { :action => :list }
  22. def index
  23. list
  24. render :action => 'list' unless request.xhr?
  25. end
  26. def list
  27. @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
  28. render :action => "list", :layout => false if request.xhr?
  29. end
  30. def new
  31. # Prefills the form with 'Non member' role permissions
  32. @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
  33. if request.post? && @role.save
  34. # workflow copy
  35. if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
  36. @role.workflows.copy(copy_from)
  37. end
  38. flash[:notice] = l(:notice_successful_create)
  39. redirect_to :action => 'list'
  40. end
  41. @permissions = @role.setable_permissions
  42. @roles = Role.find :all, :order => 'builtin, position'
  43. end
  44. def edit
  45. @role = Role.find(params[:id])
  46. if request.post? and @role.update_attributes(params[:role])
  47. flash[:notice] = l(:notice_successful_update)
  48. redirect_to :action => 'list'
  49. end
  50. @permissions = @role.setable_permissions
  51. end
  52. def destroy
  53. @role = Role.find(params[:id])
  54. @role.destroy
  55. redirect_to :action => 'list'
  56. rescue
  57. flash[:error] = 'This role is in use and can not be deleted.'
  58. redirect_to :action => 'index'
  59. end
  60. def move
  61. @role = Role.find(params[:id])
  62. case params[:position]
  63. when 'highest'
  64. @role.move_to_top
  65. when 'higher'
  66. @role.move_higher
  67. when 'lower'
  68. @role.move_lower
  69. when 'lowest'
  70. @role.move_to_bottom
  71. end if params[:position]
  72. redirect_to :action => 'list'
  73. end
  74. def workflow
  75. @role = Role.find_by_id(params[:role_id])
  76. @tracker = Tracker.find_by_id(params[:tracker_id])
  77. if request.post?
  78. Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
  79. (params[:issue_status] || []).each { |old, news|
  80. news.each { |new|
  81. @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
  82. }
  83. }
  84. if @role.save
  85. flash[:notice] = l(:notice_successful_update)
  86. redirect_to :action => 'workflow', :role_id => @role, :tracker_id => @tracker
  87. end
  88. end
  89. @roles = Role.find(:all, :order => 'builtin, position')
  90. @trackers = Tracker.find(:all, :order => 'position')
  91. @statuses = IssueStatus.find(:all, :order => 'position')
  92. end
  93. def report
  94. @roles = Role.find(:all, :order => 'builtin, position')
  95. @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
  96. if request.post?
  97. @roles.each do |role|
  98. role.permissions = params[:permissions][role.id.to_s]
  99. role.save
  100. end
  101. flash[:notice] = l(:notice_successful_update)
  102. redirect_to :action => 'list'
  103. end
  104. end
  105. end