Ghost/ghost/admin/app/routes/pro.js
Thibaut Patel dc9c812d9c Renamed isAdmin/isOwner/isAdminOrOwner to reduce confusion
issue https://github.com/TryGhost/Team/issues/857

- The goal is to avoid testing for the owner role only is cases where we should be testing for the owner or admin role
- `isOwner` => `isOwnerOnly`
- `isAdmin` => `isAdminOnly`
- `isOwnerOrAdmin` => `isAdmin` (concerns now both Owner and Admins)
2021-07-12 14:55:56 +02:00

57 lines
1.4 KiB
JavaScript

import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import {inject as service} from '@ember/service';
// TODO: rename billing route and service to /pro
export default AuthenticatedRoute.extend({
billing: service(),
session: service(),
queryParams: {
action: {refreshModel: true}
},
beforeModel(transition) {
this._super(...arguments);
if (!this.session.user.isOwnerOnly) {
return this.transitionTo('home');
}
this.billing.set('previousTransition', transition);
},
model(params) {
if (params.action) {
this.billing.set('action', params.action);
}
this.billing.setBillingWindowOpen(true);
},
actions: {
willTransition(transition) {
let isBillingTransition = false;
if (transition) {
let destinationUrl = (typeof transition.to === 'string')
? transition.to
: (transition.intent
? transition.intent.url
: '');
if (destinationUrl?.includes('/pro')) {
isBillingTransition = true;
}
}
this.billing.setBillingWindowOpen(isBillingTransition);
}
},
buildRouteInfoMetadata() {
return {
titleToken: 'Ghost(Pro)'
};
}
});