App icon indicating copy to clipboard operation
App copied to clipboard

[HOLD for payment 2024-12-16] [$250] Web - Header - Approve button appears briefly when it shouldn't

Open IuliiaHerets opened this issue 1 year ago β€’ 20 comments

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:

  1. Go to https://staging.new.expensify.com/
  2. As an admin, create a new workspace and add User A along with another user.
  3. Go to the more features and enable workflow and rules
  4. Navigate to the "Workflows" and add an approval workflow where User A is assigned as both the submitter and approver.
  5. Go to the "Rules" section and enable "Prevent Self Approval."
  6. Log in as User A, go to the workspace chat, and create an expense.
  7. Open the expense preview and observe that the submit button is disabled.
  8. Switch to the admin account and go to the "Workflows" section to change the approver from User A to the other user.
  9. 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

View all open jobs on GitHub

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 OwnerCurrent Issue Owner: @jliexpensify

IuliiaHerets avatar Nov 16 '24 19:11 IuliiaHerets

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.

melvin-bot[bot] avatar Nov 16 '24 19:11 melvin-bot[bot]

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 managerID value 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 canApproveIOU function 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

NJ-2020 avatar Nov 17 '24 08:11 NJ-2020

I can reproduce this one, I think it'll be a #quality issue?

jliexpensify avatar Nov 17 '24 21:11 jliexpensify

Job added to Upwork: https://www.upwork.com/jobs/~021858267603397515787

melvin-bot[bot] avatar Nov 17 '24 21:11 melvin-bot[bot]

Triggered auto assignment to Contributor-plus team member for initial proposal review - @DylanDylann (External)

melvin-bot[bot] avatar Nov 17 '24 21:11 melvin-bot[bot]

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 managerID of the expense report to user 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 still user A's accountID.

  • As a result, when user A calls submitReport, we change the expense report's stateNum and statusNum:

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?

    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 still user 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 avatar Nov 18 '24 06:11 daledah

@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 avatar Nov 21 '24 03:11 DylanDylann

@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

daledah avatar Nov 21 '24 03:11 daledah

@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

DylanDylann avatar Nov 21 '24 03:11 DylanDylann

Triggered auto assignment to @francoisl, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

melvin-bot[bot] avatar Nov 21 '24 03:11 melvin-bot[bot]

πŸ“£ @DylanDylann πŸŽ‰ An offer has been automatically sent to your Upwork account for the Reviewer role πŸŽ‰ Thanks for contributing to the Expensify app!

Offer link Upwork job

melvin-bot[bot] avatar Nov 21 '24 06:11 melvin-bot[bot]

πŸ“£ @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 πŸ“–

melvin-bot[bot] avatar Nov 21 '24 06:11 melvin-bot[bot]

@francoisl, @jliexpensify, @DylanDylann, @daledah Eep! 4 days overdue now. Issues have feelings too...

melvin-bot[bot] avatar Nov 26 '24 09:11 melvin-bot[bot]

@daledah Could you give an ETA?

DylanDylann avatar Nov 26 '24 09:11 DylanDylann

@DylanDylann I'll open the PR in a couple hours.

daledah avatar Nov 26 '24 09:11 daledah

@DylanDylann PR is ready.

daledah avatar Nov 26 '24 16:11 daledah

Reviewing label has been removed, please complete the "BugZero Checklist".

melvin-bot[bot] avatar Dec 09 '24 16:12 melvin-bot[bot]

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:

melvin-bot[bot] avatar Dec 09 '24 16:12 melvin-bot[bot]

@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]

melvin-bot[bot] avatar Dec 09 '24 16:12 melvin-bot[bot]

Payment Summary

  • C: @daledah $250 (to be paid via Upworks)
  • C+: @DylanDylann $250 (to be paid via Upworks)

Upwork job

jliexpensify avatar Dec 09 '24 22:12 jliexpensify

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:

  1. User A go to the WS chat, and create an expense.
  2. Open the expense preview and observe that the submit button is disabled.
  3. Switch to the admin account and go to the "Workflows" section to change the approver from User A to the other user.
  4. Return to User A's account, observe that the submit button is now enabled, and click on it.
  5. Verify that: Approve button does not appear

Do we agree πŸ‘ or πŸ‘Ž

DylanDylann avatar Dec 10 '24 03:12 DylanDylann

Paid and job closed!

jliexpensify avatar Dec 16 '24 10:12 jliexpensify