From 833281861692ec265ac94731716c186d213083c8 Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 6 Sep 2023 13:29:21 +0100 Subject: [PATCH 1/5] FEATURE: implement way to temporarily ignore redirect --- .../discourse/initializers/custom-wizard-redirect.js.es6 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 index 70676bb0..16e4205a 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 @@ -22,6 +22,7 @@ export default { withPluginApi("0.8.36", (api) => { api.onAppEvent("page:changed", (data) => { const currentUser = api.getCurrentUser(); + const searchParams = new URLSearchParams(window.location.search); if (currentUser) { const redirectToWizard = currentUser.redirect_to_wizard; @@ -30,6 +31,7 @@ export default { .concat(["loading"]); if ( redirectToWizard && + !searchParams.has('ignore_redirect') && data.currentRouteName !== "customWizardStep" && !excludedPaths.find((p) => { return data.currentRouteName.indexOf(p) > -1; From 037132fb1a990b8b519f624b09a02d2d6ad7dabb Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 6 Sep 2023 16:26:30 +0100 Subject: [PATCH 2/5] prettier --- .../discourse/initializers/custom-wizard-redirect.js.es6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 index 16e4205a..02f11a6d 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 @@ -31,7 +31,7 @@ export default { .concat(["loading"]); if ( redirectToWizard && - !searchParams.has('ignore_redirect') && + !searchParams.has("ignore_redirect") && data.currentRouteName !== "customWizardStep" && !excludedPaths.find((p) => { return data.currentRouteName.indexOf(p) > -1; From 8649ab22864682910e2e33a949c486537c2eac6a Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 6 Sep 2023 16:27:40 +0100 Subject: [PATCH 3/5] bump patch --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 756154bb..ea56d174 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.4.18 +# version: 2.4.19 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Juan Marcos Gutierrez Ramos # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From 050a38a9d38250b43125490675031240d7445709 Mon Sep 17 00:00:00 2001 From: merefield Date: Fri, 8 Sep 2023 07:13:52 +0100 Subject: [PATCH 4/5] make code testable, add test --- .../discourse/initializers/custom-wizard-redirect.js.es6 | 2 +- test/javascripts/acceptance/wizard-test.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 index 02f11a6d..391340b7 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 @@ -31,7 +31,7 @@ export default { .concat(["loading"]); if ( redirectToWizard && - !searchParams.has("ignore_redirect") && + !data.url.includes("ignore_redirect") && data.currentRouteName !== "customWizardStep" && !excludedPaths.find((p) => { return data.currentRouteName.indexOf(p) > -1; diff --git a/test/javascripts/acceptance/wizard-test.js b/test/javascripts/acceptance/wizard-test.js index dd441649..0527cf0f 100644 --- a/test/javascripts/acceptance/wizard-test.js +++ b/test/javascripts/acceptance/wizard-test.js @@ -74,6 +74,15 @@ acceptance("Wizard | Redirect", function (needs) { "pending wizard routing works" ); }); + + test("Don't redirect to pending Wizard when ingore redirect param is supplied", async function (assert) { + sinon.stub(DiscourseURL, "routeTo"); + await visit("/latest?ignore_redirect=1"); + assert.notOk( + DiscourseURL.routeTo.calledWith("/w/wizard"), + "pending wizard routing blocked" + ); + }); }); acceptance("Wizard | Wizard", function (needs) { From ebc0f706e31c99d437dfb741690a643d3b5a472a Mon Sep 17 00:00:00 2001 From: merefield Date: Fri, 8 Sep 2023 07:18:31 +0100 Subject: [PATCH 5/5] remove redundant assignment --- .../discourse/initializers/custom-wizard-redirect.js.es6 | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 index 391340b7..c02f0f3d 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 @@ -22,7 +22,6 @@ export default { withPluginApi("0.8.36", (api) => { api.onAppEvent("page:changed", (data) => { const currentUser = api.getCurrentUser(); - const searchParams = new URLSearchParams(window.location.search); if (currentUser) { const redirectToWizard = currentUser.redirect_to_wizard;