diff --git a/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 b/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 index 58c6715d..bb29653b 100644 --- a/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 +++ b/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 @@ -46,10 +46,9 @@ export default SingleSelectComponent.extend(Subscription, { if (allowGuests) { const filteredFeature = wizardSchema.filters.allow_guests[feature]; if (filteredFeature) { - const filteredAttribute = filteredFeature[attribute]; if (filteredAttribute) { - attributes = attributes.filter(a => filteredAttribute.includes(a)) + attributes = attributes.filter((a) => filteredAttribute.includes(a)); } } } diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 350d91a1..d6d9d49d 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -18,7 +18,6 @@ const wizard = { allow_guests: null, theme_id: null, permitted: null, - allow_guests: null }, mapped: ["permitted"], required: ["id"], @@ -209,10 +208,10 @@ const action = { const filters = { allow_guests: { action: { - type: ['route_to', 'send_message'] - } - } -} + type: ["route_to", "send_message"], + }, + }, +}; const custom_field = { klass: ["topic", "post", "group", "category"], @@ -228,7 +227,7 @@ const wizardSchema = { field, custom_field, action, - filters + filters, }; export function buildFieldTypes(types) { diff --git a/assets/javascripts/discourse/routes/custom-wizard-index.js.es6 b/assets/javascripts/discourse/routes/custom-wizard-index.js.es6 index d6917650..f7860ef8 100644 --- a/assets/javascripts/discourse/routes/custom-wizard-index.js.es6 +++ b/assets/javascripts/discourse/routes/custom-wizard-index.js.es6 @@ -6,6 +6,7 @@ export default Route.extend({ const wizard = getCachedWizard(); if ( wizard && + (wizard.user || wizard.allow_guests) && wizard.permitted && !wizard.completed && wizard.start diff --git a/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 b/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 index dd7b8be8..3193d783 100644 --- a/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 +++ b/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 @@ -7,7 +7,12 @@ export default Route.extend({ const wizard = getCachedWizard(); this.set("wizard", wizard); - if (!wizard || !wizard.permitted || wizard.completed) { + if ( + !wizard || + (!wizard.user && !wizard.allow_guests) || + !wizard.permitted || + wizard.completed + ) { this.replaceWith("customWizard"); } }, diff --git a/lib/custom_wizard/subscription.rb b/lib/custom_wizard/subscription.rb index 700e6087..20a444eb 100644 --- a/lib/custom_wizard/subscription.rb +++ b/lib/custom_wizard/subscription.rb @@ -24,6 +24,12 @@ class CustomWizard::Subscription standard: ['*'], business: ['*'], community: ['*'] + }, + allow_guests: { + none: [], + standard: ['*'], + business: ['*'], + community: ['*'] } }, step: { diff --git a/spec/requests/custom_wizard/steps_controller_spec.rb b/spec/requests/custom_wizard/steps_controller_spec.rb index 68d9f3f9..9f77c100 100644 --- a/spec/requests/custom_wizard/steps_controller_spec.rb +++ b/spec/requests/custom_wizard/steps_controller_spec.rb @@ -24,6 +24,7 @@ describe CustomWizard::StepsController do context "with allow_guests enabled" do before do + enable_subscription("standard") new_template = wizard_template.dup new_template["allow_guests"] = true new_template.delete("actions") diff --git a/test/javascripts/acceptance/wizard-test.js b/test/javascripts/acceptance/wizard-test.js index 063c80fb..d7078166 100644 --- a/test/javascripts/acceptance/wizard-test.js +++ b/test/javascripts/acceptance/wizard-test.js @@ -9,6 +9,7 @@ import { import { wizard, wizardCompleted, + wizardGuest, wizardNoUser, wizardNotPermitted, } from "../helpers/wizard"; @@ -106,3 +107,19 @@ acceptance("Wizard | Wizard", function (needs) { assert.strictEqual($("body.custom-wizard").length, 0); }); }); + +acceptance("Wizard | Guest access", function (needs) { + needs.pretender((server, helper) => { + server.get("/w/wizard.json", () => helper.response(wizardGuest)); + }); + + test("Does not require login", async function (assert) { + await visit("/w/wizard"); + assert.ok(!exists(".wizard-no-access.requires-login")); + }); + + test("Starts", async function (assert) { + await visit("/w/wizard"); + assert.ok(query(".wizard-column"), true); + }); +}); diff --git a/test/javascripts/helpers/wizard.js b/test/javascripts/helpers/wizard.js index 700cedc7..25ccccbb 100644 --- a/test/javascripts/helpers/wizard.js +++ b/test/javascripts/helpers/wizard.js @@ -6,6 +6,8 @@ import updateJson from "../fixtures/update"; import { cloneJSON } from "discourse-common/lib/object"; const wizardNoUser = cloneJSON(wizardJson); +const wizardGuest = cloneJSON(wizardJson); +wizardGuest.allow_guests = true; const wizard = cloneJSON(wizardJson); wizard.user = cloneJSON(userJson); @@ -40,6 +42,7 @@ export { wizardNoUser, wizardNotPermitted, wizardCompleted, + wizardGuest, stepNotPermitted, allFieldsWizard, wizard,