OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Extract permission check for share management to controller concern
Aaron Contreras36f6685a803c
diff --git a/app/components/shares/concerns/authorization.rb b/app/controllers/concerns/shares/work_packages/authorization.rbsimilarity index 78%rename from app/components/shares/concerns/authorization.rbrename to app/controllers/concerns/shares/work_packages/authorization.rbindex 6c5041866a9..32b4bf5f34e 100644--- a/app/components/shares/concerns/authorization.rb+++ b/app/controllers/concerns/shares/work_packages/authorization.rb@@ -2,7 +2,7 @@# -- copyright# OpenProject is an open source project management software.-# Copyright (C) 2023 the OpenProject GmbH+# Copyright (C) 2010-2024 the OpenProject GmbH## This program is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License version 3.@@ -29,14 +29,22 @@# ++module Shares- module Concerns+ module WorkPackagesmodule Authorizationextend ActiveSupport::Concernincluded dodef sharing_manageable?# TODO: Fix this to check based on the entity- User.current.allowed_in_project?(:share_work_packages, @entity.project)+ case @entity+ when WorkPackage+ User.current.allowed_in_project?(:share_work_packages, @entity.project)+ else+ raise ArgumentError, <<~ERROR+ Checking sharing capabilities for an unsupported entity:+ - #{@entity.class}+ ERROR+ endendendenddiff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rbindex f3a89fab62a..efb79c77f52 100644--- a/app/controllers/shares_controller.rb+++ b/app/controllers/shares_controller.rb@@ -28,6 +28,7 @@class SharesController < ApplicationControllerinclude OpTurbo::ComponentStream+ include Shares::WorkPackages::Authorizationinclude MemberHelperbefore_action :load_entity@@ -45,8 +46,7 @@ class SharesController < ApplicationControllerrender Shares::ModalBodyComponent.new(entity: @entity,shares: @shares,errors: @errors,- sharing_manageable: User.current.allowed_in_project?(:share_work_packages,- @entity.project),+ sharing_manageable: sharing_manageable?,available_roles:), layout: nilend@@ -156,8 +156,7 @@ class SharesController < ApplicationControllercomponent: Shares::ModalBodyComponent.new(entity: @entity,available_roles:,shares: @new_shares || load_shares,- sharing_manageable: User.current.allowed_in_project?(:share_work_packages,- @project),+ sharing_manageable: sharing_manageable?,errors: @errors))@@ -168,29 +167,24 @@ class SharesController < ApplicationControllerreplace_via_turbo_stream(component: Shares::InviteUserFormComponent.new(entity: @entity,available_roles:,- sharing_manageable: User.current.allowed_in_project?(:share_work_packages,- @project),+ sharing_manageable: sharing_manageable?,errors: @errors))update_via_turbo_stream(component: Shares::CounterComponent.new(entity: @entity,count: current_visible_member_count,- sharing_manageable: User.current.allowed_in_project?(:share_work_packages,- @project))+ sharing_manageable: sharing_manageable?))@new_shares.each do |share|prepend_via_turbo_stream(component: Shares::ShareRowComponent.new(share:,available_roles:,- sharing_manageable: User.current.allowed_in_project?(:share_work_packages,- @project)),+ sharing_manageable: sharing_manageable?),target_component: Shares::ModalBodyComponent.new(entity: @entity,available_roles:,- sharing_manageable: User.current.allowed_in_project?(- :share_work_packages, @project- ),+ sharing_manageable: sharing_manageable?,shares: load_shares,errors: @errors))@@ -202,9 +196,7 @@ class SharesController < ApplicationControllerdef respond_with_new_invite_formreplace_via_turbo_stream(component: Shares::InviteUserFormComponent.new(entity: @entity,available_roles:,- sharing_manageable: User.current.allowed_in_project?(- :share_work_packages, @project- ),+ sharing_manageable: sharing_manageable?,errors: @errors))respond_with_turbo_streams@@ -221,23 +213,17 @@ class SharesController < ApplicationControllerdef respond_with_remove_shareremove_via_turbo_stream(component: Shares::ShareRowComponent.new(share: @share,available_roles:,- sharing_manageable: User.current.allowed_in_project?(- :share_work_packages, @project- )))+ sharing_manageable: sharing_manageable?))update_via_turbo_stream(component: Shares::CounterComponent.new(entity: @entity,count: current_visible_member_count,- sharing_manageable: User.current.allowed_in_project?(- :share_work_packages, @project- )))+ sharing_manageable: sharing_manageable?))respond_with_turbo_streamsenddef respond_with_update_user_detailsupdate_via_turbo_stream(component: Shares::UserDetailsComponent.new(share: @share,- manager_mode: User.current.allowed_in_project?(- :share_work_packages, @entity.project- ),+ manager_mode: sharing_manageable?,invite_resent: true))respond_with_turbo_streams@@ -260,16 +246,14 @@ class SharesController < ApplicationControllerremove_via_turbo_stream(component: Shares::ShareRowComponent.new(share:,available_roles:,- sharing_manageable: User.current.allowed_in_project?(:share_work_packages,- @project))+ sharing_manageable: sharing_manageable?))endupdate_via_turbo_stream(component: Shares::CounterComponent.new(entity: @entity,count: current_visible_member_count,- sharing_manageable: User.current.allowed_in_project?(:share_work_packages,- @project))+ sharing_manageable: sharing_manageable?))respond_with_turbo_streams