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

Merge pull request #138 from paviliondev/maybe_later_bug

FIX: clear submission if skipped by user
Dieser Commit ist enthalten in:
Angus McLeod 2021-08-23 14:12:48 +08:00 committet von GitHub
Commit e865516f48
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 59 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -68,7 +68,8 @@ class CustomWizard::WizardController < ::ApplicationController
result.merge!(redirect_to: submission.redirect_to) result.merge!(redirect_to: submission.redirect_to)
end end
wizard.final_cleanup! submission.remove if submission.present?
wizard.reset
end end
render json: result render json: result

Datei anzeigen

@ -97,6 +97,17 @@ class CustomWizard::Submission
new(wizard, data, user_id) new(wizard, data, user_id)
end end
def remove
if present?
user_id = @user.id
wizard_id = @wizard.id
submission_id = @id
data = PluginStore.get("#{wizard_id}_#{KEY}", user_id)
data.delete_if { |sub| sub["id"] == submission_id }
PluginStore.set("#{wizard_id}_#{KEY}", user_id, data)
end
end
def self.cleanup_incomplete_submissions(wizard) def self.cleanup_incomplete_submissions(wizard)
user_id = wizard.user.id user_id = wizard.user.id
all_submissions = list(wizard, user_id: user_id) all_submissions = list(wizard, user_id: user_id)

Datei anzeigen

@ -50,30 +50,55 @@ describe CustomWizard::WizardController do
expect(response.parsed_body["error"]).to eq("We couldn't find a wizard at that address.") expect(response.parsed_body["error"]).to eq("We couldn't find a wizard at that address.")
end end
it 'skips a wizard if user is allowed to skip' do context 'when user skips the wizard' do
put '/w/super-mega-fun-wizard/skip.json'
expect(response.status).to eq(200)
end
it 'lets user skip if user cant access wizard' do it 'skips a wizard if user is allowed to skip' do
@template["permitted"] = permitted_json["permitted"] put '/w/super-mega-fun-wizard/skip.json'
CustomWizard::Template.save(@template, skip_jobs: true) expect(response.status).to eq(200)
end
put '/w/super-mega-fun-wizard/skip.json' it 'lets user skip if user cant access wizard' do
expect(response.status).to eq(200) @template["permitted"] = permitted_json["permitted"]
end CustomWizard::Template.save(@template, skip_jobs: true)
it 'returns a no skip message if user is not allowed to skip' do put '/w/super-mega-fun-wizard/skip.json'
@template['required'] = 'true' expect(response.status).to eq(200)
CustomWizard::Template.save(@template) end
put '/w/super-mega-fun-wizard/skip.json'
expect(response.parsed_body['error']).to eq("Wizard can't be skipped")
end
it 'skip response contains a redirect_to if in users submissions' do it 'returns a no skip message if user is not allowed to skip' do
@wizard = CustomWizard::Wizard.create(@template["id"], user) @template['required'] = 'true'
CustomWizard::Submission.new(@wizard, redirect_to: "/t/2").save CustomWizard::Template.save(@template)
put '/w/super-mega-fun-wizard/skip.json' put '/w/super-mega-fun-wizard/skip.json'
expect(response.parsed_body['redirect_to']).to eq('/t/2') expect(response.parsed_body['error']).to eq("Wizard can't be skipped")
end
it 'skip response contains a redirect_to if in users submissions' do
@wizard = CustomWizard::Wizard.create(@template["id"], user)
CustomWizard::Submission.new(@wizard, redirect_to: "/t/2").save
put '/w/super-mega-fun-wizard/skip.json'
expect(response.parsed_body['redirect_to']).to eq('/t/2')
end
it "deletes the submission if user has filled up some data" do
@wizard = CustomWizard::Wizard.create(@template["id"], user)
CustomWizard::Submission.new(@wizard, step_1_field_1: "Hello World").save
current_submission = @wizard.current_submission
put '/w/super-mega-fun-wizard/skip.json'
list = CustomWizard::Submission.list(@wizard)
expect(list.any? { |submission| submission.id == current_submission.id }).to eq(false)
end
it "starts from the first step if user visits after skipping the wizard" do
put '/w/super-mega-fun-wizard/steps/step_1.json', params: {
fields: {
step_1_field_1: "Text input"
}
}
put '/w/super-mega-fun-wizard/skip.json'
get '/w/super-mega-fun-wizard.json'
expect(response.parsed_body["start"]).to eq('step_1')
end
end end
end end