mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Parameterized api sourced verification threshold
refs https://github.com/TryGhost/Toolbox/issues/387 - The limit values should be as configurable as possible to adjust verification thresholds dinamically per-usecase. This solves a problem of doing a separate version release when we need to adjust the verification thresholds. - Before this "importThreshold" was the same concept as "apiThreshold", which makes it hard&confusing to reason about and hard to parameterize each specific case.
This commit is contained in:
parent
7d2f49a0a8
commit
6e76fcc36a
3 changed files with 12 additions and 8 deletions
|
@ -105,8 +105,9 @@ module.exports = {
|
|||
});
|
||||
|
||||
verificationTrigger = new VerificationTrigger({
|
||||
apiTriggerThreshold: _.get(config.get('hostSettings'), 'emailVerification.importThreshold'),
|
||||
apiTriggerThreshold: _.get(config.get('hostSettings'), 'emailVerification.apiThreshold'),
|
||||
adminTriggerThreshold: _.get(config.get('hostSettings'), 'emailVerification.adminThreshold'),
|
||||
importTriggerThreshold: _.get(config.get('hostSettings'), 'emailVerification.importThreshold'),
|
||||
isVerified: () => config.get('hostSettings:emailVerification:verified') === true,
|
||||
isVerificationRequired: () => settingsCache.get('email_verification_required') === true,
|
||||
sendVerificationEmail: ({subject, message, amountTriggered}) => {
|
||||
|
|
|
@ -16,6 +16,7 @@ class VerificationTrigger {
|
|||
* @param {object} deps
|
||||
* @param {number} deps.apiTriggerThreshold Threshold for triggering API&Import sourced verifications
|
||||
* @param {number} deps.adminTriggerThreshold Threshold for triggering Admin sourced verifications
|
||||
* @param {number} deps.importTriggerThreshold Threshold for triggering Import sourced verifications
|
||||
* @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, amountTriggered: number}) => void} deps.sendVerificationEmail Sends an email to the escalation address to confirm that customer needs to be verified
|
||||
|
@ -26,6 +27,7 @@ class VerificationTrigger {
|
|||
constructor({
|
||||
apiTriggerThreshold,
|
||||
adminTriggerThreshold,
|
||||
importTriggerThreshold,
|
||||
isVerified,
|
||||
isVerificationRequired,
|
||||
sendVerificationEmail,
|
||||
|
@ -35,6 +37,7 @@ class VerificationTrigger {
|
|||
}) {
|
||||
this._apiTriggerThreshold = apiTriggerThreshold;
|
||||
this._adminTriggerThreshold = adminTriggerThreshold;
|
||||
this._importTriggerThreshold = importTriggerThreshold;
|
||||
this._isVerified = isVerified;
|
||||
this._isVerificationRequired = isVerificationRequired;
|
||||
this._sendVerificationEmail = sendVerificationEmail;
|
||||
|
@ -79,7 +82,7 @@ class VerificationTrigger {
|
|||
}
|
||||
|
||||
async getImportThreshold() {
|
||||
const volumeThreshold = this._apiTriggerThreshold;
|
||||
const volumeThreshold = this._importTriggerThreshold;
|
||||
if (isFinite(volumeThreshold)) {
|
||||
const membersTotal = await this._membersStats.getTotalMembers();
|
||||
return Math.max(membersTotal, volumeThreshold);
|
||||
|
@ -89,7 +92,7 @@ class VerificationTrigger {
|
|||
}
|
||||
|
||||
async testImportThreshold() {
|
||||
if (!isFinite(this._apiTriggerThreshold)) {
|
||||
if (!isFinite(this._importTriggerThreshold)) {
|
||||
// Infinite threshold, quick path
|
||||
return;
|
||||
}
|
||||
|
@ -105,7 +108,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._apiTriggerThreshold);
|
||||
const importThreshold = Math.max(membersTotal - events.meta.pagination.total, this._importTriggerThreshold);
|
||||
if (isFinite(importThreshold) && events.meta.pagination.total > importThreshold) {
|
||||
await this._startVerificationProcess({
|
||||
amount: events.meta.pagination.total,
|
||||
|
|
|
@ -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({
|
||||
apiTriggerThreshold: 2,
|
||||
importTriggerThreshold: 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({
|
||||
apiTriggerThreshold: 2,
|
||||
importTriggerThreshold: 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({
|
||||
apiTriggerThreshold: Infinity,
|
||||
importTriggerThreshold: Infinity,
|
||||
memberStats: {
|
||||
getTotalMembers: membersStub
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ describe('Email verification flow', function () {
|
|||
});
|
||||
|
||||
const trigger = new VerificationTrigger({
|
||||
apiTriggerThreshold: 2,
|
||||
importTriggerThreshold: 2,
|
||||
Settings: {
|
||||
edit: settingsStub
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue