Repository navigation
Align Cancel payment gate with the pay gate for paid-elsewhere reports - #98082
Beamanator merged 13 commits into
Conversation
cancelPayment guessed the post-cancel state from policy.approvalMode alone, always landing on APPROVED. That is wrong for reports paid from Outstanding (instant submit without approvals, or payments-disabled workspaces) and cannot distinguish an instant-submit report (should return to Outstanding) from a delayed-submit report auto-closed to Done via SUBMITTED_AND_CLOSED (should return to Done). Derive the pre-payment state from the report's own action history instead: find the last workflow action before the latest PAY action and map it back to the state the report was in. Falls back to the policy-based guess when there is no action history.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db69435cdc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…TTED action A submit-and-close report (approvals and payments off) auto-closes to Done on submit, but its optimistic action is a plain SUBMITTED action — the server reconciles it to SUBMITTED_AND_CLOSED later. Paying and cancelling in that window (offline or slow API) previously reverted the report to Outstanding because the SUBMITTED action was read as an instant-submit. Distinguish the two by the policy's own close behavior (payments disabled -> Done).
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0d6352e5da
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…orkflow cancelPayment distinguished a submit-and-close report (auto-closed to Done) from an instant-submit report (Outstanding) by the policy's reimbursementChoice via arePaymentsEnabled. That misfires on a submit-and-close workspace that has payments enabled: submitReport still closes such a report to Done and stamps its optimistic SUBMITTED action with originalMessage.workflow = OPTIONAL, but the payments check flipped it back to Outstanding on cancel. Read the workflow off the SUBMITTED action instead, matching how submitReport decides the state. This anchors the report to Done regardless of payments and no longer depends on reimbursementChoice.
|
@shubham1206agra Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ab4b2c7de
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
The optimistic revert can now move the report's stateNum away from APPROVED (e.g. to SUBMITTED when reverting to Outstanding), but the cancelPayment failureData only restored statusNum to REIMBURSED. On a failed or rolled-back CancelPayment that left the paid report in a mixed SUBMITTED/REIMBURSED state. Restore stateNum to the report's pre-cancel value in the failure update so a rollback returns it to the paid APPROVED/REIMBURSED state. Added a regression test that fails the request after an Outstanding revert.
|
@dilshodmackbook-sketch I believe this PR is not complete. Please double check |
|
@dilshodmackbook-sketch Also, test this PR on actual env, not the simulated ideal state. |
…admins isCancelPaymentAction gated on isPayer, which on a manual-reimbursement workspace narrows to the single designated reimburser. But the pay gate (canIOUBePaid / isPayer with onlyShowPayElsewhere semantics) admits any admin with WORKFLOWS_PAYMENTS write access, so a non-reimburser admin could mark a report paid yet was blocked from cancelling it — the two gates disagreed. Admit that same admin in the cancel gate: keep the admin check, then allow the designated reimburser OR (manual reimbursement AND WORKFLOWS_PAYMENTS write access). This completes the gating half of the issue alongside the revert-state change; without it Cancel payment never surfaces for those admins.
The cancel gate kept an isAdmin guard, but the pay gate (canIOUBePaid) has none: its canPay is isPayer || (manual reimbursement && WORKFLOWS_PAYMENTS write). So a non-admin who could mark the report paid — e.g. a payments admin, or a non-admin designated reimburser — was blocked from cancelling, re-introducing the same pay/cancel asymmetry this change set out to fix. Gate cancel on the exact canPay predicate instead, with no separate admin check. Added a test for a non-admin payments admin.
|
@shubham1206agra ready to review |
|
@dilshodmackbook-sketch Again, test this PR on actual env, not the simulated ideal state. Also, please show the entire browser in screenshot/video please |
|
@shubham1206agra I re-recorded the web flow on dev.new.expensify.com with the whole browser in frame — updated in the MacOS: Chrome / Safari section, one online and one offline. Mark as paid then Cancel payment reverts the report to its pre-payment state on the real env. Please take another look. The fix is pure JS with no native changes, so iOS native behaves identically and is covered by the web and mWeb recordings. |
trjExpensify
left a comment
There was a problem hiding this comment.
Agreed product change 👍
|
Let's put this PR on hold on #97556 (comment) |
Policies always load on OpenApp and nothing is allowed on a deleted policy, so the unresolvable-policy fallback the guard blocked can't happen in practice. Retarget the manager negative test at a real paid-group policy and trim the verbose comments.
|
@shubham1206agra friendly bump on this one. All the review comments from last week are addressed and pushed, the extra |
|
@dilshodmackbook-sketch Can you please test all the scenarios stated here #98082 (review) and send the screenshot as a comment for one platform only? |
|
@shubham1206agra Ran the full matrix from your review on web (Chrome). Screenshots are grouped below — the "More" menu is open on a paid-elsewhere expense report in each case, so you can see directly whether Cancel payment is offered. Every case matches the expected result.
B3 confirms the widening doesn't leak to Direct workspaces, and B4 stays hidden without needing the paid-group-policy guard. C1/C2 confirm bank eligibility follows the latest pay action and its NACHA cutoff. Cancel payment now offered (A1, A2, A3, C1)
Cancel payment stays hidden (B1, B2, B3, B4, C2)
A few notes on the rest of the list:
No JS console errors in any case. |
f9cc28b to
06dae9b
Compare
…yment-revert-state
Upstream removed the isProduction parameter from getSecondaryReportActions/ getSecondaryTransactionThreadActions (now read from the runtime module), so the branch's added test cases no longer type-check when passing isProduction: false.
fb551ec to
2240e58
Compare
|
@shubham1206agra can you review the test results when you get a chance? |
|
Bump @shubham1206agra. This has been waiting on you for a week. |
Reviewer Checklist
Screenshots/VideosScreen.Recording.2026-09-01.at.9.00.11.PM.mov |
|
🚧 Beamanator has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/Beamanator in version: 9.4.66-0 🚀
|
|
🤖 Yes — help site changes were required. Draft docs PR: #100105 This PR widened who is offered Cancel payment (previously workspace admin and payer; now anyone who could mark the report paid). Three help articles described the old, narrower rule. What I changed
How I checked the behavior and the labelsGate the docs now describe, from This matches the pay gate at
Labels verified in the live web UI, not from memory: Cancel payment (report More menu), Mark as paid and Pay with business account (pay dialog), and the Payments section plus Payer row in Workflows. Not documented: the latest-pay-action change (a superseded pay action no longer keeps Cancel payment around after a cancel-and-repay). That is a correctness fix to an internal calculation with no separate user-facing rule to describe. I could not run One thing I couldn't do: GitHub rejected assigning you to #100105 ( @dilshodmackbook-sketch, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR |
|
🚀 Deployed to staging by https://github.com/Beamanator in version: 9.4.68-0 🚀
|
|
🚀 Deployed to production by https://github.com/francoisl in version: 9.4.68-1 🚀
Bundle Size Analysis (Sentry): |
Aligns the help site with the Cancel payment gate change in Expensify#98082. Co-authored-by: Dilshod Bunyodov <dilshodmackbook-sketch@users.noreply.github.com>


Explanation of Change
This fixes the gating defect behind Cancel payment on a manually-paid ("paid elsewhere") report.
Cancel payment didn't surface for every admin/payer who could mark the report paid.
isCancelPaymentActiongated onisAdmin && isPayer. On a manual-reimbursement workspaceisPayernarrows to the single designated reimburser, and the extraisAdminrequirement further excluded non-admin payers. But the pay gate (canIOUBePaid.canPay) admits any payer, or on a manual workspace any member withWORKFLOWS_PAYMENTSwrite access, with no admin requirement. So a non-admin payments admin, or a non-reimburser admin, could mark a report paid yet was blocked from cancelling it — the two gates disagreed.The cancel gate now mirrors
canIOUBePaid.canPayexactly:Whoever could mark the report paid can now cancel it, and no one else.
Fixed Issues
$ #97577
PROPOSAL: #97577 (comment)
Tests
Offline tests
The Cancel payment gate does not depend on connectivity.
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Screen.Recording.2026-08-10.at.12.35.36.mp4
Android: mWeb Chrome
Screen.Recording.2026-08-10.at.12.26.17.mp4
iOS: mWeb Safari
Screen.Recording.2026-08-10.at.12.16.41.mov
MacOS: Chrome / Safari
Screen.Recording.2026-08-10.at.12.08.17.mp4
Screen.Recording.2026-08-10.at.12.38.41.mov