Ghost/ghost/admin/app/routes/members.js

65 lines
2.2 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';
2019-01-22 19:23:26 +03:00
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 MembersRoute extends AdminRoute {
@service store;
@service feature;
2019-01-22 19:23:26 +03:00
fromAnalytics = false;
queryParams = {
label: {refreshModel: true},
searchParam: {refreshModel: true, replace: true},
paidParam: {refreshModel: true},
orderParam: {refreshModel: true},
filterParam: {refreshModel: true}
};
2019-01-22 19:23:26 +03:00
beforeModel() {
super.beforeModel(...arguments);
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
// - TODO: redirect if members is disabled?
}
model(params) {
this.controllerFor('members').resetFilters(params);
return this.controllerFor('members').fetchMembersTask.perform(params);
}
// trigger a background load of members plus labels for filter dropdown
setupController(controller, model, transition) {
super.setupController(...arguments);
controller.fetchLabelsTask.perform();
if (transition.from?.name === 'posts.analytics') {
// Sadly transition.from.params is not reliable to use (not populated on transitions)
const oldParams = transition.router?.oldState?.params['posts.analytics'] ?? {};
// We need to store analytics in 'this' to have it accessible for the member route
this.fromAnalytics = Object.values(oldParams);
controller.fromAnalytics = this.fromAnalytics;
} else if (transition.from?.metadata?.fromAnalytics) {
// Handle returning from member route
const fromAnalytics = transition.from?.metadata.fromAnalytics ?? null;
controller.fromAnalytics = fromAnalytics;
this.fromAnalytics = fromAnalytics;
} else {
controller.fromAnalytics = null;
this.fromAnalytics = null;
}
}
resetController() {
super.resetController(...arguments);
// don't reset fromAnalytics here, we need to reuse it. We reset it in setup
//controller.fromAnalytics = null;
}
buildRouteInfoMetadata() {
return {
titleToken: 'Members',
mainClasses: ['gh-main-fullwidth'],
fromAnalytics: this.fromAnalytics
};
2019-01-22 19:23:26 +03:00
}
}