Skip to content

[Due for payment 2026-10-20] [Exploratory] Room - Admin cannot remove an invited member from the workspace chat #99271

Closed

Description

@applause-bot

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: v9.4.59-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/70273303/folder/13176686/41236628/1683779899?sort=%2Bidentifier
Email or phone of affected tester (no customers): n/a
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.5.1 Safari/Chrome, iPhone 13 iOS 26.6
App Component: Chat Report View

Action Performed:

  1. Go to https://staging.new.expensify.com
  2. As admin, create a workspace
  3. Navigate to the workspace chat
  4. Invite a user to the workspace chat
  5. Select Invite to chat option on the whisper message
  6. Click on the workspace chat header > Members

Expected Result:

Admin should be able to remove the invited member from the workspace chat

Actual Result:

Admin cannot remove an invited member from the workspace chat, the Remove from chat button is disabled

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome Safari

Screenshots/Videos

Bug7239694_1787355428757.Recording__2828.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Julia Ponikarchuk
Bug ID: 7239694

Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. applause-bot commented on Aug 23, 2026

    @applause-bot
    Author

    While Applause doesn't embed attachments for this bug, here are the links for quick view:
    https://platform.applause.com/services/links/v1/external/11587dc70d36f38323210cae55092140d7d9e193e1a6dbd40fc54ad4ad80647c

  2. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Sep 5, 2026
  3. MelvinBot commented on Sep 5, 2026

    @MelvinBot
    Contributor

    Updated 2026-09-10: Revised based on feedback from ikevin127.

    Proposal

    What is the root cause of that problem?

    isPolicyAdmin(policy, login) ignores the login you pass it and returns the viewing user's role instead. Since only a workspace admin can reach the Members page of a workspace chat, the check "is this row an admin?" is always true, so every member becomes un-removable.

    The two checks that disable removal:

    Both call isPolicyAdmin(policy, details.login) with the default shouldCheckGlobalPolicyRole = true, which short-circuits on policy.role — the current user's role — and never reads the login (src/libs/PolicyUtils.ts:642-652).

    This is a regression from #80006 (merged 2026-02-10), which deleted isUserPolicyAdmin (which did look the target login up in employeeList) and swapped in isPolicyAdmin without passing false.

    The "Invite to chat" whisper is only the trigger, not the cause — it is the easiest way to get a third person into a fresh workspace chat. The bug reproduces for any member of any workspace chat viewed by an admin, regardless of how they joined.

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

    Four parts. Parts 1 and 4 fix the bug; parts 2 and 3 stop it from coming back and close the near-miss that sits next to it.

    1. Pass false at both call sites, via a named const with a comment. The whole bug is a dropped third argument, so an anonymous false inline in a boolean chain is not enough — the next refactor drops it again just as silently.

    This is the pattern already used correctly in src/libs/actions/Policy/Member.ts:254.

    2. Document the trap on isPolicyAdmin itself. The current doc comment says "Checks if the current user is an admin of the policy" while the signature advertises a login parameter — that mismatch is what produced this bug. Spelling out that login is silently discarded unless shouldCheckGlobalPolicyRole is false is what protects the other 21 call sites that pass a login, not just these two.

    3. Add an O(1) normalized-login fallback in getPolicyRole. employeeList is keyed by the canonical lowercase login, but personalDetails.login is not guaranteed lowercase — that is exactly why PersonalDetailsUtils.ts:37 maintains a separate lowercased cache. Without this, part 1 would turn a mixed-case admin into a removable "non-admin". Exact key first so an existing hit can never regress, then one lowercase lookup — no case-insensitive scan of employeeList, since this runs per participant while rendering a member list.

    4. Fail closed on the details page when details.login is missing. Before the fix that case was accidentally safe, because the check returned the viewer's admin role and disabled removal. After the fix an absent login resolves to "not an admin" and offers removal for a member whose role we cannot determine. DynamicRoomMembersPage.tsx skips participants with no personal details, but DynamicRoomMemberDetailsPage.tsx can be reached directly by route.

    Tests. Unit tests in tests/unit/PolicyUtilsTest.ts pinning the shouldCheckGlobalPolicyRole semantics in both directions, the mixed-case match, and exact-key precedence over the normalized fallback.

    Full diff
    diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts
    index 3ff13bc28e4..ec95a0165db 100644
    --- a/src/libs/PolicyUtils.ts
    +++ b/src/libs/PolicyUtils.ts
    @@ -176,6 +176,10 @@ function getActivePoliciesWithExpenseChatAndTimeEnabled(policies: OnyxCollection
     
     /**
      * Checks if the current user is an admin of the policy.
    + *
    + * By default this answers "is the *viewing* user an admin?", because `getPolicyRole` short-circuits on the global
    + * `policy.role`. When `login` belongs to somebody other than the current user you must pass
    + * `shouldCheckGlobalPolicyRole = false`, otherwise the `login` argument is silently ignored.
      */
     const isPolicyAdmin = (policy: OnyxInputOrEntry<Policy>, login?: string, shouldCheckGlobalPolicyRole = true): boolean =>
         getPolicyRole(policy, login, shouldCheckGlobalPolicyRole) === CONST.POLICY.ROLE.ADMIN;
    @@ -648,7 +652,10 @@ function getPolicyRole(policy: OnyxInputOrEntry<Policy>, currentUserLogin?: stri
             return;
         }
     
    -    return policy?.employeeList?.[currentUserLogin]?.role;
    +    // `employeeList` is keyed by the canonical lowercase login, but a login read off personal details is not
    +    // guaranteed to be lowercase, so fall back to a normalized lookup when the exact key misses. Both lookups are
    +    // O(1), unlike a case-insensitive scan of every employee, which would run per participant on member lists.
    +    return policy?.employeeList?.[currentUserLogin]?.role ?? policy?.employeeList?.[currentUserLogin.toLowerCase()]?.role;
     }
     
     /**
    diff --git a/src/pages/DynamicRoomMemberDetailsPage.tsx b/src/pages/DynamicRoomMemberDetailsPage.tsx
    index a180c3e2db6..c870a83bbe8 100644
    --- a/src/pages/DynamicRoomMemberDetailsPage.tsx
    +++ b/src/pages/DynamicRoomMemberDetailsPage.tsx
    @@ -60,7 +60,12 @@ function DynamicRoomMemberDetailsPage({report, route}: DynamicRoomMemberDetailsP
         const displayName = temporaryGetDisplayNameOrDefault({passedPersonalDetails: details, translate, formatPhoneNumber});
         const isSelectedMemberCurrentUser = accountID === currentUserPersonalDetails?.accountID;
         const isSelectedMemberOwner = accountID === report.ownerAccountID;
    -    const shouldDisableRemoveUser = (isPolicyExpenseChat(report) && isPolicyAdmin(policy, details.login)) || isSelectedMemberCurrentUser || isSelectedMemberOwner;
    +    // Check the selected member's own role on the policy, not the viewer's. `shouldCheckGlobalPolicyRole` must stay false
    +    // here, otherwise this short-circuits on `policy.role` (the viewing admin) and every member looks like an admin.
    +    const isSelectedMemberPolicyAdmin = isPolicyAdmin(policy, details.login, false);
    +    // Without a login we cannot resolve the member's policy role, so fail closed rather than offering removal. This page
    +    // can be reached directly by route, unlike the members list, which skips participants that have no personal details.
    +    const shouldDisableRemoveUser = (isPolicyExpenseChat(report) && (!details.login || isSelectedMemberPolicyAdmin)) || isSelectedMemberCurrentUser || isSelectedMemberOwner;
         const askForConfirmationToRemove = () => {
             showConfirmModal({
                 buttonVariant: CONST.BUTTON_VARIANT.DANGER,
    diff --git a/src/pages/DynamicRoomMembersPage.tsx b/src/pages/DynamicRoomMembersPage.tsx
    index 209bc8da2ce..0ae1b91e139 100644
    --- a/src/pages/DynamicRoomMembersPage.tsx
    +++ b/src/pages/DynamicRoomMembersPage.tsx
    @@ -214,7 +214,9 @@ function DynamicRoomMembersPage({report, policy}: DynamicRoomMembersPageProps) {
                     continue;
                 }
                 const pendingChatMember = reportMetadata?.pendingChatMembers?.findLast((member) => member.accountID === accountID.toString());
    -            const isAdmin = isPolicyAdmin(policy, details.login);
    +            // Check the listed member's own role on the policy, not the viewer's. `shouldCheckGlobalPolicyRole` must stay
    +            // false here, otherwise this short-circuits on `policy.role` (the viewing admin) and every member looks like an admin.
    +            const isAdmin = isPolicyAdmin(policy, details.login, false);
                 const isDisabled = pendingChatMember?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || details.isOptimisticPersonalDetail;
                 const isSelectionDisabled =
                     (isPolicyExpenseChat && isAdmin) ||
    diff --git a/tests/unit/PolicyUtilsTest.ts b/tests/unit/PolicyUtilsTest.ts
    index bc2cebcc9ae..5b72ba94fdf 100644
    --- a/tests/unit/PolicyUtilsTest.ts
    +++ b/tests/unit/PolicyUtilsTest.ts
    @@ -72,6 +72,7 @@ import {
         isMergeHRCompleteSetupNeededSelector,
         isPerDiemEligiblePolicy,
         isPerDiemEnabled,
    +    isPolicyAdmin,
         isPolicyMemberWithoutPendingDelete,
         isSubmitterApproveBlockedOnSubmitWorkspace,
         isRilletVendorMatchingActive,
    @@ -417,6 +418,59 @@ describe('PolicyUtils', () => {
             });
         });
     
    +    describe('isPolicyAdmin', () => {
    +        const adminLogin = 'admin@test.com';
    +        const memberLogin = 'member@test.com';
    +        // `role` is the role of the user currently viewing the policy, `employeeList` holds every member's own role
    +        const buildPolicy = (): Policy =>
    +            createMock<Policy>({
    +                ...createRandomPolicy(1, CONST.POLICY.TYPE.CORPORATE),
    +                role: CONST.POLICY.ROLE.ADMIN,
    +                employeeList: {
    +                    [adminLogin]: {role: CONST.POLICY.ROLE.ADMIN},
    +                    [memberLogin]: {role: CONST.POLICY.ROLE.USER},
    +                },
    +            });
    +
    +        it('resolves the role of the passed login when shouldCheckGlobalPolicyRole is false', () => {
    +            expect(isPolicyAdmin(buildPolicy(), memberLogin, false)).toBe(false);
    +            expect(isPolicyAdmin(buildPolicy(), adminLogin, false)).toBe(true);
    +        });
    +
    +        it('ignores the passed login and answers for the viewing user by default', () => {
    +            // This documents the trap that made every member of a workspace chat look like an admin to a viewing
    +            // admin, which disabled the "Remove from chat" button for all of them
    +            expect(isPolicyAdmin(buildPolicy(), memberLogin)).toBe(true);
    +        });
    +
    +        it('returns false for a login that is not in the employee list when shouldCheckGlobalPolicyRole is false', () => {
    +            expect(isPolicyAdmin(buildPolicy(), 'stranger@test.com', false)).toBe(false);
    +        });
    +
    +        it('returns false for an undefined login when shouldCheckGlobalPolicyRole is false', () => {
    +            expect(isPolicyAdmin(buildPolicy(), undefined, false)).toBe(false);
    +        });
    +
    +        it('matches an employee whose login is not lowercase when shouldCheckGlobalPolicyRole is false', () => {
    +            expect(isPolicyAdmin(buildPolicy(), 'Admin@Test.com', false)).toBe(true);
    +            expect(isPolicyAdmin(buildPolicy(), 'Member@Test.com', false)).toBe(false);
    +        });
    +
    +        it('prefers an exact employee list key over the normalized one', () => {
    +            const policy = createMock<Policy>({
    +                ...createRandomPolicy(1, CONST.POLICY.TYPE.CORPORATE),
    +                role: undefined,
    +                employeeList: {
    +                    'Mixed@Test.com': {role: CONST.POLICY.ROLE.ADMIN},
    +                    'mixed@test.com': {role: CONST.POLICY.ROLE.USER},
    +                },
    +            });
    +
    +            expect(isPolicyAdmin(policy, 'Mixed@Test.com', false)).toBe(true);
    +            expect(isPolicyAdmin(policy, 'mixed@test.com', false)).toBe(false);
    +        });
    +    });
    +
         describe('useDefaultFundID', () => {
             beforeEach(() => {
                 wrapOnyxWithWaitForBatchedUpdates(Onyx);

    What alternative solutions did you explore? (Optional)

    Rejected: reinstate a dedicated isUserPolicyAdmin(policy, login) helper that only reads employeeList.

    It removes the footgun rather than documenting it, but it partially reverts the consolidation #80006 deliberately made: that PR collapsed two near-identical helpers into one and added shouldCheckGlobalPolicyRole precisely so a single function could serve both callers. Re-splitting it puts back the duplication the refactor removed, and leaves isPolicyAdmin's login parameter just as easy to misuse for the 21 other call sites that pass one. Part 2 above targets the same footgun without undoing the consolidation.

    Supporting evidence

    Why only an admin sees this page. src/pages/DynamicReportDetailsPage.tsx:298: shouldOpenRoomMembersPage = isUserCreatedPolicyRoom || isChatThread || (isPolicyExpenseChat && isPolicyAdmin). For a workspace chat, the only viewer who reaches the Room Members stack is a policy admin — so policy.role === 'admin' is guaranteed on that screen, and the short-circuit always fires.

    The invited member is a clean participant. resolveActionableMentionWhisper → buildParticipantsInviteData writes only {notificationPreference, role: MEMBER} into report.participants — no pendingAction, no reportMetadata.pendingChatMembers entry, and nothing in policy.employeeList. So none of the pending-delete filters apply, and there is no "remove them from the workspace instead" story.

    The regressing diff (#80006, verified via the PR files API):

    -const shouldDisableRemoveUser = (isPolicyExpenseChat(report) && isUserPolicyAdmin(policy, details.login)) || ...
    +const shouldDisableRemoveUser = (isPolicyExpenseChat(report) && isPolicyAdmin(policy, details.login)) || ...
    -            const isAdmin = isUserPolicyAdmin(policy, details.login);
    +            const isAdmin = isPolicyAdmin(policy, details.login);

    That same PR added the shouldCheckGlobalPolicyRole flag specifically to preserve the old semantics, and passed false correctly in Member.ts — just not at these two sites.

    Call-site audit. 23 call sites in src/ pass a login to isPolicyAdmin. These two are the only misuses; the other 21 pass the current user's own login/email, which is correct under the default.

    Verification. ikevin127 ran typecheck, lint-changed, React Compiler compliance and cspell clean, with 1891/1891 passing across the 6 policy-related suites, and confirmed on staging that a plain participant is now removable, an admin participant stays non-removable, and a #room is unaffected. That staging pass also clears the earlier open question about whether the backend RemoveFromRoom command accepts removing a participant from a policyExpenseChat — it does.


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/99271#issuecomment-5555230947) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal. · view recording

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Sep 5, 2026
  5. melvin-bot commented on Sep 5, 2026

    @melvin-bot

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

  6. melvin-bot commented on Sep 5, 2026

    @melvin-bot

    Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.

  7. melvin-bot commented on Sep 6, 2026

    @melvin-bot

    @ikevin127 this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

  8. 36 remaining items

  9. melvin-bot commented on Oct 6, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  10. melvin-bot commented on Oct 6, 2026

    @melvin-bot

    Payment Summary

    Resolving PRs:

    BugZero Checklist (@mallenexpensify)

    • I have confirmed assignees, roles, and Upwork contracts look correct
    • I have paid out Upwork contracts / manual NewDot requests
    • [BugZero Assignee] I have created a GH issue for creating/updating the regression test once above steps have been agreed upon
  11. melvin-bot commented on Oct 9, 2026

    @melvin-bot

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

  12. ikevin127 commented on Oct 13, 2026

    @ikevin127
    Contributor

    Note

    Payment will be due on 20th because of this follow-up PR that was deployed today. Payment will be $100 because there was 1 regression (which required the follow-up PR).

  13. changed the title [-][Due for payment 2026-10-07] [Exploratory] Room - Admin cannot remove an invited member from the workspace chat[/-] [+][Due for payment 2026-10-20] [Exploratory] Room - Admin cannot remove an invited member from the workspace chat[/+] on Oct 13, 2026
  14. mallenexpensify commented on Oct 21, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @ikevin127 due $100 via NewDot

  15. quinthar commented on Oct 27, 2026

    @quinthar
    Contributor

    Approved $100 to @ikevin127

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorNot a priorityWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions