Added email notifications toggle for gift subscription events#27307
Added email notifications toggle for gift subscription events#27307
Conversation
WalkthroughAdds two boolean user notification fields, 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
f65d37e to
8b11f20
Compare
7ce4c34 to
54e8c1a
Compare
8b11f20 to
e8e31a8
Compare
54e8c1a to
032805e
Compare
e8e31a8 to
cd3a9a2
Compare
032805e to
1093508
Compare
cd3a9a2 to
ff8dae9
Compare
ff8dae9 to
49501b5
Compare
1093508 to
3109fd9
Compare
296b96f to
e6c0203
Compare
ref https://linear.app/ghost/issue/BER-3523 Added email notifications toggle for gift subscription events
e6c0203 to
88a4a35
Compare
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
ghost/core/core/server/models/user.js (1)
499-523:⚠️ Potential issue | 🟠 MajorFail closed for unknown email alert types.
getEmailAlertUserscurrently falls back tostatus:activewhentypeis unrecognized, which can notify all active owners/admins and bypass per-event opt-in flags. With the new gift keys, a typo/regression in a caller becomes an over-notification path.Suggested fix
getEmailAlertUsers(type, options) { options = options || {}; - - let filter = 'status:active'; - if (type === 'free-signup') { - filter += '+free_member_signup_notification:true'; - } else if (type === 'paid-started') { - filter += '+paid_subscription_started_notification:true'; - } else if (type === 'paid-canceled') { - filter += '+paid_subscription_canceled_notification:true'; - } else if (type === 'mention-received') { - filter += '+mention_notifications:true'; - } else if (type === 'milestone-received') { - filter += '+milestone_notifications:true'; - } else if (type === 'donation') { - filter += '+donation_notifications:true'; - } else if (type === 'recommendation-received') { - filter += '+recommendation_notifications:true'; - } else if (type === 'gift-subscription-purchased') { - filter += '+gift_subscription_purchase_notification:true'; - } else if (type === 'gift-subscription-redeemed') { - filter += '+gift_subscription_redemption_notification:true'; - } + const notificationFieldByType = { + 'free-signup': 'free_member_signup_notification', + 'paid-started': 'paid_subscription_started_notification', + 'paid-canceled': 'paid_subscription_canceled_notification', + 'mention-received': 'mention_notifications', + 'milestone-received': 'milestone_notifications', + 'donation': 'donation_notifications', + 'recommendation-received': 'recommendation_notifications', + 'gift-subscription-purchased': 'gift_subscription_purchase_notification', + 'gift-subscription-redeemed': 'gift_subscription_redemption_notification' + }; + + const notificationField = notificationFieldByType[type]; + if (!notificationField) { + return Promise.resolve([]); + } + + const filter = `status:active+${notificationField}:true`; const updatedOptions = Object.assign({}, options, {filter, withRelated: ['roles']}); return this.findAll(updatedOptions).then((users) => { return users.toJSON().filter((user) => { return user?.roles?.some((role) => { return ['Owner', 'Administrator'].includes(role.name); }); }); }); },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ghost/core/core/server/models/user.js` around lines 499 - 523, getEmailAlertUsers currently defaults to 'status:active' for unknown types which risks over-notifying; update the function to validate the incoming type against the known set (e.g., free-signup, paid-started, paid-canceled, mention-received, milestone-received, donation, recommendation-received, gift-subscription-purchased, gift-subscription-redeemed) and fail closed for anything unrecognized by returning an empty result (e.g., return Promise.resolve([])) or applying a filter that matches no users before calling findAll; adjust the code that builds filter (variable filter) and updatedOptions so unknown types do not fall through to the active-owner path and optionally emit a warning log instead of querying with 'status:active'.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@ghost/core/core/server/models/user.js`:
- Around line 499-523: getEmailAlertUsers currently defaults to 'status:active'
for unknown types which risks over-notifying; update the function to validate
the incoming type against the known set (e.g., free-signup, paid-started,
paid-canceled, mention-received, milestone-received, donation,
recommendation-received, gift-subscription-purchased,
gift-subscription-redeemed) and fail closed for anything unrecognized by
returning an empty result (e.g., return Promise.resolve([])) or applying a
filter that matches no users before calling findAll; adjust the code that builds
filter (variable filter) and updatedOptions so unknown types do not fall through
to the active-owner path and optionally emit a warning log instead of querying
with 'status:active'.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 70dda4b7-9905-4500-8e72-42db2d671529
📒 Files selected for processing (6)
apps/admin-x-framework/src/api/users.tsapps/admin-x-settings/src/components/settings/general/users/email-notifications-tab.tsxapps/admin/test-utils/factories/user.tsghost/core/core/server/models/user.jsghost/core/core/server/services/staff/staff-service-emails.jsghost/core/test/unit/server/services/staff/staff-service.test.js
✅ Files skipped from review due to trivial changes (2)
- ghost/core/test/unit/server/services/staff/staff-service.test.js
- apps/admin/test-utils/factories/user.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- ghost/core/core/server/services/staff/staff-service-emails.js
- apps/admin-x-framework/src/api/users.ts



ref https://linear.app/ghost/issue/BER-3523
Added email notifications toggle for gift subscription events