From a7dd7bb64b7ecd7e2e2d06b378550ceb5967c12b Mon Sep 17 00:00:00 2001 From: Naz Date: Fri, 23 Jul 2021 20:37:29 +0400 Subject: [PATCH] Added email verification limit check refs https://github.com/TryGhost/Team/issues/912 - When the import threshold is reached we want to trigger an "email" limit. See details in the refed issue --- core/server/services/limits.js | 4 +-- core/server/services/members/service.js | 33 ++++++++++++++++++++++--- package.json | 2 +- yarn.lock | 8 +++--- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/core/server/services/limits.js b/core/server/services/limits.js index 03111d8b9d..fde6e6952c 100644 --- a/core/server/services/limits.js +++ b/core/server/services/limits.js @@ -4,7 +4,7 @@ const db = require('../data/db'); const LimitService = require('@tryghost/limit-service'); let limitService = new LimitService(); -const initFn = () => { +const initFn = (limits) => { let helpLink; if (config.get('hostSettings:billing:enabled') && config.get('hostSettings:billing:enabled') === true && config.get('hostSettings:billing:url')) { @@ -23,7 +23,7 @@ const initFn = () => { } limitService.loadLimits({ - limits: config.get('hostSettings:limits'), + limits: Object.assign(config.get('hostSettings:limits'), limits), subscription, db, helpLink, diff --git a/core/server/services/members/service.js b/core/server/services/members/service.js index 0905dc4929..f4eabeafd3 100644 --- a/core/server/services/members/service.js +++ b/core/server/services/members/service.js @@ -16,11 +16,14 @@ 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.' + 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` }; // Bind to settings.edited to update systems based on settings changes, similar to the bridge and models/base/listeners @@ -48,6 +51,15 @@ function reconfigureMembersAPI() { logging.error(err); }); } + +const getThreshold = () => { + if (_.get(config.get('hostSettings'), 'emailVerification.verified')) { + return null; + } + + return _.get(config.get('hostSettings'), 'emailVerification.importThreshold'); +}; + const membersImporter = new MembersCSVImporter({ storagePath: config.getContentPath('data'), getTimezone: () => settingsCache.get('timezone'), @@ -57,11 +69,26 @@ const membersImporter = new MembersCSVImporter({ addJob: jobsService.addJob.bind(jobsService), knex: db.knex, urlFor: urlUtils.urlFor.bind(urlUtils), - importThreshold: config.get('hostSettings.emailVerification.importThreshold') + importThreshold: getThreshold() }); const processImport = async (options) => { - return membersImporter.process(options); + const result = await membersImporter.process(options); + + if (result.meta.freeze) { + limits.init({ + emails: { + disabled: true, + error: tpl(messages.emailSendingDisabled) + } + }); + + throw new errors.ValidationError({ + message: tpl(messages.emailVerificationNeeded) + }); + } + + return result; }; const debouncedReconfigureMembersAPI = _.debounce(reconfigureMembersAPI, 600); diff --git a/package.json b/package.json index a7a8ad1a9d..31c6810b8f 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "@tryghost/magic-link": "1.0.7", "@tryghost/members-api": "1.23.1", "@tryghost/members-csv": "1.1.2", - "@tryghost/members-importer": "0.1.0", + "@tryghost/members-importer": "0.1.1", "@tryghost/members-ssr": "1.0.8", "@tryghost/mw-session-from-token": "0.1.22", "@tryghost/package-json": "1.0.2", diff --git a/yarn.lock b/yarn.lock index 3000ef26ba..c583c275cf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -856,10 +856,10 @@ papaparse "5.3.1" pump "^3.0.0" -"@tryghost/members-importer@0.1.0": - version "0.1.0" - resolved "https://registry.yarnpkg.com/@tryghost/members-importer/-/members-importer-0.1.0.tgz#d36544e2917c41e7f35c66c91deff567c83da9b5" - integrity sha512-eiruaYreKd7S7mGtLS2RzAMwq7T48bL4Pa5497bi3soCQCS0P8GCfonojwQmYPDHaF3xPN/oY+80q6HqP43+rw== +"@tryghost/members-importer@0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@tryghost/members-importer/-/members-importer-0.1.1.tgz#c1b6d26b3afc41fc1ae7f73e1661318d32ae949a" + integrity sha512-tzCimEgVT55x3HrOwwQuQDyX7Jx2vH6ec1HlJLVH4GwezRjh3ooztXRet6Qy5lp6oE3iB3Pob3KXaWnuI35Qtw== dependencies: "@tryghost/errors" "^0.2.13" "@tryghost/members-csv" "^1.1.2"