From 8734cda00bd6c02bf085be5a00f236500f8d1d21 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 22 Mar 2023 11:20:30 +0100 Subject: [PATCH 1/2] Fix start step when step is added to previously used wizard --- lib/custom_wizard/submission.rb | 4 ++++ lib/custom_wizard/wizard.rb | 6 +++++ spec/components/custom_wizard/wizard_spec.rb | 23 ++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/lib/custom_wizard/submission.rb b/lib/custom_wizard/submission.rb index 38cad982..ae616b0b 100644 --- a/lib/custom_wizard/submission.rb +++ b/lib/custom_wizard/submission.rb @@ -84,6 +84,10 @@ class CustomWizard::Submission data end + def submitted? + !!submitted_at + end + def self.get(wizard) data = PluginStore.get("#{wizard.id}_#{KEY}", wizard.actor_id).last new(wizard, data) diff --git a/lib/custom_wizard/wizard.rb b/lib/custom_wizard/wizard.rb index 4ed4037d..3d62cf25 100644 --- a/lib/custom_wizard/wizard.rb +++ b/lib/custom_wizard/wizard.rb @@ -176,6 +176,7 @@ class CustomWizard::Wizard def unfinished? return nil unless actor_id + return false if last_submission&.submitted? most_recent = CustomWizard::UserHistory.where( actor_id: actor_id, @@ -194,6 +195,7 @@ class CustomWizard::Wizard def completed? return nil unless actor_id + return true if last_submission&.submitted? history = CustomWizard::UserHistory.where( actor_id: actor_id, @@ -282,6 +284,10 @@ class CustomWizard::Wizard @submissions ||= CustomWizard::Submission.list(self).submissions end + def last_submission + @last_submission ||= submissions&.last + end + def current_submission @current_submission ||= begin if submissions.present? diff --git a/spec/components/custom_wizard/wizard_spec.rb b/spec/components/custom_wizard/wizard_spec.rb index 591eee8c..17151077 100644 --- a/spec/components/custom_wizard/wizard_spec.rb +++ b/spec/components/custom_wizard/wizard_spec.rb @@ -7,6 +7,7 @@ describe CustomWizard::Wizard do let(:template_json) { get_wizard_fixture("wizard") } let(:permitted_json) { get_wizard_fixture("wizard/permitted") } let(:guests_permitted_json) { get_wizard_fixture("wizard/guests_permitted") } + let(:step_json) { get_wizard_fixture("step/step") } before do Group.refresh_automatic_group!(:trust_level_3) @@ -75,6 +76,28 @@ describe CustomWizard::Wizard do expect(@wizard.start).to eq('step_2') end + it "determines the user's current step if steps are added" do + append_steps + progress_step('step_1') + progress_step('step_2') + progress_step("step_3") + + fourth_step = step_json.dup + fourth_step['id'] = "step_4" + template = template_json.dup + template['steps'] << fourth_step + + CustomWizard::Template.save(template, skip_jobs: true) + + wizard = CustomWizard::Wizard.new(template, user) + template['steps'].each do |step_template| + wizard.append_step(step_template['id']) + end + + expect(wizard.steps.size).to eq(4) + expect(wizard.start).to eq(nil) + end + it "creates a step updater" do expect( @wizard.create_updater('step_1', step_1_field_1: "Text input") From e7e9c0e8f845a69672878e84a7a9841e054da2da Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 22 Mar 2023 11:22:01 +0100 Subject: [PATCH 2/2] Bump version --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 788ba1da..55c22304 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.15 +# version: 2.2.16 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech