-
Notifications
You must be signed in to change notification settings - Fork 0
Changed member welcome email job to run based on config #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devin_pr_code_review_bench_100_devin2_base_changed_member_welcome_email_job_to_run_based_on_config_pr246
Are you sure you want to change the base?
Changes from all commits
6d57f83
3fa71dd
5d1fdee
ca932dd
30dff3b
96cac63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ const ObjectId = require('bson-objectid').default; | |
| const {NotFoundError} = require('@tryghost/errors'); | ||
| const validator = require('@tryghost/validator'); | ||
| const crypto = require('crypto'); | ||
| const config = require('../../../../../shared/config'); | ||
|
|
||
| const messages = { | ||
| noStripeConnection: 'Cannot {action} without a Stripe Connection', | ||
|
|
@@ -336,8 +337,9 @@ module.exports = class MemberRepository { | |
| const eventData = _.pick(data, ['created_at']); | ||
|
|
||
| const memberAddOptions = {...(options || {}), withRelated}; | ||
| let member; | ||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 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 ( Click to expandHow the bug is triggeredThe 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 ( 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 behaviorExpected: When Actual: When Evidence from testsThe tests at it('does NOT create outbox entry when member is imported', async function () {
configUtils.set('memberWelcomeEmailTestInbox', 'test-inbox@example.com');
// ...
assert.equal(outboxEntries.length, 0);
});ImpactImported members, admin-created members, and API-created members will incorrectly receive welcome emails when the config is set, which could result in:
Recommendation: Change the condition to Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| const runMemberCreation = async (transacting) => { | ||
| const newMember = await this._Member.add({ | ||
| ...memberData, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Inverted condition prevents welcome email job from ever being scheduled
The condition for scheduling the member welcome email job was changed from
!hasScheduled.processOutboxtohasScheduled.processOutbox, inverting the logic.Click to expand
How the bug is triggered
The
hasScheduled.processOutboxflag is initialized tofalseat module load time (ghost/core/core/server/services/member-welcome-emails/jobs/index.js:5-7):With the new condition
if (hasScheduled.processOutbox && ...), the job will only be scheduled whenhasScheduled.processOutboxistrue. However, since it starts asfalseand is only set totrueINSIDE 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.processOutboxisfalse(using!hasScheduled.processOutbox).Actual: The job is never scheduled because the condition requires
hasScheduled.processOutboxto betrue, but it's alwaysfalseuntil 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.