Repository navigation
Fix report submission failure when submitsTo points to a removed policy member - #98398
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fa1cbe200c
ℹ️ 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".
| // submitsTo can go stale and point at someone who is no longer a policy member (e.g. the configured approver was removed). | ||
| // The Workflows UI already ignores such approvers (see convertPolicyEmployeesToApprovalWorkflows), so fall back to the | ||
| // default approver to keep the submit destination consistent with what the UI displays. | ||
| if (submitsTo && policy?.employeeList?.[submitsTo]) { |
There was a problem hiding this comment.
Preserve HR-provided external managers
In HR advanced (manager) mode, submitsTo can intentionally name an HR-synced manager who is not in policy.employeeList; the workflow conversion path preserves that case when an HR final approver is configured (see tests/unit/WorkflowUtilsTest.ts:781-831). This membership guard now treats those valid external managers as stale and makes getSubmitToEmail/getSubmitToAccountID/getApprovalChain fall back to the workspace owner/default approver, so reports from HR-managed employees are submitted to the wrong approver instead of the manager supplied by the HR integration.
Useful? React with 👍 / 👎.
…cy member Only the submit path now ignores a submitsTo approver who is no longer a policy member: getSubmitReportManagerAccountID resolves the approver via getSubmittableApproverAccountID, which falls back to the default approver so SubmitReport is not called with a non-member managerAccountID. getManagerAccountEmail and getSubmitToAccountID keep returning the raw value because they also answer "who is this report with" — for example isAwaitingFirstLevelApproval compares it against report.managerID, so guarding them would hide Delete on reports already sitting with a removed approver. HR advanced (manager) mode is exempt, mirroring the HR check in convertPolicyEmployeesToApprovalWorkflows, so an HR-synced external manager is still honored. Expensify#94891
fa1cbe2 to
399946a
Compare
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
I’ll take a look at this pr tomorrow. |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppCleanShot.2026-08-20.at.17.17.15.4.mp4Android: mWeb ChromeiOS: HybridAppCleanShot.2026-08-16.at.14.14.46.2.mp4iOS: mWeb SafariCleanShot.2026-08-20.at.17.17.15.4.mp4MacOS: Chrome / SafariCleanShot.2026-08-16.at.14.14.46.2.mp4 |
|
@Abdulloh0109 Your changeset differs from the originally selected proposal. If you need to update your changes based on the Codex review, please never force push as the guideline in the future |
|
Sorry about the force push, that one's on me. Future updates will be new commits. On the deviation: the proposal had the guard in getManagerAccountEmail, but that placement broke two things. Codex was right about HR mode. convertPolicyEmployeesToApprovalWorkflows only ignores a non-member submitsTo when there is no HR final approver (WorkflowUtils.ts#L191), and I had dropped that condition, so HR-synced managers would have been rerouted. Same exemption is in place now. The bigger one: guarding the shared resolver broke 4 tests in NextStepUtilsTest and ReportSecondaryActionUtilsTest, and it wasn't just fixtures. getSubmitToAccountID also answers "who is this report with" — isAwaitingFirstLevelApproval compares it against report.managerID — so a report already sitting with an approver who was removed later would lose Delete for its owner. So the fallback now sits in getSubmittableApproverAccountID, used only by getSubmitReportManagerAccountID (callers: submitReport and Search's submit). Everything else keeps the raw value. Same result for the bug, narrower blast radius. Happy to move it back if you prefer the original placement. You're right on the screenshots and platforms. Re-recording the flow to match the test steps and adding the missing ones. |
|
@suneox I hit a problem while re-recording the flow and could use your input. I set up a Control workspace against the production API, switched Approvals to Advanced, and added a workflow where User B submits to User A. When I then remove User A, the app reassigns the approver instead of leaving it stale. The confirmation dialog even says so:
After removing, User B's So the steps in the PR can't produce the stale state on current main, which means I can't record a video that both matches them and shows the fix doing anything. How did you get into it in July? Was it a different removal path, OldDot, or an older build? If there's no reproducible path left, I'd rather rewrite the test steps to describe a workspace that already has the stale |
@Abdulloh0109 You need to update the test steps to accurately reflect your screen recording. We can't provide QA steps that they are unable to verify. |
|
Updated the test steps to match the recording, and left QA steps they can actually run (the stale state can't be created through the product). Happy to mark it [No QA] instead if you prefer. |
|
Updated the test steps to match the recording, and left QA steps they can actually run (the stale state can't be created through the product). Happy to mark it One question on platforms: this state can only be reproduced by seeding Onyx from the browser console, which isn't available in the native apps. The change itself is a plain util in |
|
@Abdulloh0109 The screenshot doesn't match the test steps yet, and please remove the redundant steps.
Keep in mind that |
|
@suneox All addressed:
Ready for another look whenever you have a chance. |
| // `submitsTo` can go stale and name someone who is no longer a policy member (e.g. the approver was removed from the | ||
| // workspace). Only the callers that actually route a submission opt into this fallback — the raw value still answers | ||
| // "who is this report with" elsewhere (see isAwaitingFirstLevelApproval). HR advanced (manager) mode is exempt | ||
| // because it intentionally routes to an HR-synced manager who is not part of `employeeList`. |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Done — simplified to the suggested wording.
| /** | ||
| * Returns the accountID the report can actually be submitted to. Unlike `getSubmitToAccountID`, a `submitsTo` approver | ||
| * who is no longer a policy member is replaced by the default approver, because SubmitReport rejects a non-member | ||
| * approver with UserNotAMember — the same membership check `convertPolicyEmployeesToApprovalWorkflows` already applies | ||
| * when the Workflows page decides which approver to display for that member. | ||
| */ |
There was a problem hiding this comment.
@Abdulloh0109 Same above keep the comment accurate/simple.
There was a problem hiding this comment.
Done — removed getSubmittableApproverAccountID entirely and moved the fallback flag onto getSubmitToAccountID instead (see the next comment). getSubmitReportManagerAccountID now calls getSubmitToAccountID(policy, expenseReport, submitterLogin, true).
| const approvalRules = policy?.rules?.approvalRules; | ||
| const ruleApprover = !isSubmitAndClose(policy) && approvalRules?.length ? getFirstRuleApprover(approvalRules, expenseReport, submitterLogin) : ''; | ||
| const submitToAccountID = getSubmitToAccountID(policy, expenseReport, submitterLogin); | ||
| const submitToAccountID = getSubmittableApproverAccountID(policy, expenseReport, submitterLogin); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Done — applied exactly this, and dropped the now-redundant getSubmittableApproverAccountID wrapper.
Drop the getSubmittableApproverAccountID wrapper and add the membership-fallback flag directly to getSubmitToAccountID instead, mirroring the parameter already on getSubmitToEmail. Also trims the explanatory comments down to their essential purpose, per suneox's review feedback on PR Expensify#98398.
suneox
left a comment
There was a problem hiding this comment.
The current change just adds a check for employeeList existence to return the default approver. LGTM
|
🚧 yuwenmemon has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/yuwenmemon in version: 9.4.58-0 🚀
|
Help site review: no changes requiredI reviewed this PR against Why: This is a purely internal approval-routing fix in Crucially, the help site already documents the behavior this PR makes correct.
The submit-time fallback added here aligns the actual submit routing with that documented "reassign to the workspace owner" behavior. There's no new or changed user-facing behavior to describe, so the articles remain accurate as-is. Since no help site changes were required, there is no linked help site PR to review. |
|
🚀 Deployed to production by https://github.com/Beamanator in version: 9.4.58-4 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
An employee's
submitsTocan go stale and point at someone who is no longer a member of the policy (e.g. the configured approver was removed from the workspace). The two sides of the app read that same value differently:convertPolicyEmployeesToApprovalWorkflowsskips any member whosesubmitsTodoesn't resolve to a current policy member, so the member is displayed under the default approver instead.getManagerAccountEmailreturned the rawsubmitsTo, which flows throughgetSubmitToEmail→getSubmitToAccountID→submitReportand is sent toSubmitReportasmanagerAccountID.The result is exactly what the issue reports: NewDot displays the correct approver, but submitting sends an approver that is not a member of the policy, and the backend rejects it with
Expensify\Error\Policy\UserNotAMember.This PR applies the same membership guard the display path already uses to
getManagerAccountEmail:submitsTois only returned when it still resolves to an entry inpolicy.employeeList; otherwise it falls back to the default approver. Fixing it in the resolver covers every caller of the submit chain in one place (getManagerAccountID,getSubmitToEmail,getSubmitToAccountID,getApprovalChain).Behavior that is intentionally unchanged:
submitsTois a valid member — the guard only triggers for approvers that no longer exist.getSubmitToEmailresolves those before falling back to the manager.A unit test was added covering the stale-
submitsTocase.Fixed Issues
$ #94891
PROPOSAL: #94891 (comment)
Tests
The stale state this PR guards against cannot be produced through the UI: removing an approver reassigns the workflow to the workspace owner ("we'll replace them in the approval workflow with … the workspace owner"), so
submitsTonever ends up pointing at a non-member that way. The steps below seed that state locally and reproduce exactly what the recording shows.npm run webon this branch, then open https://dev.new.expensify.com:8082/ (desktop, or mWeb via remote debugging) and paste the snippet below into the browser console.Seed snippet
Offline tests
The snippet in the tests above forces offline mode, so what the recording shows is the optimistic result: the report moves to Outstanding and the next step names the default approver rather than the removed one. Behaviour is identical online — the same accountID is what gets sent to
SubmitReport.QA Steps
The scenario this PR fixes cannot be created through the product: removing an approver reassigns the workflow to the workspace owner, so QA cannot put a workspace into the stale state. What QA can verify is that normal approval routing is unchanged:
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
Chrome
0ff3d116-8956-4700-9be7-d75e4b5faabb.mp4
Safari
REC-20260818222631.mp4
iOS: mWeb Safari
ios.mp4
Android: mWeb Chrome
android.mp4