From c6dc80f02ca1fb61cde842dcad09b1b667c3004d Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 17 Mar 2023 09:05:53 +0100 Subject: [PATCH] FIX: template guest validation not working with validation conditions --- lib/custom_wizard/validators/template.rb | 2 +- plugin.rb | 2 +- .../custom_wizard/template_validator_spec.rb | 8 ++++++++ .../condition/validation_condition.json | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/condition/validation_condition.json diff --git a/lib/custom_wizard/validators/template.rb b/lib/custom_wizard/validators/template.rb index 60652322..f2a4feb0 100644 --- a/lib/custom_wizard/validators/template.rb +++ b/lib/custom_wizard/validators/template.rb @@ -84,7 +84,7 @@ class CustomWizard::TemplateValidator def validate_guests(object, type) guests_permitted = @data[:permitted] && @data[:permitted].any? do |m| - m["output"].include?(CustomWizard::Wizard::GUEST_GROUP_ID) + m["output"]&.include?(CustomWizard::Wizard::GUEST_GROUP_ID) end return unless guests_permitted diff --git a/plugin.rb b/plugin.rb index 0bb34914..5b5c7980 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.2.11 +# version: 2.2.12 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech diff --git a/spec/components/custom_wizard/template_validator_spec.rb b/spec/components/custom_wizard/template_validator_spec.rb index b9b257e3..fe61be91 100644 --- a/spec/components/custom_wizard/template_validator_spec.rb +++ b/spec/components/custom_wizard/template_validator_spec.rb @@ -9,6 +9,7 @@ describe CustomWizard::TemplateValidator do let(:composer_preview) { get_wizard_fixture("field/composer_preview") } let(:guests_permitted) { get_wizard_fixture("wizard/guests_permitted") } let(:upload_field) { get_wizard_fixture("field/upload") } + let(:validation_condition) { get_wizard_fixture("condition/validation_condition") } let(:valid_liquid_template) { <<-LIQUID.strip @@ -182,6 +183,13 @@ describe CustomWizard::TemplateValidator do CustomWizard::TemplateValidator.new(template).perform ).to eq(true) end + + it "validates settings with validation conditions" do + template[:permitted] = validation_condition["condition"] + expect( + CustomWizard::TemplateValidator.new(template).perform + ).to eq(true) + end end context "steps" do diff --git a/spec/fixtures/condition/validation_condition.json b/spec/fixtures/condition/validation_condition.json new file mode 100644 index 00000000..695c25c9 --- /dev/null +++ b/spec/fixtures/condition/validation_condition.json @@ -0,0 +1,17 @@ +{ + "condition": [ + { + "type": "validation", + "pairs": [ + { + "index": 0, + "key": "trust_level", + "key_type": "user_field", + "value": "2", + "value_type": "text", + "connector": "greater_or_equal" + } + ] + } + ] +} \ No newline at end of file