diff --git a/config/settings.yml b/config/settings.yml index 514462d5..7698fd9c 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -18,3 +18,6 @@ plugins: wizard_important_notices_on_dashboard: client: true default: true + wizard_subscription_product_key: + hidden: true + default: '' diff --git a/lib/custom_wizard/subscription.rb b/lib/custom_wizard/subscription.rb index 14b95843..0712b170 100644 --- a/lib/custom_wizard/subscription.rb +++ b/lib/custom_wizard/subscription.rb @@ -136,7 +136,14 @@ class CustomWizard::Subscription @product_slug = id_and_slug[:slug] end - @product_slug ||= ENV["CUSTOM_WIZARD_PRODUCT_SLUG"] + @product_slug ||= + ( + if ENV["CUSTOM_WIZARD_PRODUCT_SLUG"].present? + ENV["CUSTOM_WIZARD_PRODUCT_SLUG"] + else + SiteSetting.wizard_subscription_product_key + end + ) end def includes?(feature, attribute, value = nil) diff --git a/plugin.rb b/plugin.rb index 12a33620..03656a85 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.11.2 +# version: 2.11.3 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Juan Marcos Gutierrez Ramos # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech diff --git a/spec/components/custom_wizard/subscription_spec.rb b/spec/components/custom_wizard/subscription_spec.rb index f1b85ab4..f5029685 100644 --- a/spec/components/custom_wizard/subscription_spec.rb +++ b/spec/components/custom_wizard/subscription_spec.rb @@ -146,4 +146,22 @@ describe CustomWizard::Subscription do end end end + + context "with a site setting" do + before { SiteSetting.wizard_subscription_product_key = "standard" } + + after { SiteSetting.wizard_subscription_product_key = nil } + + it "enables the relevant subscription" do + expect(described_class.type).to eq(:standard) + end + + context "with a subscription" do + before { enable_subscription("business") } + + it "respects the subscription" do + expect(described_class.type).to eq(:business) + end + end + end end