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

Add helper method to wrap banner and content into one check

Oliver Güntherc304da7aa2c8
diff --git a/app/components/enterprise_edition/banner_component.html.erb b/app/components/enterprise_edition/banner_component.html.erb
index 53572d7b407..91c4fd6e3d4 100644
--- a/app/components/enterprise_edition/banner_component.html.erb
+++ b/app/components/enterprise_edition/banner_component.html.erb
@@ -98,4 +98,3 @@
end
end
%>
-<%= content if feature_available? %>
diff --git a/app/helpers/enterprise_helper.rb b/app/helpers/enterprise_helper.rb
index ffc04cb7eb7..8d78875fb6d 100644
--- a/app/helpers/enterprise_helper.rb
+++ b/app/helpers/enterprise_helper.rb
@@ -29,6 +29,14 @@
#++
module EnterpriseHelper
+ ##
+ # Renders the enterprise banner component with a guard for the given feature key.
+ # If the feature is not enabled, it will not render the given block.
+ def with_enterprise_banner_guard(feature_key, **args)
+ concat(render(EnterpriseEdition::BannerComponent.new(feature_key, **args)))
+ yield if EnterpriseToken.allows_to?(feature_key)
+ end
+
def enterprise_angular_trial_inputs
trial_key = Token::EnterpriseTrialKey.find_by(user_id: User.system.id)
diff --git a/app/views/custom_actions/index.html.erb b/app/views/custom_actions/index.html.erb
index 56ca8ed0b82..afff2b400c5 100644
--- a/app/views/custom_actions/index.html.erb
+++ b/app/views/custom_actions/index.html.erb
@@ -28,10 +28,7 @@
%>
<%=
- render EnterpriseEdition::BannerComponent.new(
- :custom_actions,
- variant: :large,
- video: "enterprise/custom-actions.mp4"
- ) do %>
- <%= render(::CustomActions::TableComponent.new(rows: @custom_actions)) %>
-<% end %>
+ with_enterprise_banner_guard(:custom_actions, variant: :large, video: "enterprise/custom-actions.mp4") do
+ render(::CustomActions::TableComponent.new(rows: @custom_actions))
+ end
+%>
diff --git a/app/views/custom_styles/show.html.erb b/app/views/custom_styles/show.html.erb
index 89fd91246a8..c4acd4a6312 100644
--- a/app/views/custom_styles/show.html.erb
+++ b/app/views/custom_styles/show.html.erb
@@ -27,7 +27,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<%= render EnterpriseEdition::BannerComponent.new(
+<%= with_enterprise_banner_guard(
:define_custom_style,
variant: :large,
video: "enterprise/custom-design.mp4"
diff --git a/lookbook/docs/components/enterprise.md.erb b/lookbook/docs/components/enterprise.md.erb
index ffe04de8bd0..7c78e832ed4 100644
--- a/lookbook/docs/components/enterprise.md.erb
+++ b/lookbook/docs/components/enterprise.md.erb
@@ -21,17 +21,6 @@ For each banner, you can provide:
If you don't provide a title for the upsell banner, it will simply use the name of the feature.
-### Passing through content
-
-You can pass through additional content to the upsell banner, which will be rendered below the banner if the feature is available
-
-
-```erb
-<%%= render EnterpriseEdition::BannerComponent.new(:enterprise_feature) do %%>
- Some additional content that will be rendered below the banner, only if the feature is available
-<%% end %%>
-```
-
### Defining the text
This is the default convention:
@@ -137,3 +126,16 @@ render EnterpriseEdition::BannerComponent.new(
```
<%= embed OpenProject::EnterpriseEdition::BannerComponentPreview, :large, panels: %i[] %>
+
+### Passing through content
+
+You can use the helper method `with_enterprise_banner_guard` to conditionally render content based on the availability of an enterprise feature,
+and render a banner at the same time.
+
+This is useful when you want to show content only if the feature is available in the user's current plan.
+
+```erb
+<%%= with_enterprise_banner_guard(:enterprise_feature, **banner_args) do %>
+ Some additional content that will be rendered below the banner, only if the feature is available
+<%% end %>
+```
diff --git a/modules/ldap_groups/spec/features/administration_spec.rb b/modules/ldap_groups/spec/features/administration_spec.rb
index dcc2408deae..85913001bc5 100644
--- a/modules/ldap_groups/spec/features/administration_spec.rb
+++ b/modules/ldap_groups/spec/features/administration_spec.rb
@@ -10,8 +10,7 @@ RSpec.describe "LDAP group sync administration spec", :js do
context "without EE" do
it "shows upsell" do
- expect(page).to have_enterprise_upsell_page
- expect(page).to have_text "Available starting with the Premium enterprise plan"
+ expect(page).to have_enterprise_banner(:premium)
end
end
diff --git a/modules/team_planner/app/views/team_planner/team_planner/index.html.erb b/modules/team_planner/app/views/team_planner/team_planner/index.html.erb
index 301f72e714e..5d78ee36518 100644
--- a/modules/team_planner/app/views/team_planner/team_planner/index.html.erb
+++ b/modules/team_planner/app/views/team_planner/team_planner/index.html.erb
@@ -17,12 +17,11 @@
%>
<%=
- render(EnterpriseEdition::BannerComponent.new(
+ with_enterprise_banner_guard(
:team_planner_view,
variant: :large,
video: "enterprise/team-planner-animation.mp4"
- )) do %>
-
-<%= render ::TeamPlanner::TableComponent.new(rows: @views, current_user: current_user) %>
-
-<% end %>
+ ) do
+ render ::TeamPlanner::TableComponent.new(rows: @views, current_user: current_user)
+ end
+%>
diff --git a/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb b/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb
index a68d3a7fa71..e8ca63d351c 100644
--- a/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb
+++ b/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb
@@ -16,10 +16,11 @@
%>
<%=
- render(EnterpriseEdition::BannerComponent.new(
+ with_enterprise_banner_guard(
:team_planner_view,
variant: :large,
video: "enterprise/team-planner-animation.mp4"
- )) do %>
- <%= render ::TeamPlanner::Overview::TableComponent.new(rows: @views, current_user: current_user) %>
-<% end %>
+ ) do
+ render ::TeamPlanner::Overview::TableComponent.new(rows: @views, current_user: current_user)
+ end
+%>