You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2026-10-20] [Exploratory] Room - Admin cannot remove an invited member from the workspace chat #99271
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
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.
src/pages/DynamicRoomMembersPage.tsx:217 — isSelectionDisabled → no row can be checked, so the bulk button stays disabled via isDisabled={!selectedMembers.length}
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.
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):
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
@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!
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).
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
Activity
applause-bot commentedon Aug 23, 2026
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
MelvinBot commentedon Sep 5, 2026
Updated 2026-09-10: Revised based on feedback from
ikevin127.Proposal
What is the root cause of that problem?
isPolicyAdmin(policy, login)ignores theloginyou 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 alwaystrue, so every member becomes un-removable.The two checks that disable removal:
src/pages/DynamicRoomMemberDetailsPage.tsx:63—shouldDisableRemoveUser→ drivesisDisabledon the Remove from chat button (:114)src/pages/DynamicRoomMembersPage.tsx:217—isSelectionDisabled→ no row can be checked, so the bulk button stays disabled viaisDisabled={!selectedMembers.length}Both call
isPolicyAdmin(policy, details.login)with the defaultshouldCheckGlobalPolicyRole = true, which short-circuits onpolicy.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 inemployeeList) and swapped inisPolicyAdminwithout passingfalse.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
falseat both call sites, via a named const with a comment. The whole bug is a dropped third argument, so an anonymousfalseinline in a boolean chain is not enough — the next refactor drops it again just as silently.DynamicRoomMemberDetailsPage.tsx:63→const isSelectedMemberPolicyAdmin = isPolicyAdmin(policy, details.login, false);DynamicRoomMembersPage.tsx:217→const isAdmin = isPolicyAdmin(policy, details.login, false);This is the pattern already used correctly in
src/libs/actions/Policy/Member.ts:254.2. Document the trap on
isPolicyAdminitself. The current doc comment says "Checks if the current user is an admin of the policy" while the signature advertises aloginparameter — that mismatch is what produced this bug. Spelling out thatloginis silently discarded unlessshouldCheckGlobalPolicyRoleisfalseis 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.employeeListis keyed by the canonical lowercase login, butpersonalDetails.loginis not guaranteed lowercase — that is exactly whyPersonalDetailsUtils.ts:37maintains 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 ofemployeeList, since this runs per participant while rendering a member list.4. Fail closed on the details page when
details.loginis 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.tsxskips participants with no personal details, butDynamicRoomMemberDetailsPage.tsxcan be reached directly by route.Tests. Unit tests in
tests/unit/PolicyUtilsTest.tspinning theshouldCheckGlobalPolicyRolesemantics in both directions, the mixed-case match, and exact-key precedence over the normalized fallback.Full diff
What alternative solutions did you explore? (Optional)
Rejected: reinstate a dedicated
isUserPolicyAdmin(policy, login)helper that only readsemployeeList.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
shouldCheckGlobalPolicyRoleprecisely so a single function could serve both callers. Re-splitting it puts back the duplication the refactor removed, and leavesisPolicyAdmin'sloginparameter 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 — sopolicy.role === 'admin'is guaranteed on that screen, and the short-circuit always fires.The invited member is a clean participant.
resolveActionableMentionWhisper→buildParticipantsInviteDatawrites only{notificationPreference, role: MEMBER}intoreport.participants— nopendingAction, noreportMetadata.pendingChatMembersentry, and nothing inpolicy.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):
That same PR added the
shouldCheckGlobalPolicyRoleflag specifically to preserve the old semantics, and passedfalsecorrectly inMember.ts— just not at these two sites.Call-site audit. 23 call sites in
src/pass a login toisPolicyAdmin. These two are the only misuses; the other 21 pass the current user's own login/email, which is correct under the default.Verification.
ikevin127rantypecheck,lint-changed, React Compiler compliance andcspellclean, 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#roomis unaffected. That staging pass also clears the earlier open question about whether the backendRemoveFromRoomcommand accepts removing a participant from apolicyExpenseChat— 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
melvin-bot commentedon Sep 5, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @ikevin127 (
External)melvin-bot commentedon Sep 5, 2026
Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.
melvin-bot commentedon Sep 6, 2026
@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!
36 remaining items
melvin-bot commentedon Oct 6, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)melvin-bot commentedon Oct 6, 2026
Payment Summary
Resolving PRs:
Resolve the member's own policy role when checking room member removal #101643
Reviewer: @ikevin127 owed $175 via NewDot
BugZero Checklist (@mallenexpensify)
melvin-bot commentedon Oct 9, 2026
@mallenexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
ikevin127 commentedon Oct 13, 2026
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).
[-][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[/+]mallenexpensify commentedon Oct 21, 2026
Payment Summary
Contributor+: @ikevin127 due $100 via NewDot
quinthar commentedon Oct 27, 2026
Approved $100 to @ikevin127