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.

principal_memberships_controller.rb 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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 PrincipalMembershipsController < ApplicationController
  18. layout 'admin'
  19. self.main_menu = false
  20. before_action :require_admin
  21. before_action :find_principal, :only => [:new, :create]
  22. before_action :find_membership, :only => [:edit, :update, :destroy]
  23. def new
  24. @projects = Project.active.all
  25. @roles = Role.find_all_givable
  26. respond_to do |format|
  27. format.html
  28. format.js
  29. end
  30. end
  31. def create
  32. @members = Member.create_principal_memberships(@principal, params[:membership])
  33. respond_to do |format|
  34. format.html { redirect_to_principal @principal }
  35. format.js
  36. end
  37. end
  38. def edit
  39. @roles = Role.givable.to_a
  40. end
  41. def update
  42. @membership.attributes = params.require(:membership).permit(:role_ids => [])
  43. @membership.save
  44. respond_to do |format|
  45. format.html { redirect_to_principal @principal }
  46. format.js
  47. end
  48. end
  49. def destroy
  50. if @membership.deletable?
  51. @membership.destroy
  52. end
  53. respond_to do |format|
  54. format.html { redirect_to_principal @principal }
  55. format.js
  56. end
  57. end
  58. private
  59. def find_principal
  60. principal_id = params[:user_id] || params[:group_id]
  61. @principal = Principal.find(principal_id)
  62. rescue ActiveRecord::RecordNotFound
  63. render_404
  64. end
  65. def find_membership
  66. @membership = Member.find(params[:id])
  67. @principal = @membership.principal
  68. rescue ActiveRecord::RecordNotFound
  69. render_404
  70. end
  71. def redirect_to_principal(principal)
  72. redirect_to edit_polymorphic_path(principal, :tab => 'memberships')
  73. end
  74. end