[HOLD for payment 2024-12-16] [$250] Web - Header - Approve button appears briefly when it shouldn't
If you havenβt already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Version Number: 9.0.63-3 Reproducible in staging?: Y Reproducible in production?: Y Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team
Action Performed:
- Go to https://staging.new.expensify.com/
- As an admin, create a new workspace and add User A along with another user.
- Go to the more features and enable workflow and rules
- Navigate to the "Workflows" and add an approval workflow where User A is assigned as both the submitter and approver.
- Go to the "Rules" section and enable "Prevent Self Approval."
- Log in as User A, go to the workspace chat, and create an expense.
- Open the expense preview and observe that the submit button is disabled.
- Switch to the admin account and go to the "Workflows" section to change the approver from User A to the other user.
- Return to User A's account, observe that the submit button is now enabled, and click on it.
Expected Result:
When clicking the submit button, the approve button should not appear at any point.
Actual Result:
When clicking the submit button, the approve button briefly appears.
Workaround:
Unknown
Platforms:
- [ ] Android: Standalone
- [ ] Android: HybridApp
- [ ] Android: mWeb Chrome
- [ ] iOS: Standalone
- [ ] iOS: HybridApp
- [ ] iOS: mWeb Safari
- [x] MacOS: Chrome / Safari
- [ ] MacOS: Desktop
Screenshots/Videos
https://github.com/user-attachments/assets/ba5b35ea-be79-43ce-965d-906abd350313
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~021858267603397515787
- Upwork Job ID: 1858267603397515787
- Last Price Increase: 2024-11-17
- Automatic offers:
- DylanDylann | Reviewer | 105001353
- daledah | Contributor | 105001356
Issue Owner
Current Issue Owner: @jliexpensify
Triggered auto assignment to @jliexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Web - Header - Approve button appears briefly when it shouldn't
What is the root cause of that problem?
For example we have 3 users: A (admin), B, and C
Admin: Add new approval workflow (from B and approval B), the BE will set the managerID for the approval to B because the approval is BE so when other member submit expense the managerID will be user B
Admin: Enable new rule to prevent self-approvals "Prevent self-approvals", it will block us from submit/approve the expense if the expense is from user B
B: Submit new expense and open the expense, the submit button inside report header will be disabled because we enable the "Prevent self-approvals" option inside the Rules page
Admin: Inside the approval workflow, change the approval to another user (C)
B: The submit/approve button become clickable because the approval is not equal to submitter
B: If we go offline mode, then submit the expense the approve button will show because this check return true https://github.com/Expensify/App/blob/9774032c7b9e72c5f8ee0de6adbe843a7efa2c4a/src/libs/actions/IOU.ts#L6739 https://github.com/Expensify/App/blob/9774032c7b9e72c5f8ee0de6adbe843a7efa2c4a/src/libs/actions/IOU.ts#L6757 It's because the expense manager id is equal to the current account id (B), it's because after the admin change the approver inside the approval workflow to another user C, the BE doesn't update the managerID
So if we go online mode the BE returns the correct managerID (user C) because inside the params we pass the correct managerID (user C) https://github.com/Expensify/App/blob/9774032c7b9e72c5f8ee0de6adbe843a7efa2c4a/src/libs/actions/IOU.ts#L7235-L7241 and we can also see inside the report header nextstep message returning the correct approval name because we're getting the approval account id from the policy instead of using the managerID https://github.com/Expensify/App/blob/9774032c7b9e72c5f8ee0de6adbe843a7efa2c4a/src/libs/actions/IOU.ts#L6846-L6860
What changes do you think we should make in order to solve the problem?
There are several options to solve this issue
- Inside report screen for the
managerIDvalue https://github.com/Expensify/App/blob/9774032c7b9e72c5f8ee0de6adbe843a7efa2c4a/src/pages/home/ReportScreen.tsx#L188 we can do the following:
managerID: PolicyUtils.getSubmitToAccountID(policy, expenseReport) ?? reportOnyx?.managerID
- Inside
canApproveIOUfunction we can use the approval account id from the policy instead of using the managerID
const managerID = managerID: PolicyUtils.getSubmitToAccountID(policy, iouReport) ?? iouReport?.managerID ?? -1;
const isCurrentUserManager = managerID === userAccountID;
...
return isCurrentUserManager && !isOpenExpenseReport && !isApproved && !iouSettled && !isArchivedReport && !isTransactionBeingScanned;
- When submitting the expense, we can pass the mangerID from the approval account id from the policy inside the optimistic data
What alternative solutions did you explore? (Optional)
instead of using PolicyUtils.getSubmitToAccountID we can do the similar logic like what we do here
https://github.com/Expensify/App/blob/9774032c7b9e72c5f8ee0de6adbe843a7efa2c4a/src/libs/actions/IOU.ts#L6846-L6860
I can reproduce this one, I think it'll be a #quality issue?
Job added to Upwork: https://www.upwork.com/jobs/~021858267603397515787
Triggered auto assignment to Contributor-plus team member for initial proposal review - @DylanDylann (External)
Edited by proposal-police: This proposal was edited at 2024-11-21 03:23:38 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
When clicking the submit button, the approve button briefly appears.
What is the root cause of that problem?
-
If the approval workflow is set as: User A is assigned as both the submitter and approver. Then when user A submitting an expense, BE will set the
managerIDof the expense report touser A's accountID. -
Then if we change the approval workflow so that the user A is no longer the approver. Here, BE does not update the expense report's
managerID, it is stilluser A's accountID. -
As a result, when user A calls
submitReport, we change the expense report'sstateNumandstatusNum:
https://github.com/Expensify/App/blob/9774032c7b9e72c5f8ee0de6adbe843a7efa2c4a/src/libs/actions/IOU.ts#L7148-L7149
, so the approve button is still displayed optimistically with the disable state because the shouldShowApproveButton:
https://github.com/Expensify/App/blob/9774032c7b9e72c5f8ee0de6adbe843a7efa2c4a/src/components/ReportActionItem/ReportPreview.tsx#L340
is true but shouldDisableApproveButton:
https://github.com/Expensify/App/blob/9774032c7b9e72c5f8ee0de6adbe843a7efa2c4a/src/components/ReportActionItem/ReportPreview.tsx#L342
is false, until the BE returns the correct managerID.
What changes do you think we should make in order to solve the problem?
- In here we should add the optimistic managerID below like we did when approving an expense:
const approvalChain = ReportUtils.getApprovalChain(PolicyUtils.getPolicy(expenseReport?.policyID), expenseReport);
const managerID = isLastApprover(approvalChain) ? expenseReport?.managerID : getNextApproverAccountID(expenseReport);
and then revert the managerID value in failureData.
- The bug I mentioned in RCA section:
Here, BE does not update the expense report's
managerID, it is stilluser A's accountID
should be fixed in BE side as well.
What alternative solutions did you explore? (Optional)
We also can set managerID to approvalChain[0] when submitting reports
@daledah What do you think if we always set the first approver ID to managerID when submitting a report? Another question why do we need to revert the managerID in the failureData?
@DylanDylann I updated my proposal to cover your suggestion
Another question why do we need to revert the managerID in the failureData?
Agree. I will remove it in the PR
@NJ-2020 Thanks for your contribution with detailed RCA. I notice that you suggest 4 solutions with a brief and sketchy explanation for each one. I think we should only propose solutions that you think are the best and give more detail about that.
@daledah's proposal looks good to me
π π π C+ Reviewed
Triggered auto assignment to @francoisl, see https://stackoverflow.com/c/expensify/questions/7972 for more details.
π£ @DylanDylann π An offer has been automatically sent to your Upwork account for the Reviewer role π Thanks for contributing to the Expensify app!
π£ @daledah π An offer has been automatically sent to your Upwork account for the Contributor role π Thanks for contributing to the Expensify app!
Offer link Upwork job Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review π§βπ» Keep in mind: Code of Conduct | Contributing π
@francoisl, @jliexpensify, @DylanDylann, @daledah Eep! 4 days overdue now. Issues have feelings too...
@daledah Could you give an ETA?
@DylanDylann I'll open the PR in a couple hours.
@DylanDylann PR is ready.
Reviewing label has been removed, please complete the "BugZero Checklist".
The solution for this issue has been :rocket: deployed to production :rocket: in version 9.0.72-1 and is now subject to a 7-day regression period :calendar:. Here is the list of pull requests that resolve this issue:
- https://github.com/Expensify/App/pull/53051
If no regressions arise, payment will be issued on 2024-12-16. :confetti_ball:
For reference, here are some details about the assignees on this issue:
- @DylanDylann requires payment automatic offer (Reviewer)
- @daledah requires payment automatic offer (Contributor)
@DylanDylann @jliexpensify @DylanDylann The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]
Payment Summary
- C: @daledah $250 (to be paid via Upworks)
- C+: @DylanDylann $250 (to be paid via Upworks)
BugZero Checklist:
- [x] [Contributor] Classify the bug:
Bug classification
Source of bug:
- [ ] 1a. Result of the original design (eg. a case wasn't considered)
- [x] 1b. Mistake during implementation
- [ ] 1c. Backend bug
- [ ] 1z. Other:
Where bug was reported:
- [x] 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
- [ ] 2b. Reported on staging (eg. found during regression or PR testing)
- [ ] 2d. Reported on a PR
- [ ] 2z. Other:
Who reported the bug:
- [ ] 3a. Expensify user
- [ ] 3b. Expensify employee
- [ ] 3c. Contributor
- [x] 3d. QA
- [ ] 3z. Other:
-
[x] [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to comment: https://github.com/Expensify/App/pull/28947#discussion_r1877243773
-
[ ] [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion:
-
[x] [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
-
[ ] [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue:
Regression Test Proposal
Precondition:
Admin create a WS and add employee A and B Admin enable workflow and rules Go to workflow, add a workflow with use A as both submitter and approver Go to the "Rules" section and enable "Prevent Self Approval."
Test:
- User A go to the WS chat, and create an expense.
- Open the expense preview and observe that the submit button is disabled.
- Switch to the admin account and go to the "Workflows" section to change the approver from User A to the other user.
- Return to User A's account, observe that the submit button is now enabled, and click on it.
- Verify that: Approve button does not appear
Do we agree π or π
Paid and job closed!