diff --git a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 index 7f6effae..997356e7 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 @@ -1,3 +1,5 @@ +import ApplicationRoute from 'discourse/routes/application'; + export default { name: "custom-wizard-redirect", after: "message-bus", @@ -11,5 +13,21 @@ export default { const wizardUrl = window.location.origin + '/w/' + wizardId; window.location.href = wizardUrl; }); + + ApplicationRoute.reopen({ + actions: { + willTransition(transition) { + const redirectToWizard = this.get('currentUser.redirect_to_wizard'); + const excludedPaths = Discourse.SiteSettings.wizard_redirect_exclude_paths.split('|').concat(['loading']); + + if (redirectToWizard && excludedPaths.indexOf(this.routeName) === -1) { + transition.abort(); + window.location = '/w/' + redirectToWizard.dasherize(); + } + + return this._super(transition); + } + } + }) } }; diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index a45fc9dc..75372a30 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -5,3 +5,6 @@ en: too_short: "%{label} must be at least %{min} characters" none: "We couldn't find a wizard at that address." no_skip: "Wizard can't be skipped" + + site_settings: + wizard_redirect_exclude_paths: "Routes excluded from wizard redirects." diff --git a/config/settings.yml b/config/settings.yml new file mode 100644 index 00000000..eec23afb --- /dev/null +++ b/config/settings.yml @@ -0,0 +1,7 @@ +plugins: + wizard_redirect_exclude_paths: + client: true + type: list + default: 'admin' + choices: + - admin