-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Fixed paid welcome emails incorrectly sent to admin-created members #26086
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: main
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request modifies the option propagation mechanism in MemberBreadService to conditionally spread both Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.40.5)ghost/core/test/e2e-api/members/webhooks.test.jsThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
When members are created via Admin API with stripe_customer_id: - Session auth (context.user) → source='admin' → no staff notification - API key auth (context.api_key) → source='api' → staff notification sent This is correct because: - Staff notifications filter: ['api', 'member'] only - Admins manually linking Stripe customers already know about the subscription
Documents all staff notification email types, their triggers, and the source filtering logic that determines when notifications are sent. refs #26086
Documents all staff notification email types, their triggers, and the source filtering logic that determines when notifications are sent. refs #26086
ef12707 to
2391d40
Compare
|
I did some digging and found this issue from the original implementation: https://github.com/TryGhost/Product/issues/1864
So I think this actually is correct, and the members webhook tests were only passing because of this bug |
ref TryGhost/Product#1864 These tests verify the intended behavior documented in the referenced issue: - source='admin' (session auth) → NO staff notification emails - source='api' (API key auth) → Staff notification emails ARE sent - source='member' (checkout webhook) → Staff notification emails ARE sent - source='import' → NO staff notification emails Also added `sentEmailCount` assertion to the mock manager for verifying that zero emails were sent.
| mockManager.assert.sentEmail({ | ||
| subject: /Paid subscription started: Cancel me at the end of the billing cycle/, | ||
| to: 'jbloggs@example.com' | ||
| }); | ||
|
|
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.
This assertion should not have been here in the first place, but it was required in the test due to the underlying bug we found.
The member created above in this test now correctly has source = 'admin', and Ghost correctly should not send a "Paid subscription started" notification email in this case. There isn't really a behavioral change here, because there isn't any UI in Admin that allows creating paid members with stripe_customer_id.
| mockManager.assert.sentEmail({ | ||
| subject: /Paid subscription started: Cancel me now/, | ||
| to: 'jbloggs@example.com' | ||
| }); | ||
|
|
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.
Ditto here
ref https://linear.app/ghost/issue/NY-891/before-ga-double-check-that-only-members-createdupdated-through-portal
Summary
member-bread-service.add()to verify context is passed tolinkStripeCustomercontextwas not included insharedOptionswhen callinglinkStripeCustomerProblem
When an admin creates a member via the Admin API with a
stripe_customer_id, the paid welcome email was incorrectly being sent. This happened because:member-bread-service.add()callslinkStripeCustomer()withsharedOptionssharedOptionsonly includedtransacting, notcontextlinkStripeCustomer()→linkSubscription()uses context to determine the source_resolveContextSource({})defaulted to'member''member'is inWELCOME_EMAIL_SOURCES, the paid welcome email was queuedFix
Updated
sharedOptionsinmember-bread-service.jsto includecontext:Now the source correctly resolves to
'admin'for admin-created members, and no welcome email is sent.Side effect in members API tests
This change also corrects a bug in the staff notifications behavior, which was being hidden by the bug described above. Previously in the members API tests we were asserting that a "Paid subscription started" staff notification was sent. This was the case because, due to the bug described and fixed in this PR, the member in these tests was being incorrectly created with source = 'member'.
Now these members are correctly created with source = 'admin', and we correctly do not send the "Paid subscription started" notification anymore.
Testing
Signup as a paid member via portal
Add a paid member via Admin API
/ghost/api/admin/members, using your access token to authenticate and passing the stripe_customer_idstatus = paidAdd a paid member via members CSV import
status = paid