Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.56k stars 2.9k forks source link

[$250] Category rule - Approver field is not empty after the approver is removed from the workspace #49574

Open IuliiaHerets opened 1 month ago

IuliiaHerets commented 1 month ago

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.39-0 Reproducible in staging?: Y Reproducible in production?: Y Email or phone of affected tester (no customers): applausetester+kh010901@applause.expensifail.com Issue reported by: Applause Internal Team

Action Performed:

Precondition:

  1. Go to staging.new.expensify.com
  2. Go to workspace settings > Categories..
  3. Click on any category.
  4. Click Approver.
  5. Select a member as the approver.
  6. Go to Members.
  7. Remove the member from the workspace.
  8. Go back to the category rule of the category in Step 3.

Expected Result:

Approver field will be empty because the approver is no longer a workspace member.

Actual Result:

Approver field still shows the removed member when the approver is no longer a workspace member.

Workaround:

Unknown

Platforms:

Screenshots/Videos

https://github.com/user-attachments/assets/d169ef74-d918-435d-832f-8fe111f02d22

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021854279355604338561
  • Upwork Job ID: 1854279355604338561
  • Last Price Increase: 2024-11-13
Issue OwnerCurrent Issue Owner: @mollfpr
melvin-bot[bot] commented 1 month ago

Triggered auto assignment to @mallenexpensify (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.

IuliiaHerets commented 1 month ago

We think that this bug might be related to #wave-control

IuliiaHerets commented 1 month ago

@mallenexpensify FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

abzokhattab commented 1 month ago

Edited by proposal-police: This proposal was edited at 2024-09-22 11:52:04 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

The approver field is not empty after the approver is removed from the workspace.

What is the root cause of that problem?

We don't reset the approval rule to be empty after deleting a member.

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

Since we retrieve the category rule in the getCategoryApproverRule function, we can reset the rule.approver property to null if the employee is found to be deleted from the policy's employee list.

To achieve this, we need to add the policyEmployeeList as an additional argument to the getCategoryApproverRule function. We then use the employee list to check if the approver has been removed:

function getCategoryApproverRule(approvalRules: ApprovalRule[], categoryName: string, policyEmployeeList?: Policy['employeeList']) {
    const approverRule = approvalRules?.find((rule) =>
        rule.applyWhen.find(({condition, field, value}) => condition === CONST.POLICY.RULE_CONDITIONS.MATCHES && field === CONST.POLICY.FIELDS.CATEGORY && value === categoryName),
    );

    if (!approverRule) {
        return null;
    }

    if (policyEmployeeList) {
        const approverPolicyMember = approverRule.approver ? policyEmployeeList?.[approverRule.approver] : null;
        if (!approverPolicyMember || approverPolicyMember?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
            approverRule.approver = '';
        }
    }
    return approverRule;
}

Next, we need to add the policy.employeeList as an argument here: https://github.com/Expensify/App/blob/2fdea8246269e9c1cc6b9ccf2a349fc6aa31d83e/src/pages/workspace/categories/CategorySettingsPage.tsx#L80

optional: if we want to reset the rule completely in this case, we can return null instead of resetting the approverRule.approver in this case. here is the sudo code for the updated code:

    return approvalRules?.find((rule) =>
        rule.applyWhen.find(({condition, field, value}) => condition === CONST.POLICY.RULE_CONDITIONS.MATCHES && field === CONST.POLICY.FIELDS.CATEGORY && value === categoryName) && 
    (!policyEmployeeList || rule.approver == null || policyEmployeeList[rule.approver]?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)
    )

POC

https://github.com/user-attachments/assets/903f05ed-7ed5-4e36-97ee-8f8152a9abdf

What alternative solutions did you explore? (Optional)

Another solution is to implement both frontend and backend changes when removing a member from a workspace:

  1. In the remove member request (DeleteMembersFromWorkspace), the backend should also check if this member is used as an approver in any rules and reset the rule value accordingly.
  2. In the frontend, we should set the rule and set the pending fields in the optimisticData, successData, and failureData of the delete member request (DeleteMembersFromWorkspace), ensuring we also handle the offline environment properly. PS: the rule info could be fetched from the policy and we can find the approval rule after looping though the rules object (rules.approvalRules) and check if the approver is used in any of them.
mallenexpensify commented 1 month ago

Checking with Tom about quick

melvin-bot[bot] commented 1 month ago

@mallenexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

mallenexpensify commented 1 month ago

Posted and bumped in #wave-control room https://expensify.slack.com/archives/C06ML6X0W9L/p1727482508265999?thread_ts=1727123059.243429&cid=C06ML6X0W9L

mallenexpensify commented 1 month ago

Per Dylan, Put on hold pending the beta being built for it

mallenexpensify commented 1 month ago

On hold

mallenexpensify commented 2 weeks ago

Off hold, the below was closed

Bumped to Daily, will test soon.

MelvinBot commented 2 weeks ago

This has been labelled "Needs Reproduction". Follow the steps here: https://stackoverflowteams.com/c/expensify/questions/16989

melvin-bot[bot] commented 2 weeks ago

@mallenexpensify Huh... This is 4 days overdue. Who can take care of this?

melvin-bot[bot] commented 1 week ago

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

melvin-bot[bot] commented 1 week ago

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

mallenexpensify commented 1 week ago

Was able to reproduce

SnagitHelper2024 2024-11-06 13 45 44

and

SnagitHelper2024 2024-11-06 13 46 16

@mollfpr, can you review the proposal above? Thx

melvin-bot[bot] commented 1 week ago

Triggered auto assignment to @zanyrenney (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.

mallenexpensify commented 1 week ago

@zanyrenney I'm off the next week, can you please keep an eye on this issue til I'm back? Thx

melvin-bot[bot] commented 1 week ago

@mallenexpensify, @mollfpr, @zanyrenney Eep! 4 days overdue now. Issues have feelings too...

melvin-bot[bot] commented 5 days ago

๐Ÿ“ฃ It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? ๐Ÿ’ธ

zanyrenney commented 5 days ago

Sure thing @mallenexpensify !

zanyrenney commented 5 days ago

Seeing as @mallenexpensify successfully reproduced this, I am removing the label.

zanyrenney commented 5 days ago

bumping @mollfpr to review the proposal above.

melvin-bot[bot] commented 4 days ago

@mallenexpensify, @mollfpr, @zanyrenney Still overdue 6 days?! Let's take care of this!

mollfpr commented 4 days ago

We don't reset the approval rule to be empty after deleting a member.

@abzokhattab I agree with RCA, but why is the solution not related to resetting the rules?

abzokhattab commented 1 day ago

Updated the proposal to include an additional point on resetting the rule in case the approval status is changed.

melvin-bot[bot] commented 23 hours ago

@mallenexpensify, @mollfpr, @zanyrenney Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

mallenexpensify commented 8 hours ago

@mollfpr , ๐Ÿ‘€ above plz. Thanks for watching over Zany, I'm back!

mollfpr commented 5 hours ago

We don't reset the approval rule to be empty after deleting a member.

@abzokhattab, I'm still not onboard with the solution. The root cause is in our BE response not updating the policy rules.approvalRules after removing the member. So I think the proper solution is:

  1. BE: Fixing the API DeleteMembersFromWorkspace response to have the rules.approvalRules updated with the employee list
  2. FE: Follow up with the same approach for the OFFLINE

That's it, no need to update getCategoryApproverRule since we got the correct data for rules.approvalRules.

abzokhattab commented 51 minutes ago

Thanks @mollfpr for your feedback.

I think i have referred to this approach in the alternative proposal but i have just added more details to it to be more concrete.

please review the alternative proposal and let me know what you think.

mollfpr commented 15 minutes ago

Ohyeah, you already have that in the alternative solution my bad ๐Ÿ™

The alternative solution looks good to me and it's pretty much the same as the strategy I suggest. I think we can move forward from here and discuss the BE changes with the selected engineer.

๐ŸŽ€ ๐Ÿ‘€ ๐ŸŽ€ C+ reviewed!