diff --git a/ghost/core/core/server/services/members/service.js b/ghost/core/core/server/services/members/service.js index 15f5933534..6855f29d1a 100644 --- a/ghost/core/core/server/services/members/service.js +++ b/ghost/core/core/server/services/members/service.js @@ -105,7 +105,7 @@ module.exports = { }); verificationTrigger = new VerificationTrigger({ - configThreshold: _.get(config.get('hostSettings'), 'emailVerification.importThreshold'), + apiTriggerThreshold: _.get(config.get('hostSettings'), 'emailVerification.importThreshold'), isVerified: () => config.get('hostSettings:emailVerification:verified') === true, isVerificationRequired: () => settingsCache.get('email_verification_required') === true, sendVerificationEmail: ({subject, message, amountImported}) => { diff --git a/ghost/member-events/lib/MemberCreatedEvent.js b/ghost/member-events/lib/MemberCreatedEvent.js index 9368b4d4a9..66b6e6320f 100644 --- a/ghost/member-events/lib/MemberCreatedEvent.js +++ b/ghost/member-events/lib/MemberCreatedEvent.js @@ -1,7 +1,7 @@ /** * @typedef {object} MemberCreatedEventData * @prop {string} memberId - * @prop {string} source + * @prop {'import' | 'system' | 'api' | 'admin' | 'member'} source * @prop {import('@tryghost/member-attribution/lib/attribution').Attribution} [attribution] Attribution */ diff --git a/ghost/member-events/lib/MemberSubscribeEvent.js b/ghost/member-events/lib/MemberSubscribeEvent.js index efc20efa34..c17af2f309 100644 --- a/ghost/member-events/lib/MemberSubscribeEvent.js +++ b/ghost/member-events/lib/MemberSubscribeEvent.js @@ -1,7 +1,7 @@ /** * @typedef {object} MemberSubscribeEventData * @prop {string} memberId - * @prop {string} source + * @prop {'import' | 'system' | 'api' | 'admin' | 'member'} source */ module.exports = class MemberSubscribeEvent { diff --git a/ghost/members-api/lib/repositories/member.js b/ghost/members-api/lib/repositories/member.js index ce88d496fb..f1f213d01e 100644 --- a/ghost/members-api/lib/repositories/member.js +++ b/ghost/members-api/lib/repositories/member.js @@ -98,6 +98,11 @@ module.exports = class MemberRepository { return subscription.plan && subscription.plan.nickname && subscription.plan.nickname.toLowerCase() === 'complimentary'; } + /** + * Maps the framework context to members_*.source table record value + * @param {Object} context instance of ghost framework context object + * @returns {'import' | 'system' | 'api' | 'admin' | 'member'} + */ _resolveContextSource(context) { let source; diff --git a/ghost/verification-trigger/lib/verification-trigger.js b/ghost/verification-trigger/lib/verification-trigger.js index 6e693488bc..a919ea741c 100644 --- a/ghost/verification-trigger/lib/verification-trigger.js +++ b/ghost/verification-trigger/lib/verification-trigger.js @@ -13,7 +13,7 @@ class VerificationTrigger { /** * * @param {object} deps - * @param {number} deps.configThreshold Threshold for triggering verification as defined in config + * @param {number} deps.apiTriggerThreshold Threshold for triggering verification as defined in config * @param {() => boolean} deps.isVerified Check Ghost config to see if we are already verified * @param {() => boolean} deps.isVerificationRequired Check Ghost settings to see whether verification has been requested * @param {(content: {subject: string, message: string, amountImported: number}) => {}} deps.sendVerificationEmail Sends an email to the escalation address to confirm that customer needs to be verified @@ -22,7 +22,7 @@ class VerificationTrigger { * @param {any} deps.eventRepository For querying events */ constructor({ - configThreshold, + apiTriggerThreshold, isVerified, isVerificationRequired, sendVerificationEmail, @@ -30,7 +30,7 @@ class VerificationTrigger { Settings, eventRepository }) { - this._configThreshold = configThreshold; + this._apiTriggerThreshold = apiTriggerThreshold; this._isVerified = isVerified; this._isVerificationRequired = isVerificationRequired; this._sendVerificationEmail = sendVerificationEmail; @@ -44,7 +44,7 @@ class VerificationTrigger { async _handleMemberSubscribeEvent(event) { const source = event.data?.source; - const sourceThreshold = this._configThreshold; + const sourceThreshold = this._apiTriggerThreshold; if (source === 'api' && isFinite(sourceThreshold)) { const createdAt = new Date(); @@ -65,7 +65,7 @@ class VerificationTrigger { } async getImportThreshold() { - const volumeThreshold = this._configThreshold; + const volumeThreshold = this._apiTriggerThreshold; if (isFinite(volumeThreshold)) { const membersTotal = await this._membersStats.getTotalMembers(); return Math.max(membersTotal, volumeThreshold); @@ -75,7 +75,7 @@ class VerificationTrigger { } async testImportThreshold() { - if (!isFinite(this._configThreshold)) { + if (!isFinite(this._apiTriggerThreshold)) { // Infinite threshold, quick path return; } @@ -91,7 +91,7 @@ class VerificationTrigger { // Import threshold is either the total number of members (discounting any created by imports in // the last 30 days) or the threshold defined in config, whichever is greater. - const importThreshold = Math.max(membersTotal - events.meta.pagination.total, this._configThreshold); + const importThreshold = Math.max(membersTotal - events.meta.pagination.total, this._apiTriggerThreshold); if (isFinite(importThreshold) && events.meta.pagination.total > importThreshold) { await this.startVerificationProcess({ amountImported: events.meta.pagination.total, diff --git a/ghost/verification-trigger/test/verification-trigger.test.js b/ghost/verification-trigger/test/verification-trigger.test.js index 45bde4bd32..f7400f55ab 100644 --- a/ghost/verification-trigger/test/verification-trigger.test.js +++ b/ghost/verification-trigger/test/verification-trigger.test.js @@ -9,7 +9,7 @@ const {MemberSubscribeEvent} = require('@tryghost/member-events'); describe('Import threshold', function () { it('Creates a threshold based on config', async function () { const trigger = new VerificationTrigger({ - configThreshold: 2, + apiTriggerThreshold: 2, membersStats: { getTotalMembers: async () => 1 } @@ -21,7 +21,7 @@ describe('Import threshold', function () { it('Increases the import threshold to the number of members', async function () { const trigger = new VerificationTrigger({ - configThreshold: 2, + apiTriggerThreshold: 2, membersStats: { getTotalMembers: async () => 3 } @@ -34,7 +34,7 @@ describe('Import threshold', function () { it('Does not check members count when config threshold is infinite', async function () { const membersStub = sinon.stub().resolves(null); const trigger = new VerificationTrigger({ - configThreshold: Infinity, + apiTriggerThreshold: Infinity, memberStats: { getTotalMembers: membersStub } @@ -203,7 +203,7 @@ describe('Email verification flow', function () { }); const trigger = new VerificationTrigger({ - configThreshold: 2, + apiTriggerThreshold: 2, Settings: { edit: settingsStub }, @@ -246,7 +246,7 @@ describe('Email verification flow', function () { }); const trigger = new VerificationTrigger({ - configThreshold: Infinity, + apiTriggerThreshold: Infinity, Settings: { edit: settingsStub },