Changed member welcome email job to run based on config#19
Conversation
| } | ||
|
|
||
| if (!hasScheduled.processOutbox && !process.env.NODE_ENV.startsWith('test')) { | ||
| if (hasScheduled.processOutbox && !process.env.NODE_ENV.startsWith('test')) { |
There was a problem hiding this comment.
🔴 Inverted condition prevents welcome email job from ever being scheduled
The condition for scheduling the member welcome email job was changed from !hasScheduled.processOutbox to hasScheduled.processOutbox, inverting the logic.
Click to expand
How the bug is triggered
The hasScheduled.processOutbox flag is initialized to false at module load time (ghost/core/core/server/services/member-welcome-emails/jobs/index.js:5-7):
let hasScheduled = {
processOutbox: false
};With the new condition if (hasScheduled.processOutbox && ...), the job will only be scheduled when hasScheduled.processOutbox is true. However, since it starts as false and is only set to true INSIDE the if-block (line 22), the condition can never be satisfied.
Actual vs Expected behavior
Expected: The job should be scheduled on the first call when hasScheduled.processOutbox is false (using !hasScheduled.processOutbox).
Actual: The job is never scheduled because the condition requires hasScheduled.processOutbox to be true, but it's always false until the job is scheduled.
Impact
The member welcome email processing job will never run, meaning welcome emails will never be sent to new members even when the feature is enabled via config.
Recommendation: Change the condition back to if (!hasScheduled.processOutbox && !process.env.NODE_ENV.startsWith('test')) to ensure the job is scheduled on the first call.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if (this._labsService.isSet('welcomeEmails') && WELCOME_EMAIL_SOURCES.includes(source)) { | ||
| var member; | ||
| const welcomeEmailConfig = config.get('memberWelcomeEmailTestInbox'); | ||
| if (welcomeEmailConfig || WELCOME_EMAIL_SOURCES.includes(source)) { |
There was a problem hiding this comment.
🔴 OR condition causes welcome emails to be sent for all sources when config is set
The condition for creating outbox entries was changed from AND (&&) to OR (||), causing welcome emails to be sent for all member sources (import, admin, api) when the config is set.
Click to expand
How the bug is triggered
The original logic was:
if (this._labsService.isSet('welcomeEmails') && WELCOME_EMAIL_SOURCES.includes(source))This required BOTH the feature flag to be enabled AND the source to be in the allowed list (['member']).
The new logic is:
if (welcomeEmailConfig || WELCOME_EMAIL_SOURCES.includes(source))This creates an outbox entry if EITHER the config is set OR the source is 'member'.
Actual vs Expected behavior
Expected: When memberWelcomeEmailTestInbox config is set, welcome emails should only be sent for members created with source 'member' (self-signup). Members created via import, admin, or API should NOT receive welcome emails.
Actual: When memberWelcomeEmailTestInbox config is set, welcome emails are sent for ALL member sources including import, admin, and API.
Evidence from tests
The tests at ghost/core/test/integration/services/member-welcome-emails.test.js:67-94 explicitly expect that imported members and admin-created members should NOT create outbox entries even when the config is set:
it('does NOT create outbox entry when member is imported', async function () {
configUtils.set('memberWelcomeEmailTestInbox', 'test-inbox@example.com');
// ...
assert.equal(outboxEntries.length, 0);
});Impact
Imported members, admin-created members, and API-created members will incorrectly receive welcome emails when the config is set, which could result in:
- Spam complaints from bulk-imported members
- Confusion for members added by admins
- Unexpected email volume
Recommendation: Change the condition to if (welcomeEmailConfig && WELCOME_EMAIL_SOURCES.includes(source)) to require both the config to be set AND the source to be in the allowed list.
Was this helpful? React with 👍 or 👎 to provide feedback.
Benchmark PR from qodo-benchmark#246