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

Raise error when feature cannot be found

Oliver Güntherb10971ed5d99
diff --git a/app/components/enterprise_edition/plan_for_feature.rb b/app/components/enterprise_edition/plan_for_feature.rb
index 108572a0b3a..6341e5e29d1 100644
--- a/app/components/enterprise_edition/plan_for_feature.rb
+++ b/app/components/enterprise_edition/plan_for_feature.rb
@@ -64,18 +64,25 @@ module EnterpriseEdition
end
def features
- return @features if defined?(@features)
+ defined?(@features) || begin
+ @features = I18n.t(:features, scope: i18n_scope, default: nil)&.values
+ end
@features = I18n.t(:features, scope: i18n_scope, default: nil)&.values
end
def plan
- @plan ||= OpenProject::Token.lowest_plan_for(feature_key)&.capitalize
+ defined?(@plan) || begin
+ @plan = OpenProject::Token.lowest_plan_for(feature_key)
+ raise ArgumentError, "#{feature_key} is not a valid feature, as no plan mapped to it." if @plan.nil?
+ end
+
+ @plan
end
def plan_text
plan_name = render(Primer::Beta::Text.new(font_weight: :bold, classes: "upsell-colored")) do
- I18n.t("ee.upsell.plan_name", plan:)
+ I18n.t("ee.upsell.plan_name", plan: plan.capitalize)
end
I18n.t("ee.upsell.plan_text_html", plan_name:).html_safe
diff --git a/spec/components/enterprise_edition/banner_component_spec.rb b/spec/components/enterprise_edition/banner_component_spec.rb
index 24ed35edbef..65b43e77ba7 100644
--- a/spec/components/enterprise_edition/banner_component_spec.rb
+++ b/spec/components/enterprise_edition/banner_component_spec.rb
@@ -38,6 +38,7 @@ RSpec.describe EnterpriseEdition::BannerComponent, type: :component do
let(:href) { "https://www.example.org" }
let(:component_test_selector) { "op-enterprise-banner" }
let(:features) { nil }
+ let(:plan) { :basic }
let(:enforce_available_locales) { I18n.config.enforce_available_locales }
let(:i18n_upsell) do
{
@@ -84,6 +85,11 @@ RSpec.describe EnterpriseEdition::BannerComponent, type: :component do
.to receive(:links)
.and_return(static_links)
+ allow(OpenProject::Token)
+ .to receive(:lowest_plan_for)
+ .with(:some_enterprise_feature)
+ .and_return(plan)
+
I18n.config.enforce_available_locales = !enforce_available_locales
I18n.backend.store_translations(