Ghost/ghost/admin/app/routes/settings/membership.js

62 lines
1.7 KiB
JavaScript
Raw Normal View History

Refactored away CurrentUserSettings mixin (#2200) no issue Mixins are deprecated in Ember so we want to remove their usage. The `CurrentUserSettings` mixin was used in Route files to provide `transitionAuthor()` (that also transitions contributors) and `transitionEditor()` methods so the the consuming route could use them to prevent access to authors/editors. In practice the only reason this was used was to prevent access to admin-only routes. - added an `AdminRoute` class that inherits from our `AuthenticatedRoute` class - when any route inherits from this class it will only allow access to admins and owners, any other user will be redirected to the home screen (dashboard or site depending on permissions) - updated all of our admin-only routes to use the new `AdminRoute` - allowed for removal of `CurrentUserSettings` mixin usage - allowed for `beforeModel()` hooks to be removed from consuming routes in many cases - some admin-only routes were extending/inheriting directly from Ember's `Route` based on the assumption that the router hierarchy would have a parent route perform the redirect. Those have also been switched to `AdminRoute` for consistency and to prevent accidentally making them available if the router hierarchy changes - `/#/settings` does not use the `AdminRoute` so that it can redirect to the current user's setting page for non-admin users - removed `CurrentUserSettings` mixin file - cleaned up unnecessary computed property and function used for redirect-when-disabled in the Zapier route
2022-01-17 13:05:27 +03:00
import AdminRoute from 'ghost-admin/routes/admin';
import VerifyEmail from '../../components/modals/settings/verify-email';
import {inject as service} from '@ember/service';
Refactored away CurrentUserSettings mixin (#2200) no issue Mixins are deprecated in Ember so we want to remove their usage. The `CurrentUserSettings` mixin was used in Route files to provide `transitionAuthor()` (that also transitions contributors) and `transitionEditor()` methods so the the consuming route could use them to prevent access to authors/editors. In practice the only reason this was used was to prevent access to admin-only routes. - added an `AdminRoute` class that inherits from our `AuthenticatedRoute` class - when any route inherits from this class it will only allow access to admins and owners, any other user will be redirected to the home screen (dashboard or site depending on permissions) - updated all of our admin-only routes to use the new `AdminRoute` - allowed for removal of `CurrentUserSettings` mixin usage - allowed for `beforeModel()` hooks to be removed from consuming routes in many cases - some admin-only routes were extending/inheriting directly from Ember's `Route` based on the assumption that the router hierarchy would have a parent route perform the redirect. Those have also been switched to `AdminRoute` for consistency and to prevent accidentally making them available if the router hierarchy changes - `/#/settings` does not use the `AdminRoute` so that it can redirect to the current user's setting page for non-admin users - removed `CurrentUserSettings` mixin file - cleaned up unnecessary computed property and function used for redirect-when-disabled in the Zapier route
2022-01-17 13:05:27 +03:00
export default class MembershipSettingsRoute extends AdminRoute {
@service notifications;
@service settings;
@service modals;
queryParams = {
verifyEmail: {
replace: true
}
};
beforeModel(transition) {
super.beforeModel(...arguments);
// @todo: remove in the future, but keep it for now because we might still have some old verification urls in emails
if (transition.to.queryParams?.supportAddressUpdate === 'success') {
this.notifications.showAlert(
`Support email address has been updated`,
{type: 'success', key: 'members.settings.support-address.updated'}
);
}
}
model() {
this.settings.reload();
}
afterModel(model, transition) {
if (transition.to.queryParams.verifyEmail) {
this.modals.open(VerifyEmail, {
token: transition.to.queryParams.verifyEmail
});
// clear query param so it doesn't linger and cause problems re-entering route
transition.abort();
return this.transitionTo('settings.membership', {queryParams: {verifyEmail: null}});
}
}
actions = {
willTransition(transition) {
return this.controller.leaveRoute(transition);
}
};
buildRouteInfoMetadata() {
return {
titleToken: 'Settings - Membership'
};
}
resetController(controller, isExiting) {
if (isExiting) {
controller.reset();
}
}
}