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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. class PrincipalMembershipsController < ApplicationController
  19. layout 'admin'
  20. self.main_menu = false
  21. helper :members
  22. before_action :require_admin
  23. before_action :find_principal, :only => [:new, :create]
  24. before_action :find_membership, :only => [:edit, :update, :destroy]
  25. def new
  26. @projects = Project.active.all
  27. @roles = Role.find_all_givable
  28. respond_to do |format|
  29. format.html
  30. format.js
  31. end
  32. end
  33. def create
  34. @members = Member.create_principal_memberships(@principal, params[:membership])
  35. respond_to do |format|
  36. format.html { redirect_to_principal @principal }
  37. format.js
  38. end
  39. end
  40. def edit
  41. @roles = Role.givable.to_a
  42. end
  43. def update
  44. @membership.attributes = params.require(:membership).permit(:role_ids => [])
  45. @membership.save
  46. respond_to do |format|
  47. format.html { redirect_to_principal @principal }
  48. format.js
  49. end
  50. end
  51. def destroy
  52. if @membership.deletable?
  53. @membership.destroy
  54. end
  55. respond_to do |format|
  56. format.html { redirect_to_principal @principal }
  57. format.js
  58. end
  59. end
  60. private
  61. def find_principal
  62. principal_id = params[:user_id] || params[:group_id]
  63. @principal = Principal.find(principal_id)
  64. rescue ActiveRecord::RecordNotFound
  65. render_404
  66. end
  67. def find_membership
  68. @membership = Member.find(params[:id])
  69. @principal = @membership.principal
  70. rescue ActiveRecord::RecordNotFound
  71. render_404
  72. end
  73. def redirect_to_principal(principal)
  74. redirect_to edit_polymorphic_path(principal, :tab => 'memberships')
  75. end
  76. end