From 93e88145895f707021fee3677231ae373218b074 Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 28 Jul 2021 14:24:52 +0400 Subject: [PATCH] Moved sending email error into MEGA closes https://github.com/TryGhost/Team/issues/913 - Having a limit service rule triggered was a temporary hack to get a basic email blocking version working - As the freeze value is now persisted in the DB it's possible to read and rely on it to throw an error straight from MEGA. --- core/server/services/mega/mega.js | 9 ++++++++- core/server/services/members/service.js | 11 +---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/core/server/services/mega/mega.js b/core/server/services/mega/mega.js index 2bee266486..674ec763e8 100644 --- a/core/server/services/mega/mega.js +++ b/core/server/services/mega/mega.js @@ -25,7 +25,8 @@ const events = require('../../lib/common/events'); const messages = { invalidSegment: 'Invalid segment value. Use one of the valid:"status:free" or "status:-free" values.', unexpectedFilterError: 'Unexpected {property} value "{value}", expected an NQL equivalent', - noneFilterError: 'Cannot send email to "none" {property}' + noneFilterError: 'Cannot send email to "none" {property}', + emailSendingDisabled: `Sending is temporarily disabled because your account is currently in review. You should have an email about this from us already, but you can also reach us any time at support@ghost.org` }; const getFromAddress = () => { @@ -159,6 +160,12 @@ const addEmail = async (postModel, options) => { await limitService.errorIfWouldGoOverLimit('emails'); } + if (settingsCache.get('email_verification_required') === true) { + throw new errors.HostLimitError({ + message: tpl(messages.emailSendingDisabled) + }); + } + const knexOptions = _.pick(options, ['transacting', 'forUpdate']); const filterOptions = Object.assign({}, knexOptions, {limit: 1}); diff --git a/core/server/services/members/service.js b/core/server/services/members/service.js index a87dc9fcc1..00c303bd72 100644 --- a/core/server/services/members/service.js +++ b/core/server/services/members/service.js @@ -17,14 +17,12 @@ const ghostVersion = require('@tryghost/version'); const _ = require('lodash'); const {GhostMailer} = require('../mail'); const jobsService = require('../jobs'); -const limits = require('../limits'); const messages = { noLiveKeysInDevelopment: 'Cannot use live stripe keys in development. Please restart in production mode.', sslRequiredForStripe: 'Cannot run Ghost without SSL when Stripe is connected. Please update your url config to use "https://".', remoteWebhooksInDevelopment: 'Cannot use remote webhooks in development. See https://ghost.org/docs/webhooks/#stripe-webhooks for developing with Stripe.', - emailVerificationNeeded: `To make sure you get great deliverability on a list of that size, we'll need to enable some extra features for your account. A member of our team will be in touch with you by email to review your account make sure everything is configured correctly so you're ready to go.`, - emailSendingDisabled: `Sending is temporarily disabled because your account is currently in review. You should have an email about this from us already, but you can also reach us any time at support@ghost.org` + emailVerificationNeeded: `To make sure you get great deliverability on a list of that size, we'll need to enable some extra features for your account. A member of our team will be in touch with you by email to review your account make sure everything is configured correctly so you're ready to go.` }; // Bind to settings.edited to update systems based on settings changes, similar to the bridge and models/base/listeners @@ -77,13 +75,6 @@ const processImport = async (options) => { const isVerifiedEmail = config.get('hostSettings:emailVerification:verified') === true; if ((!isVerifiedEmail) && freezeTriggered) { - limits.init({ - emails: { - disabled: true, - error: tpl(messages.emailSendingDisabled) - } - }); - await models.Settings.edit([{ key: 'email_freeze', value: true