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
Adapt sharing dialog to include banner
Oliver Güntherc2d48fc980b1
diff --git a/app/components/shares/manage_shares_component.html.erb b/app/components/shares/manage_shares_component.html.erbindex 4412dbce2ae..502e811d502 100644--- a/app/components/shares/manage_shares_component.html.erb+++ b/app/components/shares/manage_shares_component.html.erb@@ -1,4 +1,10 @@<%=+ if strategy.enterprise_feature+ modal_content.with_row do+ render(EnterpriseEdition::BannerComponent.new(strategy.enterprise_feature))+ end+ end+if strategy.manageable?modal_content.with_row dorender(Shares::InviteUserFormComponent.new(strategy:, errors:))diff --git a/app/components/shares/modal_body_component.html.erb b/app/components/shares/modal_body_component.html.erbindex 7612091818c..3bc42afca95 100644--- a/app/components/shares/modal_body_component.html.erb+++ b/app/components/shares/modal_body_component.html.erb@@ -7,8 +7,7 @@endend- render(strategy.upsell_banner(modal_content:))- render(strategy.manage_shares_component(modal_content:, errors:)) if strategy.allow_feature?+ render(strategy.manage_shares_component(modal_content:, errors:))endend%>diff --git a/app/components/shares/project_queries/upsell_component.html.erb b/app/components/shares/project_queries/upsell_component.html.erbdeleted file mode 100644index 083a767ea13..00000000000--- a/app/components/shares/project_queries/upsell_component.html.erb+++ /dev/null@@ -1,5 +0,0 @@-<%=- modal_content.with_row(data: { "test-selector": "op-share-dialog-upsell-block" }) do- render(EnterpriseEdition::BannerComponent.new(:project_list_sharing, dismissable: true))- end-%>diff --git a/app/components/shares/project_queries/upsell_component.rb b/app/components/shares/project_queries/upsell_component.rbdeleted file mode 100644index 1777943ad30..00000000000--- a/app/components/shares/project_queries/upsell_component.rb+++ /dev/null@@ -1,43 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 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.-#-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-# Copyright (C) 2006-2013 Jean-Philippe Lang-# Copyright (C) 2010-2013 the ChiliProject Team-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License-# as published by the Free Software Foundation; either version 2-# of the License, or (at your option) any later version.-#-# This program is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU General Public License-# along with this program; if not, write to the Free Software-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-#-# See COPYRIGHT and LICENSE files for more details.-#++--module Shares- module ProjectQueries- class UpsellComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent- include OpPrimer::ComponentHelpers-- def initialize(modal_content:)- super-- @modal_content = modal_content- end-- attr_reader :modal_content- end- end-enddiff --git a/app/components/shares/work_packages/modal_upsell_component.html.erb b/app/components/shares/work_packages/modal_upsell_component.html.erbdeleted file mode 100644index f10285902d1..00000000000--- a/app/components/shares/work_packages/modal_upsell_component.html.erb+++ /dev/null@@ -1,7 +0,0 @@-<%=- component_wrapper(tag: "turbo-frame") do- modal_content.with_row do- render(EnterpriseEdition::BannerComponent.new(:work_package_sharing))- end- end-%>diff --git a/app/components/shares/work_packages/modal_upsell_component.rb b/app/components/shares/work_packages/modal_upsell_component.rbdeleted file mode 100644index a26e98f422c..00000000000--- a/app/components/shares/work_packages/modal_upsell_component.rb+++ /dev/null@@ -1,49 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 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.-#-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-# Copyright (C) 2006-2013 Jean-Philippe Lang-# Copyright (C) 2010-2013 the ChiliProject Team-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License-# as published by the Free Software Foundation; either version 2-# of the License, or (at your option) any later version.-#-# This program is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU General Public License-# along with this program; if not, write to the Free Software-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-#-# See COPYRIGHT and LICENSE files for more details.-#++--module Shares- module WorkPackages- class ModalUpsellComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent- include ApplicationHelper- include OpTurbo::Streamable- include OpPrimer::ComponentHelpers-- def initialize(modal_content:)- super-- @modal_content = modal_content- end-- attr_reader :modal_content-- def self.wrapper_key- "share_modal_body"- end- end- end-enddiff --git a/app/models/sharing_strategies/base_strategy.rb b/app/models/sharing_strategies/base_strategy.rbindex bff01d94d89..4577526b815 100644--- a/app/models/sharing_strategies/base_strategy.rb+++ b/app/models/sharing_strategies/base_strategy.rb@@ -70,6 +70,16 @@ module SharingStrategiesraise NotImplementedError, "Override in a subclass and return a title for the sharing dialog"end+ def enterprise_feature+ nil+ end++ def feature_available?+ return true if enterprise_feature.nil?++ EnterpriseToken.allows_to?(enterprise_feature)+ end+def custom_body_components?!additional_body_components.empty?enddiff --git a/app/models/sharing_strategies/project_query_strategy.rb b/app/models/sharing_strategies/project_query_strategy.rbindex cd30bb88804..88dd3828cba 100644--- a/app/models/sharing_strategies/project_query_strategy.rb+++ b/app/models/sharing_strategies/project_query_strategy.rb@@ -47,7 +47,7 @@ module SharingStrategiesenddef manageable?- @entity.editable?+ @entity.editable? && feature_available?enddef viewable?@@ -105,17 +105,12 @@ module SharingStrategiesendend- def title- I18n.t(:label_share_project_list)- end-- def upsell_banner(modal_content:)- Shares::ProjectQueries::UpsellComponent.new(modal_content:)+ def enterprise_feature+ :project_list_sharingend- def allow_feature?- EnterpriseToken.allows_to?(:project_list_sharing) ||- EnterpriseToken.trialling?(:project_list_sharing)+ def title+ I18n.t(:label_share_project_list)endprivatediff --git a/app/models/sharing_strategies/work_package_strategy.rb b/app/models/sharing_strategies/work_package_strategy.rbindex e398663d0e9..b7702ecdbf6 100644--- a/app/models/sharing_strategies/work_package_strategy.rb+++ b/app/models/sharing_strategies/work_package_strategy.rb@@ -46,7 +46,7 @@ module SharingStrategiesenddef manageable?- user.allowed_in_project?(:share_work_packages, @entity.project)+ feature_available? && user.allowed_in_project?(:share_work_packages, @entity.project)enddef viewable?@@ -103,13 +103,8 @@ module SharingStrategiesI18n.t(:label_share_work_package)end- def upsell_banner(modal_content:)- Shares::WorkPackages::ModalUpsellComponent.new(modal_content:)- end-- def allow_feature?- EnterpriseToken.allows_to?(:work_package_sharing) ||- EnterpriseToken.trialling?(:work_package_sharing)+ def enterprise_feature+ :work_package_sharingendprivatediff --git a/spec/controllers/shares_controller_spec.rb b/spec/controllers/shares_controller_spec.rbindex 911a4755c8c..69e8f92b6ae 100644--- a/spec/controllers/shares_controller_spec.rb+++ b/spec/controllers/shares_controller_spec.rb@@ -196,13 +196,13 @@ RSpec.describe SharesController docontext "when the strategy allows viewing but enterprise check fails" dobefore doallow_any_instance_of(SharingStrategies::ProjectQueryStrategy).to receive_messages(viewable?: true, manageable?: false)- allow(Shares::ProjectQueries::UpsellComponent).to receive(:new).and_call_original+ allow(EnterpriseEdition::BannerComponent).to receive(:new).and_call_originalendit "renders the upsell component" domake_requestexpect(response).to have_http_status(:ok)- expect(Shares::ProjectQueries::UpsellComponent).to have_received(:new)+ expect(EnterpriseEdition::BannerComponent).to have_received(:new)endend@@ -230,13 +230,13 @@ RSpec.describe SharesController doallow_any_instance_of(SharingStrategies::ProjectQueryStrategy).to receive_messages(viewable?: false, manageable?: true)- allow(Shares::ProjectQueries::UpsellComponent).to receive(:new).and_call_original+ allow(EnterpriseEdition::BannerComponent).to receive(:new).and_call_originalend- it "renders the upsell component" do+ it "renders a banner component" domake_requestexpect(response).to have_http_status(:ok)- expect(Shares::ProjectQueries::UpsellComponent).to have_received(:new)+ expect(EnterpriseEdition::BannerComponent).to have_received(:new)endenddiff --git a/spec/models/sharing_strategies/project_query_strategy_spec.rb b/spec/models/sharing_strategies/project_query_strategy_spec.rbindex fdee828bb86..c14c23bc67e 100644--- a/spec/models/sharing_strategies/project_query_strategy_spec.rb+++ b/spec/models/sharing_strategies/project_query_strategy_spec.rb@@ -66,10 +66,14 @@ RSpec.describe SharingStrategies::ProjectQueryStrategy doenddescribe "#manageable?" do- context "when the entity is editable" do+ context "when the entity is editable, and the feature available", with_ee: %i[project_list_sharing] doit { expect(strategy.manageable?).to be(true) }end+ context "when the entity is editable, but feature is not available" do+ it { expect(strategy.manageable?).to be(false) }+ end+context "when the entity is not editable" dolet(:entity) { instance_double(ProjectQuery, editable?: false, visible?: true) }diff --git a/spec/models/sharing_strategies/work_package_strategy_spec.rb b/spec/models/sharing_strategies/work_package_strategy_spec.rbindex ccb94a6a178..d866dc57aab 100644--- a/spec/models/sharing_strategies/work_package_strategy_spec.rb+++ b/spec/models/sharing_strategies/work_package_strategy_spec.rb@@ -71,7 +71,13 @@ RSpec.describe SharingStrategies::WorkPackageStrategy doendend- it { expect(strategy).to be_manageable }+ context "when feature is available", with_ee: %i[work_package_sharing] do+ it { expect(strategy.manageable?).to be(true) }+ end++ context "when feature is not available" do+ it { expect(strategy.manageable?).to be(false) }+ endendcontext "without permissions to share the work package" do