Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 8 tasks
IuliiaHerets opened this issue Nov 16, 2024 · 21 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@IuliiaHerets
Copy link

IuliiaHerets commented Nov 16, 2024

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
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6667262_1731770324152.1.mp4

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 IuliiaHerets added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Nov 16, 2024
Copy link

melvin-bot bot commented Nov 16, 2024

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.

@NJ-2020
Copy link
Contributor

NJ-2020 commented Nov 17, 2024

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

const isCurrentUserManager = managerID === userAccountID;

return isCurrentUserManager && !isOpenExpenseReport && !isApproved && !iouSettled && !isArchivedReport && !isTransactionBeingScanned;

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)

App/src/libs/actions/IOU.ts

Lines 7235 to 7241 in 9774032

const parameters: SubmitReportParams = {
reportID: expenseReport.reportID,
managerAccountID: PolicyUtils.getSubmitToAccountID(policy, expenseReport) ?? expenseReport.managerID,
reportActionID: optimisticSubmittedReportAction.reportActionID,
};
API.write(WRITE_COMMANDS.SUBMIT_REPORT, parameters, {optimisticData, successData, failureData});

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

App/src/libs/actions/IOU.ts

Lines 6846 to 6860 in 9774032

function getNextApproverAccountID(report: OnyxEntry<OnyxTypes.Report>) {
const policy = PolicyUtils.getPolicy(report?.policyID);
const approvalChain = ReportUtils.getApprovalChain(policy, report);
const submitToAccountID = PolicyUtils.getSubmitToAccountID(policy, report);
if (approvalChain.length === 0) {
return submitToAccountID;
}
const nextApproverEmail = approvalChain.length === 1 ? approvalChain.at(0) : approvalChain.at(approvalChain.indexOf(currentUserEmail) + 1);
if (!nextApproverEmail) {
return submitToAccountID;
}
return PersonalDetailsUtils.getAccountIDsByLogins([nextApproverEmail]).at(0);

What changes do you think we should make in order to solve the problem?

There are several options to solve this issue

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

App/src/libs/actions/IOU.ts

Lines 6846 to 6860 in 9774032

function getNextApproverAccountID(report: OnyxEntry<OnyxTypes.Report>) {
const policy = PolicyUtils.getPolicy(report?.policyID);
const approvalChain = ReportUtils.getApprovalChain(policy, report);
const submitToAccountID = PolicyUtils.getSubmitToAccountID(policy, report);
if (approvalChain.length === 0) {
return submitToAccountID;
}
const nextApproverEmail = approvalChain.length === 1 ? approvalChain.at(0) : approvalChain.at(approvalChain.indexOf(currentUserEmail) + 1);
if (!nextApproverEmail) {
return submitToAccountID;
}
return PersonalDetailsUtils.getAccountIDsByLogins([nextApproverEmail]).at(0);

@jliexpensify
Copy link
Contributor

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

@jliexpensify jliexpensify added the External Added to denote the issue can be worked on by a contributor label Nov 17, 2024
@melvin-bot melvin-bot bot changed the title Web - Header - Approve button appears briefly when it shouldn't [$250] Web - Header - Approve button appears briefly when it shouldn't Nov 17, 2024
Copy link

melvin-bot bot commented Nov 17, 2024

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 17, 2024
Copy link

melvin-bot bot commented Nov 17, 2024

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

@daledah
Copy link
Contributor

daledah commented Nov 18, 2024

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:

App/src/libs/actions/IOU.ts

Lines 7148 to 7149 in 9774032

stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,

, so the approve button is still displayed optimistically with the disable state because the shouldShowApproveButton:

const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(iouReport, policy), [iouReport, policy]);

is true but shouldDisableApproveButton:

const shouldDisableApproveButton = shouldShowApproveButton && !ReportUtils.isAllowedToApproveExpenseReport(iouReport);

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

@DylanDylann
Copy link
Contributor

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

@daledah
Copy link
Contributor

daledah commented Nov 21, 2024

@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

@DylanDylann
Copy link
Contributor

@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

Copy link

melvin-bot bot commented Nov 21, 2024

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

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 21, 2024
Copy link

melvin-bot bot commented Nov 21, 2024

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

Copy link

melvin-bot bot commented Nov 21, 2024

📣 @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 📖

Copy link

melvin-bot bot commented Nov 26, 2024

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

@melvin-bot melvin-bot bot added the Overdue label Nov 26, 2024
@DylanDylann
Copy link
Contributor

@daledah Could you give an ETA?

@melvin-bot melvin-bot bot removed the Overdue label Nov 26, 2024
@daledah
Copy link
Contributor

daledah commented Nov 26, 2024

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

@melvin-bot melvin-bot bot added the Reviewing Has a PR in review label Nov 26, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 and removed Daily KSv2 labels Nov 26, 2024
@daledah
Copy link
Contributor

daledah commented Nov 26, 2024

@DylanDylann PR is ready.

@muttmuure muttmuure moved this to MEDIUM in [#whatsnext] #quality Nov 29, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Dec 9, 2024
@melvin-bot melvin-bot bot changed the title [$250] Web - Header - Approve button appears briefly when it shouldn't [HOLD for payment 2024-12-16] [$250] Web - Header - Approve button appears briefly when it shouldn't Dec 9, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Dec 9, 2024
Copy link

melvin-bot bot commented Dec 9, 2024

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

Copy link

melvin-bot bot commented Dec 9, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.72-1 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-12-16. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Dec 9, 2024

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

@jliexpensify
Copy link
Contributor

Payment Summary

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

Upwork job

@DylanDylann
Copy link
Contributor

DylanDylann commented Dec 10, 2024

BugZero Checklist:

  • [Contributor] Classify the bug:
Bug classification

Source of bug:

  • 1a. Result of the original design (eg. a case wasn't considered)
  • 1b. Mistake during implementation
  • 1c. Backend bug
  • 1z. Other:

Where bug was reported:

  • 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
  • 3d. QA
  • 3z. Other:
  • [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: [NoQA] Feat: Add submit action #28947 (comment)

  • [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:

  • [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 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
Development

No branches or pull requests

6 participants