0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Added host limit check for members email publish (#11534)

no issue
This commit is contained in:
Rishabh Garg 2020-02-13 10:43:36 +05:30 committed by GitHub
parent 25721828d9
commit 9c1aa07ea8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@ const membersService = require('../members');
const bulkEmailService = require('../bulk-email');
const models = require('../../models');
const postEmailSerializer = require('./post-email-serializer');
const config = require('../../config');
const getEmailData = async (postModel, recipients = []) => {
const emailTmpl = await postEmailSerializer.serialize(postModel);
@ -142,6 +143,24 @@ async function handleUnsubscribeRequest(req) {
}
}
function checkHostLimitForMembers(members = []) {
const membersHostLimit = config.get('host_settings:limits:members');
if (membersHostLimit) {
const allowedMembersLimit = membersHostLimit.max;
const hostUpgradeLink = config.get('host_settings:limits').upgrade_url;
if (members.length > allowedMembersLimit) {
throw new common.errors.HostLimitError({
message: `Your current plan allows you to send email to up to ${allowedMembersLimit} members, but you currently have ${members.length} members`,
help: hostUpgradeLink,
errorDetails: {
limit: allowedMembersLimit,
total: members.length
}
});
}
}
}
async function pendingEmailHandler(emailModel, options) {
// CASE: do not send email if we import a database
// TODO: refactor post.published events to never fire on importing
@ -170,6 +189,8 @@ async function pendingEmailHandler(emailModel, options) {
let error = null;
try {
// Check host limit for allowed member count and throw error if over limit
checkHostLimitForMembers(members);
// NOTE: meta can contains an array which can be a mix of successful and error responses
// needs filtering and saving objects of {error, batchData} form to separate property
meta = await sendEmail(postModel, members);