fix(api/approvals): toast and history use Admin notification_email, not per-account contact (closes #735) - #740
Conversation
…t field The success toast after submitting an Azure purchase for approval was naming the per-account contact_email (e.g. jcorbett@archera.ai) as the addressee, while the Purchase History row correctly showed the Admin-set notification_email (e.g. cristi@leanercloud.com). The two UIs used different data sources for the same "who received the approval email" field. Root cause: sendPurchaseApprovalEmail returned the resolveApprovalRecipients `to` address (contact_email when present) as approval_recipient. But the History handler's resolvePendingApproverEmail always reads globalCfg.NotificationEmail. Fix: compute responseRecipient = globalNotify when set, else fall back to `to`. This matches the History handler's resolution logic exactly so both UIs show the same address. The actual email delivery (To = contact_email, Cc = notification_email) and the authorised-approver security model are unchanged. Tests: - Backend: TestHandler_sendPurchaseApprovalEmail_ResponseRecipientUsesNotificationEmail asserts responseRecipient = notificationEmail when both are configured, and that the actual email To remains contact_email (security model intact). - Backend: TestHandler_sendPurchaseApprovalEmail_ResponseRecipientFallsBackToContactEmail asserts the contact_email fallback when no notification_email is set. - Frontend: two tests in issue #735 describe block assert the toast shows whatever approval_recipient the API returns. Fixes #735.
|
Warning Review limit reached
More reviews will be available in 46 minutes and 58 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR fixes bug ChangesApproval recipient correction
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/api/handler_purchases.go`:
- Around line 1510-1514: The function approvalResponseRecipient should trim
globalNotify before testing emptiness so whitespace-only notification_email
doesn't count as set; update approvalResponseRecipient to call
strings.TrimSpace(globalNotify) and check that for != "" before returning it,
and apply the same trim-and-check fix where resolveApprovalRecipients selects
approval_recipient (the same recipient-selection logic around lines 1555-1560)
so contact email fallback works when notification_email is only whitespace.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2fadcc29-4188-410e-9662-79c9c8277ff6
📒 Files selected for processing (3)
frontend/src/__tests__/purchase-execution-toast.test.tsinternal/api/coverage_gaps_test.gointernal/api/handler_purchases.go
…heck (CR #740) approvalResponseRecipient now calls strings.TrimSpace(globalNotify) before testing for non-empty, so a whitespace-only notification_email value does not qualify as set. The trimmed value is returned to the caller, preventing stray spaces from appearing in the toast or email headers. resolveApprovalRecipients already performs the same trim at line 1653; this brings approvalResponseRecipient into parity. Regression tests added: - TestHandler_approvalResponseRecipient_TrimsWhitespace: whitespace-only falls back to contact_email. - TestHandler_approvalResponseRecipient_TrimsNonEmptyValue: padded address is returned trimmed. Fixes: CodeRabbit finding on PR #740.
|
Addressed the CodeRabbit finding:
Two regression tests added:
@coderabbitai review |
|
✅ Actions performedReview triggered.
|
Summary
Fixes #735 (P1). Diverging "approver" identity surfaced in two UIs for the same execution: toast said
Approval request sent to jcorbett@archera.ai, Purchase History saidawaiting approval from cristi@leanercloud.com.Root cause:
sendPurchaseApprovalEmail's API response setapproval_recipientto thetofield returned byresolveApprovalRecipients, which uses the per-accountcontact_email(e.g. the Archera contact) as primarytowithnotification_emailonly on Cc. Meanwhile, Purchase History'sresolvePendingApproverEmailreadsglobalCfg.NotificationEmaildirectly. The two paths diverged whenever a per-accountcontact_emailwas set.Fix
Added
approvalResponseRecipienthelper; changedresponseRecipientto preferglobalNotify(the Admin-set notification_email) over the per-accountto. Toast and Purchase History now read the same identity.Test plan
TestHandler_sendPurchaseApprovalEmail_ResponseRecipientUsesNotificationEmailTestHandler_sendPurchaseApprovalEmail_ResponseRecipientFallsBackToContactEmailpurchase-execution-toast.test.ts2 new#735testsgocyclo -over 10: zero violationsSummary by CodeRabbit
New Features
Tests