From d686ece85bcd4fb478fc49eb1ab2a47a9ac6ed2f Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 2 Jul 2018 10:30:38 +1000 Subject: [PATCH] Redirect to root from '/donate' if the plugin is disabled --- assets/javascripts/discourse/routes/donate.js.es6 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/routes/donate.js.es6 b/assets/javascripts/discourse/routes/donate.js.es6 index 04d7994..4a52b8c 100644 --- a/assets/javascripts/discourse/routes/donate.js.es6 +++ b/assets/javascripts/discourse/routes/donate.js.es6 @@ -1,8 +1,16 @@ import DiscourseRoute from "discourse/routes/discourse"; +import DiscourseURL from 'discourse/lib/url'; import { popupAjaxError } from 'discourse/lib/ajax-error'; import { ajax } from 'discourse/lib/ajax'; export default DiscourseRoute.extend({ + redirect() { + if (!Discourse.SiteSettings.discourse_donations_enabled) { + DiscourseURL.routeTo('/'); + return; + } + }, + setupController(controller) { let charges = []; let subscriptions = []; @@ -10,7 +18,7 @@ export default DiscourseRoute.extend({ controller.set('loadingDonations', true); - ajax('/donate/charges').then((result) => { + ajax('/donate/charges').then((result) => { if (result) { charges = result.charges; subscriptions = result.subscriptions; @@ -24,6 +32,6 @@ export default DiscourseRoute.extend({ }); }).catch(popupAjaxError).finally(() => { controller.set('loadingDonations', false); - }) + }); } });