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

[Held] [$250] Invoices - Workspace settings can be opened from "workspace" link when workspace is deleted #49093

Open IuliiaHerets opened 2 months ago

IuliiaHerets commented 2 months 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.33-1 Reproducible in staging?: Y Reproducible in production?: N/A - new feature, doesn't exist in prod Issue was found when executing this PR: https://github.com/Expensify/App/pull/48275 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. {User A] Send an invoice to User B.
  3. [User B] Pay the invoice using Pay as a business option.
  4. [User B] Delete the workspace.
  5. {User B] Go to invoice chat.
  6. [User B] Click on the "workspace" link in Expensify message.

Expected Result:

The link should lead to not here page because workspace is deleted.

Actual Result:

The link can open workspace settings page and Members tab leads to not here page.

Workaround:

Unknown

Platforms:

Screenshots/Videos

https://github.com/user-attachments/assets/a1540862-f566-4c88-b999-caf2bdf3094f

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021834598579747458653
  • Upwork Job ID: 1834598579747458653
  • Last Price Increase: 2024-09-13
  • Automatic offers:
    • ishpaul777 | Contributor | 104008088
    • gijoe0295 | Contributor | 104027162
Issue OwnerCurrent Issue Owner: @ntdiary
melvin-bot[bot] commented 2 months ago

Triggered auto assignment to @joekaufmanexpensify (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 2 months ago

We think that this bug might be related to #vip-bills

iwiznia commented 2 months ago

Removed blocker, see https://expensify.slack.com/archives/C9YU7BX5M/p1726158576447559

melvin-bot[bot] commented 2 months ago

Triggered auto assignment to @srikarparsi (DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.

github-actions[bot] commented 2 months ago

:wave: Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

  1. Identify the pull request that introduced this issue and revert it.
  2. Find someone who can quickly fix the issue.
  3. Fix the issue yourself.
luacmartins commented 2 months ago

@IuliiaHerets I think the uploaded video is incorrect. Can you please check?

IuliiaHerets commented 2 months ago

@luacmartins fixed, sorry for this

luacmartins commented 2 months ago

No problem. Thank you!

luacmartins commented 2 months ago

This is also reproducible in prod if we just copy/paste the workspace link

rlinoz commented 2 months ago

Just by having the workspace link in any chat the problem also happens in prod:

https://github.com/user-attachments/assets/778e2117-0eb4-47b8-9f49-6da855676b88

IuliiaHerets commented 2 months ago

We can't pay the invoice using Pay as a business in prod, so I marked it as N/A - can't check on prod

gijoe0295 commented 2 months ago

Edited by proposal-police: This proposal was edited at 2023-10-06T15:00:00Z.

Proposal

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

The link can open workspace settings page and Members tab leads to not here page.

What is the root cause of that problem?

After deleting the workspace, we still retain some workspace information to show the invoice report's avatars and name:

Screenshot 2024-09-13 at 01 27 59

These information is returned by OpenReport:

Screenshot 2024-09-13 at 01 28 52

The not found page condition here simply checks for empty/delete-pending policy:

https://github.com/Expensify/App/blob/c6ce0f80c52457759ca4e3534c2393b9240aa48d/src/pages/workspace/WorkspacePageWithSections.tsx#L171-L174

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

  1. We can add shouldShowPolicy to the shouldShowNotFoundPage above to filter these workspaces and prevent them from being accessed by URL:

https://github.com/Expensify/App/blob/7748eff72fc43ecaf3db6159928d8d581a63ab99/src/libs/PolicyUtils.ts#L180-L187

This condition is also used in WorkspacesListPage to filter viewable workspace. This solution ensures if a workspace did not appear in the workspaces list, it should not be accessible via direct URL.

https://github.com/Expensify/App/blob/0c37d5b3e3d837deb17f526ed7dff94d8ce36fa4/src/pages/workspace/WorkspacesListPage.tsx#L315

  1. We also need to add the above filter to WorkspaceInitialPage and WorkspaceProfilePage:

https://github.com/Expensify/App/blob/c2257714c5dbf58f3f61883d115496e6728a1dd9/src/pages/workspace/WorkspaceInitialPage.tsx#L310

https://github.com/Expensify/App/blob/1eecd00ad95753d8b6e0ea066fd12be62f56c3aa/src/pages/workspace/WorkspaceProfilePage.tsx#L155

  1. And modify the not found subtitle in those pages as well since they are assuming that only empty policies are deleted:

https://github.com/Expensify/App/blob/c6ce0f80c52457759ca4e3534c2393b9240aa48d/src/pages/workspace/WorkspacePageWithSections.tsx#L190

https://github.com/Expensify/App/blob/c2257714c5dbf58f3f61883d115496e6728a1dd9/src/pages/workspace/WorkspaceInitialPage.tsx#L363

melvin-bot[bot] commented 2 months ago

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

melvin-bot[bot] commented 2 months ago

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

nkdengineer commented 2 months ago

Proposal

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

The link can open the workspace settings page and Members tab leads to not here page.

What is the root cause of that problem?

After the user deletes the workspace, the policy data still exists then the not found page doesn't display because this check doesn't cover full case like we did here

https://github.com/Expensify/App/blob/14b5ccc38534683a4d96460ee5266732a65f3b0a/src/pages/workspace/WorkspacePageWithSections.tsx#L164-L170

Screenshot 2024-09-16 at 11 05 10

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

We should use the same check as we did here in shouldShow here then that can fix for all policy pages

const shouldShowPolicy = useMemo(() => {
    return PolicyUtils.shouldShowPolicy(policy, isOffline, session?.email);
}, [policy, isOffline, session?.email]);

const prevShouldShowPolicy = useMemo(() => {
    return PolicyUtils.shouldShowPolicy(prevPolicy, isOffline, session?.email);
}, [prevPolicy, isOffline, session?.email]);

const shouldShow = useMemo(() => {
    // If the policy object doesn't exist or contains only error data, we shouldn't display it.
    if (((isEmptyObject(policy) || (Object.keys(policy).length === 1 && !isEmptyObject(policy.errors))) && isEmptyObject(policyDraft)) || shouldShowNotFoundPage) {
        return true;
    }

    // We check isPendingDelete for both policy and prevPolicy to prevent the NotFound view from showing right after we delete the workspace
    return (!isEmptyObject(policy) && !PolicyUtils.isPolicyAdmin(policy) && !shouldShowNonAdmin) || (!shouldShowPolicy && !prevShouldShowPolicy);
    // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [policy, shouldShowNonAdmin, shouldShowPolicy, prevShouldShowPolicy]);

https://github.com/Expensify/App/blob/14b5ccc38534683a4d96460ee5266732a65f3b0a/src/pages/workspace/WorkspacePageWithSections.tsx#L164-L170

Then we can update the condition here like this to display the correct subtitle

shouldShowPolicy ?  'workspace.common.notAuthorized' : undefined

https://github.com/Expensify/App/blob/b69577a55bc536a411d8c1e51fc47fc0fc00d389/src/pages/workspace/WorkspacePageWithSections.tsx#L190

We can do the same fix for WorkspaceInitialPage https://github.com/Expensify/App/blob/b69577a55bc536a411d8c1e51fc47fc0fc00d389/src/pages/workspace/WorkspaceInitialPage.tsx#L310

What alternative solutions did you explore? (Optional)

We can fix this from BE side that will not return the data of deleted policy

joekaufmanexpensify commented 2 months ago

Pending review of proposal

melvin-bot[bot] commented 2 months ago

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

joekaufmanexpensify commented 2 months ago

@ntdiary can you review proposals here?

ntdiary commented 2 months ago

@ntdiary can you review proposals here?

Ah, @joekaufmanexpensify, sorry, under review. I missed this issue. πŸ˜…

allgandalf commented 2 months ago

Taking over this issue (slack), can you please assign me here @joekaufmanexpensify @srikarparsi

joekaufmanexpensify commented 2 months ago

We ended up rolling the dice for this one since there was a lot of interest, and @ishpaul777 was selected, so going with them!

melvin-bot[bot] commented 2 months ago

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

joekaufmanexpensify commented 2 months ago

Pending @ishpaul777 review of proposals

ishpaul777 commented 2 months ago

Looking πŸ‘€

ishpaul777 commented 2 months ago

@nkdengineer I dont understand the usage for prevShouldShowPolicy in your proposal could you clarify the usage please ?

nkdengineer commented 2 months ago

PolicyUtils.isPendingDeletePolicy(policy) && PolicyUtils.isPendingDeletePolicy(prevPolicy)

@ishpaul777 Here is the old condition and we should replace it with shouldShowPolicy function. That is why we have prevShouldShowPolicy variable. I create a new variable because we need to use shouldShowPolicy to display the correct subtitle.

subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}

ishpaul777 commented 2 months ago

Thanks for clarifying @nkdengineer. πŸ‘


I dont think there are any major difference between @nkdengineer solution and @gijoe0295's solution, since @gijoe0295 Proposed this first lets assign them

πŸŽ€ πŸ‘€ πŸŽ€ C+ reviewed

melvin-bot[bot] commented 2 months ago

Current assignee @srikarparsi is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.

melvin-bot[bot] commented 2 months ago

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

joekaufmanexpensify commented 2 months ago

@gijoe0295 is there an ETA for PR here?

gijoe0295 commented 2 months ago

Will complete in 5 hours.

joekaufmanexpensify commented 1 month ago

PR in review

joekaufmanexpensify commented 1 month ago

PR still in review

ishpaul777 commented 1 month ago

Still in review, found a bug that is taking sometime to fix, @gijoe0295 is still looking into it

joekaufmanexpensify commented 1 month ago

Sounds good!

joekaufmanexpensify commented 1 month ago

PR still in review

joekaufmanexpensify commented 4 weeks ago

This one's now held for https://github.com/Expensify/react-native-onyx/pull/588 , we'll finish up the PR once that's out.

joekaufmanexpensify commented 2 weeks ago

@ishpaul777 @srikarparsi I see the above PR was merged and published. Can we take this off hold now?

ishpaul777 commented 2 weeks ago

yeah i have asked @gijoe0295 to retest and confirm few days back https://github.com/Expensify/App/pull/49509#issuecomment-2450831699

joekaufmanexpensify commented 2 weeks ago

Great. TY!

gijoe0295 commented 1 week ago

Will retest today.

joekaufmanexpensify commented 1 week ago

@gijoe0295 Did you have a chance to do this?

ishpaul777 commented 1 week ago

@gijoe0295 has asked some help from @fabioh8010, the investigation in ongoing https://github.com/Expensify/App/pull/49509

joekaufmanexpensify commented 3 hours ago

Sounds good. TY!