Changed member welcome email job to run based on config#8
Conversation
Code Review by Qodo
1. var member declaration used
|
| const memberAddOptions = {...(options || {}), withRelated}; | ||
| let member; | ||
| if (this._labsService.isSet('welcomeEmails') && WELCOME_EMAIL_SOURCES.includes(source)) { | ||
| var member; |
There was a problem hiding this comment.
1. var member declaration used 📘 Rule violation ✓ Correctness
• New code declares member with var, which violates the requirement to use block-scoped let/const. • This increases the risk of hoisting/scope-related bugs and makes the variable’s lifetime harder to reason about.
Agent prompt
## Issue description
`MemberRepository.js` introduces `var member;`, which violates the codebase requirement to use `let`/`const` instead of `var`.
## Issue Context
`var` is function-scoped and hoisted, which can lead to subtle scoping/initialization issues.
## Fix Focus Areas
- ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js[339-342]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| const welcomeEmailConfig = config.get('memberWelcomeEmailTestInbox'); | ||
| if (welcomeEmailConfig || WELCOME_EMAIL_SOURCES.includes(source)) { |
There was a problem hiding this comment.
2. Config check uses wrong or 📘 Rule violation ⛯ Reliability
• The new condition if (welcomeEmailConfig || WELCOME_EMAIL_SOURCES.includes(source)) will evaluate true for source === 'member' even when the config is unset/undefined. • This fails to handle the “config not set” edge case, potentially creating outbox entries (and sending welcome emails) when the feature should be disabled.
Agent prompt
## Issue description
The welcome-email gating logic uses `||`, which bypasses the "config not set" edge case. Because `WELCOME_EMAIL_SOURCES` contains `'member'`, the condition becomes true even when `config.get('memberWelcomeEmailTestInbox')` is undefined/empty.
## Issue Context
This can cause outbox entries to be created (and downstream welcome email processing to run) when configuration indicates the feature should be disabled.
## Fix Focus Areas
- ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js[340-342]
- ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js[26-29]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| if (hasScheduled.processOutbox && !process.env.NODE_ENV.startsWith('test')) { | ||
| jobsService.addJob({ | ||
| at: '0 */5 * * * *', | ||
| job: path.resolve(__dirname, 'process-outbox.js'), |
There was a problem hiding this comment.
3. Job never scheduled 🐞 Bug ✓ Correctness
• scheduleMemberWelcomeEmailJob() now checks hasScheduled.processOutbox instead of !hasScheduled.processOutbox, but the flag initializes to false and is only set to true inside the guarded block. • This makes the scheduling block unreachable on first run, so the recurring outbox-processing job is never added (welcome emails won’t be processed). • If the flag were ever toggled elsewhere, the current logic would also allow duplicate scheduling on repeated calls instead of preventing it.
Agent prompt
### Issue description
The member welcome email outbox processor job is never scheduled because the `hasScheduled.processOutbox` check was inverted.
### Issue Context
`hasScheduled.processOutbox` initializes to `false` and is only set to `true` inside the guarded block. With the current condition, the guarded block is unreachable.
### Fix Focus Areas
- ghost/core/core/server/services/member-welcome-emails/jobs/index.js[15-23]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Benchmark PR from agentic-review-benchmarks#6