Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ import {buildPersonalDetailsUpdate, getAccountIDsByLogins, getLoginByAccountID,
import {getPolicyReimburserAccountID} from './PolicyPaymentUtils';
import {
arePaymentsEnabled,
canMemberRead as canMemberReadPolicyUtils,
canMemberWrite as canMemberWritePolicyUtils,
canCreateExpensesOnPolicy,
canSendInvoiceFromWorkspace,
Expand Down Expand Up @@ -13436,9 +13437,12 @@ function canJoinChat(
return false;
}

// For restricted visibility rooms, the user must be a non-guest workspace member to join
const policyRole = getPolicyRole(policy, currentUserEmail ?? deprecatedCurrentUserEmail);
if (isUserCreatedPolicyRoom(report) && report?.visibility === CONST.REPORT.VISIBILITY.RESTRICTED && (!policyRole || policyRole === CONST.POLICY.ROLE.GUEST)) {
// For restricted visibility rooms, the user must be a workspace member with room access to join
if (
isUserCreatedPolicyRoom(report) &&
report?.visibility === CONST.REPORT.VISIBILITY.RESTRICTED &&
!canMemberReadPolicyUtils(policy, currentUserEmail ?? deprecatedCurrentUserEmail ?? '', CONST.POLICY.POLICY_FEATURE.ROOMS)
) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import useParentReportAction from '@hooks/useParentReportAction';
import {useAllPersonalDetails} from '@hooks/usePersonalDetails';
import useReportIsArchived from '@hooks/useReportIsArchived';

import {isPolicyAdmin as isPolicyAdminUtil, isPolicyEmployee as isPolicyEmployeeUtil, isPolicyGuest as isPolicyGuestUtil} from '@libs/PolicyUtils';
import {canMemberRead, isPolicyAdmin as isPolicyAdminUtil, isPolicyEmployee as isPolicyEmployeeUtil} from '@libs/PolicyUtils';
import {
canLeaveChat,
findLastAccessedReport,
Expand Down Expand Up @@ -63,7 +63,7 @@ function ReportDetailsMenuLeaveItem({reportID}: ReportDetailsMenuLeaveItemProps)

const isPolicyAdmin = isPolicyAdminUtil(policy);
const isPolicyEmployee = isPolicyEmployeeUtil(report.policyID, policy);
const isPolicyGuest = isPolicyGuestUtil(policy);
const isRestrictedRoomMember = !canMemberRead(policy, currentUserPersonalDetails?.login ?? '', CONST.POLICY.POLICY_FEATURE.ROOMS);
const isRootGroupChat = isRootGroupChatUtil(report, isReportArchived);

const leaveChat = () => {
Expand All @@ -84,7 +84,7 @@ function ReportDetailsMenuLeaveItem({reportID}: ReportDetailsMenuLeaveItemProps)
return;
}

const isWorkspaceMemberLeavingWorkspaceRoom = isWorkspaceMemberLeavingWorkspaceRoomUtil(report, isPolicyEmployee, isPolicyAdmin, isPolicyGuest);
const isWorkspaceMemberLeavingWorkspaceRoom = isWorkspaceMemberLeavingWorkspaceRoomUtil(report, isPolicyEmployee, isPolicyAdmin, isRestrictedRoomMember);
leaveRoom(
report,
currentUserAccountID,
Expand Down
13 changes: 11 additions & 2 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17376,6 +17376,13 @@ describe('ReportUtils', () => {
employeeList: {},
};

const policyWithApproveOnlyUser: Policy = {
...createRandomPolicy(4),
id: policyID,
role: CONST.POLICY.ROLE.APPROVE_ONLY,
employeeList: {},
};

const restrictedReport: Report = {
...createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_ROOM),
type: CONST.REPORT.TYPE.CHAT,
Expand All @@ -17396,15 +17403,17 @@ describe('ReportUtils', () => {
};

// When checking whether a user can join restricted rooms
// Then regular workspace members can join, but non-members and guests cannot
// Then regular workspace members can join, but non-members, guests, and approve-only members cannot
expect(canJoinChat(restrictedReport, undefined, policyWithoutCurrentUser, undefined)).toBe(false);
expect(canJoinChat(restrictedReport, undefined, policyWithCurrentUser, undefined)).toBe(true);
expect(canJoinChat(restrictedReport, undefined, policyWithGuestUser, undefined)).toBe(false);
expect(canJoinChat(restrictedReport, undefined, policyWithApproveOnlyUser, undefined)).toBe(false);

// When checking whether a user can join public rooms
// Then non-members and guests can both join
// Then non-members, guests, and approve-only members can join
expect(canJoinChat(publicReport, undefined, policyWithoutCurrentUser, undefined)).toBe(true);
expect(canJoinChat(publicReport, undefined, policyWithGuestUser, undefined)).toBe(true);
expect(canJoinChat(publicReport, undefined, policyWithApproveOnlyUser, undefined)).toBe(true);
});
});

Expand Down
Loading