diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 9bf68b2c5432..2647c029aa7f 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -69,13 +69,11 @@ Onyx.connect({ /** * Filter out the active policies, which will exclude policies with pending deletion - * and policies the current user doesn't belong to. * These are policies that we can use to create reports with in NewDot. */ -function getActivePolicies(policies: OnyxCollection | null, currentUserLogin: string | undefined): Policy[] { +function getActivePolicies(policies: OnyxCollection | null): Policy[] { return Object.values(policies ?? {}).filter( - (policy): policy is Policy => - !!policy && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !!policy.name && !!policy.id && !!getPolicyRole(policy, currentUserLogin), + (policy): policy is Policy => !!policy && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !!policy.name && !!policy.id, ); } /** @@ -638,7 +636,7 @@ function getPolicy(policyID: string | undefined): OnyxEntry { /** Return active policies where current user is an admin */ function getActiveAdminWorkspaces(policies: OnyxCollection | null, currentUserLogin: string | undefined): Policy[] { - const activePolicies = getActivePolicies(policies, currentUserLogin); + const activePolicies = getActivePolicies(policies); return activePolicies.filter((policy) => shouldShowPolicy(policy, NetworkStore.isOffline(), currentUserLogin) && isPolicyAdmin(policy, currentUserLogin)); } @@ -654,7 +652,7 @@ function canSendInvoice(policies: OnyxCollection | null, currentUserLogi } function hasWorkspaceWithInvoices(currentUserLogin: string | undefined): boolean { - const activePolicies = getActivePolicies(allPolicies, currentUserLogin); + const activePolicies = getActivePolicies(allPolicies); return activePolicies.some((policy) => shouldShowPolicy(policy, NetworkStore.isOffline(), currentUserLogin) && policy.areInvoicesEnabled); } diff --git a/src/pages/workspace/WorkspaceNewRoomPage.tsx b/src/pages/workspace/WorkspaceNewRoomPage.tsx index c64c53306a1f..37686ba1c3a7 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.tsx +++ b/src/pages/workspace/WorkspaceNewRoomPage.tsx @@ -64,14 +64,14 @@ function WorkspaceNewRoomPage() { const workspaceOptions = useMemo( () => - PolicyUtils.getActivePolicies(policies, session?.email) + PolicyUtils.getActivePolicies(policies) ?.filter((policy) => policy.type !== CONST.POLICY.TYPE.PERSONAL) .map((policy) => ({ label: policy.name, value: policy.id, })) .sort((a, b) => localeCompare(a.label, b.label)) ?? [], - [policies, session?.email], + [policies], ); const [policyID, setPolicyID] = useState(() => { if (!!activeWorkspaceOrDefaultID && workspaceOptions.some((option) => option.value === activeWorkspaceOrDefaultID)) { diff --git a/tests/unit/PolicyUtilsTest.ts b/tests/unit/PolicyUtilsTest.ts index c37d7970f1cf..71830443063a 100644 --- a/tests/unit/PolicyUtilsTest.ts +++ b/tests/unit/PolicyUtilsTest.ts @@ -1,24 +1,10 @@ import * as PolicyUtils from '@libs/PolicyUtils'; -import ONYXKEYS from '@src/ONYXKEYS'; -import type {Policy} from '@src/types/onyx'; -import createCollection from '../utils/collections/createCollection'; -import createRandomPolicy from '../utils/collections/policies'; function toLocaleDigitMock(dot: string): string { return dot; } describe('PolicyUtils', () => { - describe('getActivePolicies', () => { - it("getActivePolicies should filter out policies that the current user doesn't belong to", () => { - const policies = createCollection( - (item) => `${ONYXKEYS.COLLECTION.POLICY}${item.id}`, - (index) => ({...createRandomPolicy(index + 1), ...(!index && {role: null})} as Policy), - 2, - ); - expect(PolicyUtils.getActivePolicies(policies, undefined)).toHaveLength(1); - }); - }); describe('getRateDisplayValue', () => { it('should return an empty string for NaN', () => { const rate = PolicyUtils.getRateDisplayValue('invalid' as unknown as number, toLocaleDigitMock);