0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-09-19 23:31:11 +02:00

Merge pull request #253 from paviliondev/dont_rely_on_application_route_override

IMPROVE: Move pending wizard check to page change event
Dieser Commit ist enthalten in:
Angus McLeod 2023-07-14 08:19:45 +02:00 committet von GitHub
Commit 270d7926cc
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 42 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -1,12 +1,16 @@
import DiscourseURL from "discourse/lib/url";
import { withPluginApi } from "discourse/lib/plugin-api";
import { dasherize } from "@ember/string";
export default { export default {
name: "custom-wizard-redirect", name: "custom-wizard-redirect",
after: "message-bus", after: "message-bus",
initialize: function (container) { initialize(container) {
const messageBus = container.lookup("service:message-bus"); const messageBus = container.lookup("service:message-bus");
const siteSettings = container.lookup("service:site-settings"); const siteSettings = container.lookup("service:site-settings");
if (!siteSettings.custom_wizard_enabled || !messageBus) { if (!siteSettings.custom_wizard_enabled) {
return; return;
} }
@ -15,30 +19,26 @@ export default {
window.location.href = wizardUrl; window.location.href = wizardUrl;
}); });
const ApplicationRoute = requirejs("discourse/routes/application").default; withPluginApi("0.8.36", (api) => {
api.onAppEvent("page:changed", (data) => {
const currentUser = api.getCurrentUser();
ApplicationRoute.reopen({ if (currentUser) {
actions: { const redirectToWizard = currentUser.redirect_to_wizard;
willTransition(transition) { const excludedPaths = siteSettings.wizard_redirect_exclude_paths
const redirectToWizard = this.get("currentUser.redirect_to_wizard");
const excludedPaths = this.siteSettings.wizard_redirect_exclude_paths
.split("|") .split("|")
.concat(["loading"]); .concat(["loading"]);
if ( if (
redirectToWizard && redirectToWizard &&
(!transition.intent.name || data.currentRouteName !== "customWizardStep" &&
!excludedPaths.find((p) => { !excludedPaths.find((p) => {
return transition.intent.name.indexOf(p) > -1; return data.currentRouteName.indexOf(p) > -1;
})) })
) { ) {
transition.abort(); DiscourseURL.routeTo(`/w/${dasherize(redirectToWizard)}`);
window.location = "/w/" + redirectToWizard.dasherize();
} }
}
return this._super(transition); });
},
},
}); });
}, },
}; };

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.4.11 # version: 2.4.12
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Juan Marcos Gutierrez Ramos # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Juan Marcos Gutierrez Ramos
# 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

@ -13,6 +13,8 @@ import {
wizardNoUser, wizardNoUser,
wizardNotPermitted, wizardNotPermitted,
} from "../helpers/wizard"; } from "../helpers/wizard";
import DiscourseURL from "discourse/lib/url";
import sinon from "sinon";
acceptance("Wizard | Not logged in", function (needs) { acceptance("Wizard | Not logged in", function (needs) {
needs.pretender((server, helper) => { needs.pretender((server, helper) => {
@ -54,6 +56,26 @@ acceptance("Wizard | Completed", function (needs) {
}); });
}); });
acceptance("Wizard | Redirect", function (needs) {
needs.user({
redirect_to_wizard: "wizard",
});
needs.pretender((server, helper) => {
server.get("/w/wizard.json", () => {
return helper.response(wizard);
});
});
test("Redirect to pending Wizard", async function (assert) {
sinon.stub(DiscourseURL, "routeTo");
await visit("/latest");
assert.ok(
DiscourseURL.routeTo.calledWith("/w/wizard"),
"pending wizard routing works"
);
});
});
acceptance("Wizard | Wizard", function (needs) { acceptance("Wizard | Wizard", function (needs) {
needs.user(); needs.user();
needs.pretender((server, helper) => { needs.pretender((server, helper) => {