Skip to content

Commit

Permalink
fix: Retention policy warning keep displaying if disabled in room (#3…
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris committed Sep 6, 2024
1 parent b8effb5 commit d27cc36
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-cameras-glow.md
Original file line number Diff line number Diff line change
@@ -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
23 changes: 10 additions & 13 deletions apps/meteor/client/views/room/hooks/useRetentionPolicy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
12 changes: 7 additions & 5 deletions apps/meteor/client/views/room/hooks/useRetentionPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,31 +43,31 @@ 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;
}

return filesOnly;
};

const extractExcludePinned = (room: IRoom, { doNotPrunePinned }: RetentionPolicySettings): boolean => {
if (hasRetentionPolicy(room) && room.retention.overrideGlobal) {
if (hasRetentionPolicy(room) && isRetentionOverridden(room)) {
return room.retention.excludePinned;
}

return doNotPrunePinned;
};

const extractIgnoreThreads = (room: IRoom, { ignoreThreads }: RetentionPolicySettings): boolean => {
if (hasRetentionPolicy(room) && room.retention.overrideGlobal) {
if (hasRetentionPolicy(room) && isRetentionOverridden(room)) {
return room.retention.ignoreThreads;
}

return ignoreThreads;
};

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);
}

Expand Down

0 comments on commit d27cc36

Please sign in to comment.