Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 09:20:29 +01: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:
Commit
270d7926cc
3 geänderte Dateien mit 42 neuen und 20 gelöschten Zeilen
|
@ -1,12 +1,16 @@
|
|||
import DiscourseURL from "discourse/lib/url";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import { dasherize } from "@ember/string";
|
||||
|
||||
export default {
|
||||
name: "custom-wizard-redirect",
|
||||
after: "message-bus",
|
||||
|
||||
initialize: function (container) {
|
||||
initialize(container) {
|
||||
const messageBus = container.lookup("service:message-bus");
|
||||
const siteSettings = container.lookup("service:site-settings");
|
||||
|
||||
if (!siteSettings.custom_wizard_enabled || !messageBus) {
|
||||
if (!siteSettings.custom_wizard_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -15,30 +19,26 @@ export default {
|
|||
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({
|
||||
actions: {
|
||||
willTransition(transition) {
|
||||
const redirectToWizard = this.get("currentUser.redirect_to_wizard");
|
||||
const excludedPaths = this.siteSettings.wizard_redirect_exclude_paths
|
||||
if (currentUser) {
|
||||
const redirectToWizard = currentUser.redirect_to_wizard;
|
||||
const excludedPaths = siteSettings.wizard_redirect_exclude_paths
|
||||
.split("|")
|
||||
.concat(["loading"]);
|
||||
|
||||
if (
|
||||
redirectToWizard &&
|
||||
(!transition.intent.name ||
|
||||
data.currentRouteName !== "customWizardStep" &&
|
||||
!excludedPaths.find((p) => {
|
||||
return transition.intent.name.indexOf(p) > -1;
|
||||
}))
|
||||
return data.currentRouteName.indexOf(p) > -1;
|
||||
})
|
||||
) {
|
||||
transition.abort();
|
||||
window.location = "/w/" + redirectToWizard.dasherize();
|
||||
DiscourseURL.routeTo(`/w/${dasherize(redirectToWizard)}`);
|
||||
}
|
||||
|
||||
return this._super(transition);
|
||||
},
|
||||
},
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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.11
|
||||
# version: 2.4.12
|
||||
# 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
|
||||
|
|
|
@ -13,6 +13,8 @@ import {
|
|||
wizardNoUser,
|
||||
wizardNotPermitted,
|
||||
} from "../helpers/wizard";
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
import sinon from "sinon";
|
||||
|
||||
acceptance("Wizard | Not logged in", function (needs) {
|
||||
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) {
|
||||
needs.user();
|
||||
needs.pretender((server, helper) => {
|
||||
|
|
Laden …
In neuem Issue referenzieren