Ghost/ghost/admin/app/utils/route.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

26 lines
782 B
JavaScript

import Route from '@ember/routing/route';
import {inject as service} from '@ember/service';
Route.reopen({
config: service(),
billing: service(),
router: service(),
actions: {
willTransition(transition) {
if (this.get('upgradeStatus.isRequired')) {
transition.abort();
this.upgradeStatus.requireUpgrade();
return false;
} else if (this.config.get('hostSettings.forceUpgrade')) {
transition.abort();
// Catch and redirect every route in a force upgrade state
this.billing.openBillingWindow(this.router.currentURL, '/pro');
return false;
} else {
return true;
}
}
}
});