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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. def index
  21. list
  22. render :action => 'list' unless request.xhr?
  23. end
  24. def list
  25. @role_pages, @roles = paginate :roles, :per_page => 10
  26. render :action => "list", :layout => false if request.xhr?
  27. end
  28. def new
  29. @role = Role.new(params[:role])
  30. if request.post?
  31. @role.permissions = Permission.find(@params[:permission_ids]) if @params[:permission_ids]
  32. if @role.save
  33. flash[:notice] = l(:notice_successful_create)
  34. redirect_to :action => 'list'
  35. end
  36. end
  37. @permissions = Permission.find(:all, :conditions => ["is_public=?", false], :order => 'sort ASC')
  38. end
  39. def edit
  40. @role = Role.find(params[:id])
  41. if request.post? and @role.update_attributes(params[:role])
  42. @role.permissions = Permission.find(@params[:permission_ids] || [])
  43. Permission.allowed_to_role_expired
  44. flash[:notice] = l(:notice_successful_update)
  45. redirect_to :action => 'list'
  46. end
  47. @permissions = Permission.find(:all, :conditions => ["is_public=?", false], :order => 'sort ASC')
  48. end
  49. def destroy
  50. @role = Role.find(params[:id])
  51. unless @role.members.empty?
  52. flash[:notice] = 'Some members have this role. Can\'t delete it.'
  53. else
  54. @role.destroy
  55. end
  56. redirect_to :action => 'list'
  57. end
  58. def workflow
  59. @role = Role.find_by_id(params[:role_id])
  60. @tracker = Tracker.find_by_id(params[:tracker_id])
  61. if request.post?
  62. Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
  63. (params[:issue_status] || []).each { |old, news|
  64. news.each { |new|
  65. @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
  66. }
  67. }
  68. if @role.save
  69. flash[:notice] = l(:notice_successful_update)
  70. end
  71. end
  72. @roles = Role.find_all
  73. @trackers = Tracker.find_all
  74. @statuses = IssueStatus.find(:all, :include => :workflows)
  75. end
  76. end