Skip to content

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

Closed

Description

@IuliiaHerets

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com 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): biruknew45+2101@gmail.com
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

Activity

  1. added
    Daily
    Bug
    on Nov 16, 2024
  2. melvin-bot commented on Nov 16, 2024

    @melvin-bot

    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.

  3. NJ-2020 commented on Nov 17, 2024

    @NJ-2020
    Contributor

    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);

  4. jliexpensify commented on Nov 17, 2024

    @jliexpensify
    Contributor

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

  5. added
    External
    on Nov 17, 2024
  6. changed the title [-]Web - Header - Approve button appears briefly when it shouldn't[/-] [+][$250] Web - Header - Approve button appears briefly when it shouldn't[/+] on Nov 17, 2024
  7. melvin-bot commented on Nov 17, 2024

    @melvin-bot
  8. added
    Help Wanted
    on Nov 17, 2024
  9. melvin-bot commented on Nov 17, 2024

    @melvin-bot

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

  10. daledah commented on Nov 18, 2024

    @daledah
    Contributor

    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

  11. DylanDylann commented on Nov 21, 2024

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

  12. 18 remaining items

  13. added
    Weekly
    Awaiting Payment
    and removed
    Weekly
    on Dec 9, 2024
  14. 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[/+] on Dec 9, 2024
  15. removed
    Reviewing
    on Dec 9, 2024
  16. melvin-bot commented on Dec 9, 2024

    @melvin-bot

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

  17. melvin-bot commented on Dec 9, 2024

    @melvin-bot

    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:

  18. melvin-bot commented on Dec 9, 2024

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

  19. jliexpensify commented on Dec 9, 2024

    @jliexpensify
    Contributor

    Payment Summary

    Upwork job

  20. DylanDylann commented on Dec 10, 2024

    @DylanDylann
    Contributor

    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 👎

  21. added
    Daily
    and removed
    Weekly
    on Dec 16, 2024
  22. jliexpensify commented on Dec 16, 2024

    @jliexpensify
    Contributor

    Paid and job closed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions