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
Move enterprise check into the sharing strategy
Klaus Zandersf7cef0e47133
diff --git a/app/components/shares/share_dialog_component.html.erb b/app/components/shares/share_dialog_component.html.erbindex 3bfaad1719a..885fae1ddcf 100644--- a/app/components/shares/share_dialog_component.html.erb+++ b/app/components/shares/share_dialog_component.html.erb@@ -2,7 +2,7 @@render(Primer::Alpha::Dialog.new(title: t(:label_share_project_list), id: 'sharing-modal', data: { 'keep-open-on-submit': true }, size: :xlarge)) do |d|d.with_header(variant: :large, mb: 3)d.with_body do- render(Shares::ModalBodyComponent.new(strategy:, errors:))+ render(strategy.modal_body_component(errors))endend%>diff --git a/app/components/shares/modal_upsale_component.html.erb b/app/components/shares/work_packages/modal_upsale_component.html.erbsimilarity index 96%rename from app/components/shares/modal_upsale_component.html.erbrename to app/components/shares/work_packages/modal_upsale_component.html.erbindex 9f6cc4ae3e2..2d5f3269a0d 100644--- a/app/components/shares/modal_upsale_component.html.erb+++ b/app/components/shares/work_packages/modal_upsale_component.html.erb@@ -3,7 +3,6 @@render Primer::Beta::Blankslate.new(border: true) do |component|component.with_visual_icon(icon: :'op-enterprise-addons', classes: 'upsale-colored')component.with_heading(tag: :h2, classes: 'upsale-colored').with_content(I18n.t(:label_enterprise_addon))- # TODO: Generalize this textcomponent.with_description { I18n.t('mail.sharing.work_packages.enterprise_text') }href = "#{OpenProject::Static::Links.links[:upsale][:href]}/?utm_source=unknown&utm_medium=community-edition&utm_campaign=work-package-sharing-modal"diff --git a/app/components/shares/modal_upsale_component.rb b/app/components/shares/work_packages/modal_upsale_component.rbsimilarity index 80%rename from app/components/shares/modal_upsale_component.rbrename to app/components/shares/work_packages/modal_upsale_component.rbindex 621b180e08a..65ab5a94c60 100644--- a/app/components/shares/modal_upsale_component.rb+++ b/app/components/shares/work_packages/modal_upsale_component.rb@@ -27,13 +27,15 @@#++module Shares- class ModalUpsaleComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent- include ApplicationHelper- include OpTurbo::Streamable- include OpPrimer::ComponentHelpers+ module WorkPackages+ class ModalUpsaleComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent+ include ApplicationHelper+ include OpTurbo::Streamable+ include OpPrimer::ComponentHelpers- def self.wrapper_key- "share_modal_body"+ def self.wrapper_key+ "share_modal_body"+ endendendenddiff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rbindex f4e0d8a6d08..a3272a1c0bb 100644--- a/app/controllers/shares_controller.rb+++ b/app/controllers/shares_controller.rb@@ -34,7 +34,6 @@ class SharesController < ApplicationControllerbefore_action :load_entitybefore_action :load_selected_shares, only: %i[bulk_update bulk_destroy]before_action :load_share, only: %i[destroy update resend_invite]- before_action :enterprise_check, only: %i[index]before_action :check_if_manageable, except: %i[index dialog]before_action :check_if_viewable, only: %i[index dialog]@@ -47,7 +46,7 @@ class SharesController < ApplicationControllerflash.now[:error] = sharing_strategy.query.errors.full_messagesend- render Shares::ModalBodyComponent.new(strategy: sharing_strategy, errors: @errors), layout: nil+ render sharing_strategy.modal_body_component(@errors), layout: nilenddef create # rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity@@ -147,12 +146,6 @@ class SharesController < ApplicationControllerrender_403end- def enterprise_check- return if EnterpriseToken.allows_to?(:work_package_sharing)-- render Shares::ModalUpsaleComponent.new- end-def destroy_share(share)Shares::DeleteService.new(user: current_user, model: share, contract_class: sharing_strategy.delete_contract_class)diff --git a/app/models/sharing_strategies/base_strategy.rb b/app/models/sharing_strategies/base_strategy.rbindex 56ac9de26f5..deb9523fae1 100644--- a/app/models/sharing_strategies/base_strategy.rb+++ b/app/models/sharing_strategies/base_strategy.rb@@ -85,6 +85,10 @@ module SharingStrategiesnilend+ def modal_body_component(errors)+ Shares::ModalBodyComponent.new(strategy: self, errors:)+ end+def query # rubocop:disable Metrics/AbcSizereturn @query if defined?(@query)diff --git a/app/models/sharing_strategies/work_package_strategy.rb b/app/models/sharing_strategies/work_package_strategy.rbindex 09bf0f8685e..1a16bdc7634 100644--- a/app/models/sharing_strategies/work_package_strategy.rb+++ b/app/models/sharing_strategies/work_package_strategy.rb@@ -99,6 +99,14 @@ module SharingStrategiesShares::WorkPackages::DeleteContractend+ def modal_body_component(errors)+ if EnterpriseToken.allows_to?(:work_package_sharing)+ super+ else+ Shares::WorkPackages::ModalUpsaleComponent.new+ end+ end+privatedef project_member?(share)