0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-29 12:20:27 +01:00

Merge pull request #238 from paviliondev/incorrect_step_when_steps_are_added

Fix start step when step is added to previously used wizard
Dieser Commit ist enthalten in:
Marcos 2023-03-22 11:51:36 -05:00 committet von GitHub
Commit 82aae6d34a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
4 geänderte Dateien mit 34 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -84,6 +84,10 @@ class CustomWizard::Submission
data data
end end
def submitted?
!!submitted_at
end
def self.get(wizard) def self.get(wizard)
data = PluginStore.get("#{wizard.id}_#{KEY}", wizard.actor_id).last data = PluginStore.get("#{wizard.id}_#{KEY}", wizard.actor_id).last
new(wizard, data) new(wizard, data)

Datei anzeigen

@ -176,6 +176,7 @@ class CustomWizard::Wizard
def unfinished? def unfinished?
return nil unless actor_id return nil unless actor_id
return false if last_submission&.submitted?
most_recent = CustomWizard::UserHistory.where( most_recent = CustomWizard::UserHistory.where(
actor_id: actor_id, actor_id: actor_id,
@ -194,6 +195,7 @@ class CustomWizard::Wizard
def completed? def completed?
return nil unless actor_id return nil unless actor_id
return true if last_submission&.submitted?
history = CustomWizard::UserHistory.where( history = CustomWizard::UserHistory.where(
actor_id: actor_id, actor_id: actor_id,
@ -282,6 +284,10 @@ class CustomWizard::Wizard
@submissions ||= CustomWizard::Submission.list(self).submissions @submissions ||= CustomWizard::Submission.list(self).submissions
end end
def last_submission
@last_submission ||= submissions&.last
end
def current_submission def current_submission
@current_submission ||= begin @current_submission ||= begin
if submissions.present? if submissions.present?

Datei anzeigen

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
# name: discourse-custom-wizard # name: discourse-custom-wizard
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. # 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 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever
# url: https://github.com/paviliondev/discourse-custom-wizard # url: https://github.com/paviliondev/discourse-custom-wizard
# contact_emails: development@pavilion.tech # contact_emails: development@pavilion.tech

Datei anzeigen

@ -7,6 +7,7 @@ describe CustomWizard::Wizard do
let(:template_json) { get_wizard_fixture("wizard") } let(:template_json) { get_wizard_fixture("wizard") }
let(:permitted_json) { get_wizard_fixture("wizard/permitted") } let(:permitted_json) { get_wizard_fixture("wizard/permitted") }
let(:guests_permitted_json) { get_wizard_fixture("wizard/guests_permitted") } let(:guests_permitted_json) { get_wizard_fixture("wizard/guests_permitted") }
let(:step_json) { get_wizard_fixture("step/step") }
before do before do
Group.refresh_automatic_group!(:trust_level_3) Group.refresh_automatic_group!(:trust_level_3)
@ -75,6 +76,28 @@ describe CustomWizard::Wizard do
expect(@wizard.start).to eq('step_2') expect(@wizard.start).to eq('step_2')
end 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 it "creates a step updater" do
expect( expect(
@wizard.create_updater('step_1', step_1_field_1: "Text input") @wizard.create_updater('step_1', step_1_field_1: "Text input")