From d27cc363a5602c71cbdeca0dd6c1b7877c37ceca Mon Sep 17 00:00:00 2001 From: Douglas Fabris Date: Fri, 6 Sep 2024 15:21:31 +0100 Subject: [PATCH] fix: Retention policy warning keep displaying if disabled in room (#33197) --- .changeset/khaki-cameras-glow.md | 5 ++++ .../room/hooks/useRetentionPolicy.spec.ts | 23 ++++++++----------- .../views/room/hooks/useRetentionPolicy.ts | 12 ++++++---- 3 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 .changeset/khaki-cameras-glow.md diff --git a/.changeset/khaki-cameras-glow.md b/.changeset/khaki-cameras-glow.md new file mode 100644 index 000000000000..87470d5c497b --- /dev/null +++ b/.changeset/khaki-cameras-glow.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixes an issue where the retention policy warning keep displaying even if the retention is disabled inside the room diff --git a/apps/meteor/client/views/room/hooks/useRetentionPolicy.spec.ts b/apps/meteor/client/views/room/hooks/useRetentionPolicy.spec.ts index 9b99d6e4d781..b5d9079c9cab 100644 --- a/apps/meteor/client/views/room/hooks/useRetentionPolicy.spec.ts +++ b/apps/meteor/client/views/room/hooks/useRetentionPolicy.spec.ts @@ -72,16 +72,13 @@ it('should return enabled and active true global retention is active for rooms o expect(result.current).toEqual(expect.objectContaining({ ...defaultValue, enabled: true, isActive: true })); }); -it.failing( - 'should isActive be false if global retention is active for rooms of the type and room has retention.enabled false', - async () => { - const fakeRoom = createFakeRoom({ t: CHANNELS_TYPE, retention: { enabled: false } }); - - const { result } = renderHook(() => useRetentionPolicy(fakeRoom), { - legacyRoot: true, - wrapper: getGlobalSettings({ enabled: true, ...roomTypeConfig[CHANNELS_TYPE] }).build(), - }); - - expect(result.current?.isActive).toBe(false); - }, -); +it('should isActive be false if global retention is active for rooms of the type and room has retention.enabled false', async () => { + const fakeRoom = createFakeRoom({ t: CHANNELS_TYPE, retention: { enabled: false } }); + + const { result } = renderHook(() => useRetentionPolicy(fakeRoom), { + legacyRoot: true, + wrapper: getGlobalSettings({ enabled: true, ...roomTypeConfig[CHANNELS_TYPE] }).build(), + }); + + expect(result.current?.isActive).toBe(false); +}); diff --git a/apps/meteor/client/views/room/hooks/useRetentionPolicy.ts b/apps/meteor/client/views/room/hooks/useRetentionPolicy.ts index 96efedef692e..076ad13c5a0f 100644 --- a/apps/meteor/client/views/room/hooks/useRetentionPolicy.ts +++ b/apps/meteor/client/views/room/hooks/useRetentionPolicy.ts @@ -4,7 +4,9 @@ import { useSetting } from '@rocket.chat/ui-contexts'; import { TIMEUNIT, isValidTimespan, timeUnitToMs } from '../../../lib/convertTimeUnit'; const hasRetentionPolicy = (room: IRoom & { retention?: any }): room is IRoomWithRetentionPolicy => - 'retention' in room && room.retention !== undefined && 'overrideGlobal' in room.retention && isValidTimespan(room.retention.maxAge); + 'retention' in room && room.retention !== undefined; + +const isRetentionOverridden = (room: IRoom & { retention?: any }) => 'overrideGlobal' in room.retention && room.retention.overrideGlobal; type RetentionPolicySettings = { enabled: boolean; @@ -41,7 +43,7 @@ const isActive = (room: IRoom, { enabled, appliesToChannels, appliesToGroups, ap }; const extractFilesOnly = (room: IRoom, { filesOnly }: RetentionPolicySettings): boolean => { - if (hasRetentionPolicy(room) && room.retention.overrideGlobal) { + if (hasRetentionPolicy(room) && isRetentionOverridden(room)) { return room.retention.filesOnly; } @@ -49,7 +51,7 @@ const extractFilesOnly = (room: IRoom, { filesOnly }: RetentionPolicySettings): }; const extractExcludePinned = (room: IRoom, { doNotPrunePinned }: RetentionPolicySettings): boolean => { - if (hasRetentionPolicy(room) && room.retention.overrideGlobal) { + if (hasRetentionPolicy(room) && isRetentionOverridden(room)) { return room.retention.excludePinned; } @@ -57,7 +59,7 @@ const extractExcludePinned = (room: IRoom, { doNotPrunePinned }: RetentionPolicy }; const extractIgnoreThreads = (room: IRoom, { ignoreThreads }: RetentionPolicySettings): boolean => { - if (hasRetentionPolicy(room) && room.retention.overrideGlobal) { + if (hasRetentionPolicy(room) && isRetentionOverridden(room)) { return room.retention.ignoreThreads; } @@ -65,7 +67,7 @@ const extractIgnoreThreads = (room: IRoom, { ignoreThreads }: RetentionPolicySet }; const getMaxAge = (room: IRoom, { maxAgeChannels, maxAgeGroups, maxAgeDMs }: RetentionPolicySettings): number => { - if (hasRetentionPolicy(room) && room.retention.overrideGlobal) { + if (hasRetentionPolicy(room) && isRetentionOverridden(room) && isValidTimespan(room.retention.maxAge)) { return timeUnitToMs(TIMEUNIT.days, room.retention.maxAge); }