From 906c0040b6a203f88bf7cefcf1affc5c3fe4e9ed Mon Sep 17 00:00:00 2001 From: Yuwen Memon Date: Thu, 11 Jan 2024 13:57:38 +0800 Subject: [PATCH] Merge pull request #34311 from Expensify/revert-34046-ionatan_killareChatRoomsEnabled Revert "[NO QA] Remove areChatRoomsEnabled checks" (cherry picked from commit 778eee53ca35fb25608ef52f13ed73166e637241) --- src/libs/PolicyUtils.ts | 5 ++++- src/types/onyx/Policy.ts | 3 +++ tests/utils/LHNTestUtils.js | 1 + tests/utils/collections/policies.ts | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 2c5c72ab1c39..0cab97299324 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -14,7 +14,10 @@ type UnitRate = {rate: number}; * These are policies that we can use to create reports with in NewDot. */ function getActivePolicies(policies: OnyxCollection): Policy[] | undefined { - return Object.values(policies ?? {}).filter((policy): policy is Policy => policy !== null && policy && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); + return Object.values(policies ?? {}).filter( + (policy): policy is Policy => + policy !== null && policy && (policy.isPolicyExpenseChatEnabled || policy.areChatRoomsEnabled) && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + ); } /** diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index a9af3339eeb4..da4522487a7a 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -62,6 +62,9 @@ type Policy = { /** The custom units data for this policy */ customUnits?: Record; + /** Whether chat rooms can be created and used on this policy. Enabled manually by CQ/JS snippet. Always true for free policies. */ + areChatRoomsEnabled: boolean; + /** Whether policy expense chats can be created and used on this policy. Enabled manually by CQ/JS snippet. Always true for free policies. */ isPolicyExpenseChatEnabled: boolean; diff --git a/tests/utils/LHNTestUtils.js b/tests/utils/LHNTestUtils.js index 7403df3ef57f..535fb018dbc3 100644 --- a/tests/utils/LHNTestUtils.js +++ b/tests/utils/LHNTestUtils.js @@ -252,6 +252,7 @@ function getFakePolicy(id = 1, name = 'Workspace-Test-001') { avatar: '', employeeList: [], isPolicyExpenseChatEnabled: true, + areChatRoomsEnabled: true, lastModified: 1697323926777105, autoReporting: true, autoReportingFrequency: 'immediate', diff --git a/tests/utils/collections/policies.ts b/tests/utils/collections/policies.ts index d9da92d26e36..96e13f915c49 100644 --- a/tests/utils/collections/policies.ts +++ b/tests/utils/collections/policies.ts @@ -7,6 +7,7 @@ export default function createRandomPolicy(index: number): Policy { id: index.toString(), name: randWord(), type: rand(Object.values(CONST.POLICY.TYPE)), + areChatRoomsEnabled: randBoolean(), autoReporting: randBoolean(), isPolicyExpenseChatEnabled: randBoolean(), autoReportingFrequency: rand(Object.values(CONST.POLICY.AUTO_REPORTING_FREQUENCIES)),