0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-01 02:41:39 -05:00

Implemented newsletter limits

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
This commit is contained in:
Simon Backx 2022-05-11 12:07:13 +02:00
parent 97553181ce
commit 2d4bbad094
6 changed files with 77 additions and 10 deletions

View file

@ -0,0 +1,27 @@
<div class="modal-content" data-test-modal="limits/multiple-newsletters">
<header class="modal-header">
<h1>Upgrade to add more newsletters</h1>
</header>
<button class="close" title="Close" type="button" {{on "click" @close}}>{{svg-jar "close"}}<span class="hidden">Close</span></button>
<div class="modal-body">
<p>
{{#if @data.message}}
{{html-safe @data.message}}
{{else}}
Your current plan doesn't support more newsletters.
{{/if}}
</p>
</div>
<div class="modal-footer">
<button class="gh-btn" data-test-button="cancel-upgrade" type="button" {{on "click" @close}}>
<span>Cancel</span>
</button>
<LinkTo @route="pro" class="gh-btn gh-btn-green" {{on "click" @close}} data-test-button="upgrade-plan">
<span>Upgrade</span>
</LinkTo>
</div>
</div>

View file

@ -10,6 +10,7 @@ export default class NewsletterManagementComponent extends Component {
@service modals;
@service router;
@service store;
@service limit;
@tracked statusFilter = 'active';
@tracked filteredNewsletters = [];
@ -91,7 +92,21 @@ export default class NewsletterManagementComponent extends Component {
}
@action
unarchiveNewsletter(newsletter) {
async unarchiveNewsletter(newsletter) {
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;
}
throw error;
}
this.confirmUnarchiveModal = this.modals.open(ConfirmUnarchiveModal, {
newsletter,
unarchiveNewsletterTask: this.unarchiveNewsletterTask

View file

@ -8,9 +8,29 @@ export default class NewNewsletterRoute extends AdminRoute {
@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');
}

View file

@ -72,6 +72,10 @@ export default class LimitsService extends Service {
limits.members.currentCountQuery = bind(this, this.getMembersCount);
}
if (limits.newsletters) {
limits.newsletters.currentCountQuery = bind(this, this.getNewslettersCount);
}
return limits;
}
@ -93,4 +97,9 @@ export default class LimitsService extends Service {
return counts.total;
}
async getNewslettersCount() {
const activeNewsletters = await this.store.query('newsletter', {filter: 'status:active', limit: 'all'});
return activeNewsletters.length;
}
}

View file

@ -42,7 +42,7 @@
"@tryghost/helpers": "1.1.64",
"@tryghost/kg-clean-basic-html": "2.2.10",
"@tryghost/kg-parser-plugins": "2.11.6",
"@tryghost/limit-service": "1.0.10",
"@tryghost/limit-service": "1.1.3",
"@tryghost/members-csv": "1.2.10",
"@tryghost/mobiledoc-kit": "0.12.5-ghost.1",
"@tryghost/nql": "0.9.2",

View file

@ -2047,10 +2047,10 @@
dependencies:
"@tryghost/kg-clean-basic-html" "^2.2.10"
"@tryghost/limit-service@1.0.10":
version "1.0.10"
resolved "https://registry.yarnpkg.com/@tryghost/limit-service/-/limit-service-1.0.10.tgz#a22ff0c62599d849472f1a073650bc19e34cd7be"
integrity sha512-sZrlBRBgzSNg5QM+GULK40wU0x+GxinUYiyf/kMWGAalCdfziYBCQx5aJYz0lBOiMWiM0xkT5FFLPIC7fPSe4w==
"@tryghost/limit-service@1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@tryghost/limit-service/-/limit-service-1.1.3.tgz#9ce9187af6c83ada6575bcc4972a71e083f3bdc5"
integrity sha512-KM1jB6iL09XJeEvt4btdoNepQgeJw51/PWhAYBVbFj6Cuo4+82QLrZwkIWAhay440A3RSgOI4D0vL/WRog0jLg==
dependencies:
"@tryghost/errors" "^1.2.1"
lodash "^4.17.21"
@ -7212,7 +7212,6 @@ ember-power-calendar@^0.16.3:
ember-power-datepicker@cibernox/ember-power-datepicker:
version "0.8.1"
uid da580474a2c449b715444934ddb626b7c07f46a7
resolved "https://codeload.github.com/cibernox/ember-power-datepicker/tar.gz/da580474a2c449b715444934ddb626b7c07f46a7"
dependencies:
ember-basic-dropdown "^3.0.11"
@ -9088,7 +9087,6 @@ gonzales-pe@4.2.4:
"google-caja-bower@https://github.com/acburdine/google-caja-bower#ghost":
version "6011.0.0"
uid "275cb75249f038492094a499756a73719ae071fd"
resolved "https://github.com/acburdine/google-caja-bower#275cb75249f038492094a499756a73719ae071fd"
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4:
@ -10407,7 +10405,6 @@ just-extend@^4.0.2:
"keymaster@https://github.com/madrobby/keymaster.git":
version "1.6.3"
uid f8f43ddafad663b505dc0908e72853bcf8daea49
resolved "https://github.com/madrobby/keymaster.git#f8f43ddafad663b505dc0908e72853bcf8daea49"
kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0:
@ -14036,7 +14033,6 @@ simple-swizzle@^0.2.2:
"simplemde@https://github.com/kevinansfield/simplemde-markdown-editor.git#ghost":
version "1.11.2"
uid "4c39702de7d97f9b32d5c101f39237b6dab7c3ee"
resolved "https://github.com/kevinansfield/simplemde-markdown-editor.git#4c39702de7d97f9b32d5c101f39237b6dab7c3ee"
sinon@^9.0.0: