mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
parent
25721828d9
commit
9c1aa07ea8
1 changed files with 21 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue