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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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 'admin'
  19. before_filter :require_admin, :except => [:index, :show]
  20. before_filter :require_admin_or_api_request, :only => [:index, :show]
  21. before_filter :find_role, :only => [:show, :edit, :update, :destroy]
  22. accept_api_auth :index, :show
  23. def index
  24. respond_to do |format|
  25. format.html {
  26. @role_pages, @roles = paginate Role.sorted, :per_page => 25
  27. render :action => "index", :layout => false if request.xhr?
  28. }
  29. format.api {
  30. @roles = Role.givable.all
  31. }
  32. end
  33. end
  34. def show
  35. respond_to do |format|
  36. format.api
  37. end
  38. end
  39. def new
  40. # Prefills the form with 'Non member' role permissions by default
  41. @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
  42. if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy])
  43. @role.copy_from(@copy_from)
  44. end
  45. @roles = Role.sorted.all
  46. end
  47. def create
  48. @role = Role.new(params[:role])
  49. if request.post? && @role.save
  50. # workflow copy
  51. if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
  52. @role.workflow_rules.copy(copy_from)
  53. end
  54. flash[:notice] = l(:notice_successful_create)
  55. redirect_to roles_path
  56. else
  57. @roles = Role.sorted.all
  58. render :action => 'new'
  59. end
  60. end
  61. def edit
  62. end
  63. def update
  64. if request.put? and @role.update_attributes(params[:role])
  65. flash[:notice] = l(:notice_successful_update)
  66. redirect_to roles_path
  67. else
  68. render :action => 'edit'
  69. end
  70. end
  71. def destroy
  72. @role.destroy
  73. redirect_to roles_path
  74. rescue
  75. flash[:error] = l(:error_can_not_remove_role)
  76. redirect_to roles_path
  77. end
  78. def permissions
  79. @roles = Role.sorted.all
  80. @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
  81. if request.post?
  82. @roles.each do |role|
  83. role.permissions = params[:permissions][role.id.to_s]
  84. role.save
  85. end
  86. flash[:notice] = l(:notice_successful_update)
  87. redirect_to roles_path
  88. end
  89. end
  90. private
  91. def find_role
  92. @role = Role.find(params[:id])
  93. rescue ActiveRecord::RecordNotFound
  94. render_404
  95. end
  96. end