Fixed welcome email being sent for Admin API creates

ref https://linear.app/tryghost/issue/ONC-274

This fix is done at the endpoint layer, which isn't ideal, but has the smallest
surface area for the change. I think we may want to move it up a layer though,
despite the extra complications. If we move the check _into_ the MembersAPI
class however, we start to run into issues with circular dependncies due to the
mess that is our dependency injection approach with the Members service
This commit is contained in:
Fabien O'Carroll 2024-08-28 12:01:29 +07:00 committed by Fabien 'egg' O'Carroll
parent 3adc0c0441
commit 2d00d5ca0e

View File

@ -2,6 +2,7 @@
// as it is a getter and may change during runtime.
const moment = require('moment-timezone');
const errors = require('@tryghost/errors');
const logging = require('@tryghost/logging');
const models = require('../../models');
const membersService = require('../../services/members');
@ -11,6 +12,7 @@ const _ = require('lodash');
const messages = {
memberNotFound: 'Member not found.',
notSendingWelcomeEmail: 'Email verification required, welcome email is disabled',
memberAlreadyExists: {
message: 'Member already exists',
context: 'Attempting to {action} member with existing email address.'
@ -115,6 +117,10 @@ const controller = {
},
permissions: true,
async query(frame) {
if (await membersService.verificationTrigger.checkVerificationRequired()) {
logging.warn(tpl(messages.notSendingWelcomeEmail));
frame.options.send_email = false;
}
const member = await membersService.api.memberBREADService.add(frame.data.members[0], frame.options);
return member;