Ghost/ghost/admin/app/routes/pro.js
Aileen Nowak b63a396423 Added handling for forceUpgrade state (#2116)
no issue

- Lapsed trials and subscriptions will set the site's hosting config to `forceUpgrade` in which case a Ghost(Pro) site does not have a valid subscription or trial
- In this state we need to redirect all routes for all staff users to `/#/pro` to ensure the subscription can be put back into an active state
- This commit tackles
    - Route update on startup on the application route level
    - Catching and redirecting all transition (utils routes)
    - Fetching the owner user to pass this information to the Ghost(Pro) app for better communication to non-owner staff users
    - Allowing non-owner users in the force upgrade state to transition to the `/#/pro` route
2021-10-22 12:29:55 +02:00

59 lines
1.5 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(),
config: service(),
queryParams: {
action: {refreshModel: true}
},
beforeModel(transition) {
this._super(...arguments);
// allow non-owner users to access the BMA when we're in a force upgrade state
if (!this.session.user.isOwnerOnly && !this.config.get('hostSettings.forceUpgrade')) {
return this.transitionTo('home');
}
this.billing.set('previousTransition', transition);
},
model(params) {
if (params.action) {
this.billing.set('action', params.action);
}
this.billing.toggleProWindow(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.toggleProWindow(isBillingTransition);
}
},
buildRouteInfoMetadata() {
return {
titleToken: 'Ghost(Pro)'
};
}
});