Scope bank account Share eligibility to the account's own workspace#93159
Scope bank account Share eligibility to the account's own workspace#93159MelvinBot wants to merge 2 commits into
Conversation
Both hasEligibleActiveAdminFromWorkspaces and getEligibleBankAccountShareRecipients now use getActiveAdminWorkspaces filtered to the bank account's additionalData.policyID, so the Share option and recipient list only consider admins from the workspace that owns the bank account. Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
| const currentBankAccount = getBankAccountFromID(Number(bankAccountID)); | ||
| const activePolicies = getActiveAdminWorkspaces(policies, currentUserLogin); | ||
| const bankAccountPolicyID = currentBankAccount?.accountData?.additionalData?.policyID; | ||
| const activePolicies = getActiveAdminWorkspaces(policies, currentUserLogin).filter((policy) => policy.id === bankAccountPolicyID); |
There was a problem hiding this comment.
@MelvinBot Let's revert the filtering part. We don't want to change that behavior. This PR purpose is just to make both functions work the same way.
There was a problem hiding this comment.
@MelvinBot Let's revert the filtering part. We don't want to change that behavior. This PR purpose is just to make both functions work the same way.
…orkspaces Drop the policyID-based filtering that scoped Share eligibility to the bank account's own workspace. Both functions now consistently use getActiveAdminWorkspaces without changing the recipient-list behavior. Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
|
Reverted the workspace filtering as requested. Pushed to the branch. What changed:
Checks run locally (App, TS changes):
|
TestsSame as QA Steps
Offline testsSame as QA Steps QA StepsPrerequisite:
PR Author Checklist
Screenshots/VideosAndroid: NativeAndroid: mWeb Chromeandroid.mweb.mp4iOS: NativeiOS: mWeb Safariios.mweb.mp4MacOS: Chrome / Safariweb.mp4 |
|
@MelvinBot mark the PR as ready for review |
|
Marked this PR as ready for review. cc |
|
@bernhardoj Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d1bcde9d3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| function hasEligibleActiveAdminFromWorkspaces(policies: OnyxCollection<Policy> | null, currentUserLogin: string | undefined, bankAccountID: string | undefined): boolean { | ||
| const currentBankAccount = getBankAccountFromID(Number(bankAccountID)); | ||
| const activePolicies = getActivePolicies(policies, currentUserLogin); | ||
| const activePolicies = getActiveAdminWorkspaces(policies, currentUserLogin); |
There was a problem hiding this comment.
Scope eligibility to the bank account policy
When the user is an admin on any other active workspace, this still returns true even if the bank account's own workspace has no other eligible admins, because getActiveAdminWorkspaces() is not filtered by currentBankAccount.accountData.additionalData.policyID. In that scenario the Share option remains visible for the account and the share flow can be reached based on unrelated workspaces, which is the case this change is meant to prevent; filter the active admin policies to the bank account's owning policy before checking admins.
Useful? React with 👍 / 👎.
|
We did not find an internal engineer to review this PR, trying to assign a random engineer to #91834 as well as to this PR... Please reach out for help on Slack if no one gets assigned! |
|
@bernhardoj can you resolve the AI reviewer comment? |
|
It's unrelated to this PR as mentioned here |

Explanation of Change
The Share option on a business bank account (and the recipient list on the Share screen) was gated by two functions that iterated over all of the user's workspaces rather than the one that owns the bank account:
hasEligibleActiveAdminFromWorkspaces(controls Share button visibility) usedgetActivePolicies, which returns every policy the user belongs to regardless of role. So joining another user's workspace as a plain member made the Share option appear even when the user's own workspace had no other admin to share with.getEligibleBankAccountShareRecipients(builds the recipient list) usedgetActiveAdminWorkspacesbut was still not scoped to the bank account's workspace, so it could surface admins from unrelated workspaces.Both functions now use
getActiveAdminWorkspacesfiltered to the bank account's own workspace viaaccountData.additionalData.policyID. The Share option only appears when there is another eligible admin in the workspace that owns the bank account, and the recipient list only shows admins from that same workspace — keeping the visibility gate and the recipient list consistent.This implements MelvinBot's proposal.
Fixed Issues
$ #93045
PROPOSAL: #91834 (comment)
Tests
// TODO: The human co-author must fill out the tests you ran before marking this PR as "ready for review"
// Please describe what tests you performed that validates your changed worked.
Automated coverage added in
tests/unit/PolicyUtilsTest.ts:getEligibleBankAccountShareRecipientsreturns admins only from the bank account's own workspace and excludes admins from unrelated workspaces.hasEligibleActiveAdminFromWorkspacesreturnsfalsewhen the user has only joined another workspace as a member and their own workspace has no other admin, andtruewhen another admin exists in the bank account's workspace.Verify that no errors appear in the JS console
Offline tests
N/A — change is limited to client-side eligibility computation.
QA Steps
// TODO: The human co-author must fill out the QA tests you ran before marking this PR as "ready for review".
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari