diff --git a/assets/javascripts/discourse/models/custom-wizard-admin.js.es6 b/assets/javascripts/discourse/models/custom-wizard-admin.js.es6 index 03afd32e..746ca00c 100644 --- a/assets/javascripts/discourse/models/custom-wizard-admin.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard-admin.js.es6 @@ -10,9 +10,9 @@ import discourseComputed from "discourse-common/utils/decorators"; const GUEST_GROUP_ID = -1; const CustomWizardAdmin = EmberObject.extend({ - @discourseComputed("permitted.@each") + @discourseComputed("permitted.@each.output") allowGuests(permitted) { - return permitted.filter((p) => p.output === GUEST_GROUP_ID).length; + return permitted.filter((p) => p.output.includes(GUEST_GROUP_ID)).length; }, save(opts) { diff --git a/lib/custom_wizard/validators/template.rb b/lib/custom_wizard/validators/template.rb index 38b2595c..154f525e 100644 --- a/lib/custom_wizard/validators/template.rb +++ b/lib/custom_wizard/validators/template.rb @@ -83,7 +83,7 @@ class CustomWizard::TemplateValidator def validate_action(action) guests_permitted = @data[:permitted] && @data[:permitted].any? do |m| - m[:output] === CustomWizard::Wizard::GUEST_GROUP_ID + m["output"].include?(CustomWizard::Wizard::GUEST_GROUP_ID) end if guests_permitted && CustomWizard::Action::REQUIRES_USER.include?(action[:type]) diff --git a/spec/components/custom_wizard/template_validator_spec.rb b/spec/components/custom_wizard/template_validator_spec.rb index b149706f..54ec9cfa 100644 --- a/spec/components/custom_wizard/template_validator_spec.rb +++ b/spec/components/custom_wizard/template_validator_spec.rb @@ -7,6 +7,7 @@ describe CustomWizard::TemplateValidator do let(:user_condition) { get_wizard_fixture("condition/user_condition") } let(:permitted_json) { get_wizard_fixture("wizard/permitted") } let(:composer_preview) { get_wizard_fixture("field/composer_preview") } + let(:guests_permitted) { get_wizard_fixture("wizard/guests_permitted") } let(:valid_liquid_template) { <<-LIQUID.strip @@ -146,6 +147,15 @@ describe CustomWizard::TemplateValidator do ).to eq(true) end + it "validates restrictions on wizards that permit guests" do + template[:permitted] = guests_permitted['permitted'] + validator = CustomWizard::TemplateValidator.new(template) + expect(validator.perform).to eq(false) + expect(validator.errors.first.type).to eq( + I18n.t("wizard.validation.not_permitted_for_guests", object_id: "action_1") + ) + end + it "validates step attributes" do template[:steps][0][:condition] = user_condition['condition'] expect(