Skip to content

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

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.erb
index 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))
end
end
%>
diff --git a/app/components/shares/modal_upsale_component.html.erb b/app/components/shares/work_packages/modal_upsale_component.html.erb
similarity index 96%
rename from app/components/shares/modal_upsale_component.html.erb
rename to app/components/shares/work_packages/modal_upsale_component.html.erb
index 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 text
component.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.rb
similarity index 80%
rename from app/components/shares/modal_upsale_component.rb
rename to app/components/shares/work_packages/modal_upsale_component.rb
index 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"
+ end
end
end
end
diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rb
index f4e0d8a6d08..a3272a1c0bb 100644
--- a/app/controllers/shares_controller.rb
+++ b/app/controllers/shares_controller.rb
@@ -34,7 +34,6 @@ class SharesController < ApplicationController
before_action :load_entity
before_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 < ApplicationController
flash.now[:error] = sharing_strategy.query.errors.full_messages
end
- render Shares::ModalBodyComponent.new(strategy: sharing_strategy, errors: @errors), layout: nil
+ render sharing_strategy.modal_body_component(@errors), layout: nil
end
def create # rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity
@@ -147,12 +146,6 @@ class SharesController < ApplicationController
render_403
end
- 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.rb
index 56ac9de26f5..deb9523fae1 100644
--- a/app/models/sharing_strategies/base_strategy.rb
+++ b/app/models/sharing_strategies/base_strategy.rb
@@ -85,6 +85,10 @@ module SharingStrategies
nil
end
+ def modal_body_component(errors)
+ Shares::ModalBodyComponent.new(strategy: self, errors:)
+ end
+
def query # rubocop:disable Metrics/AbcSize
return @query if defined?(@query)
diff --git a/app/models/sharing_strategies/work_package_strategy.rb b/app/models/sharing_strategies/work_package_strategy.rb
index 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 SharingStrategies
Shares::WorkPackages::DeleteContract
end
+ def modal_body_component(errors)
+ if EnterpriseToken.allows_to?(:work_package_sharing)
+ super
+ else
+ Shares::WorkPackages::ModalUpsaleComponent.new
+ end
+ end
+
private
def project_member?(share)