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 2.8KB

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