mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
2d4bbad094
refs https://github.com/TryGhost/Team/issues/1583 - When adding a newsletter, check the limits (both via button and route) - When unarchiving a newsletter, check the limits - Bumped `@tryghost/limit-service` package, required to make limit checking work for newsletter - Added the `getNewslettersCount` query to the `limit` service
67 lines
1.8 KiB
JavaScript
67 lines
1.8 KiB
JavaScript
import AdminRoute from 'ghost-admin/routes/admin';
|
|
import NewNewsletterModal from '../../../components/modals/newsletters/new';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default class NewNewsletterRoute extends AdminRoute {
|
|
@service modals;
|
|
@service router;
|
|
@service settings;
|
|
@service store;
|
|
@service limit;
|
|
|
|
newsletterModal = null;
|
|
|
|
/**
|
|
* Before we allow the creation of a new newsletter, we should check the limits and return to the newsletters page if required.
|
|
*/
|
|
async beforeModel() {
|
|
try {
|
|
await this.limit.limiter.errorIfWouldGoOverLimit('newsletters');
|
|
} catch (error) {
|
|
if (error.errorType === 'HostLimitError') {
|
|
// Not allowed: we reached the limit here
|
|
this.modals.open('modals/limits/multiple-newsletters', {
|
|
message: error.message
|
|
});
|
|
return this.replaceWith('settings.newsletters');
|
|
}
|
|
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
model() {
|
|
return this.store.createRecord('newsletter');
|
|
}
|
|
|
|
setupController(controller, model) {
|
|
this.newsletterModal?.close();
|
|
|
|
this.newsletterModal = this.modals.open(NewNewsletterModal, {
|
|
newsletter: model,
|
|
afterSave: this.afterSave
|
|
}, {
|
|
beforeClose: this.beforeModalClose
|
|
});
|
|
}
|
|
|
|
@action
|
|
afterSave() {
|
|
this.router.transitionTo('settings.newsletters');
|
|
}
|
|
|
|
deactivate() {
|
|
this.isLeaving = true;
|
|
this.newsletterModal?.close();
|
|
this.isLeaving = false;
|
|
}
|
|
|
|
@action
|
|
async beforeModalClose() {
|
|
if (!this.isLeaving) {
|
|
this.router.transitionTo('settings.newsletters');
|
|
}
|
|
}
|
|
}
|