Skip to content

Commit

Permalink
fix: Override retention policy missing ignore threads option (#32485)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris authored Jun 21, 2024
1 parent 68b624e commit 4a0480b
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-dancers-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Adds the missing `ignoreThreads` param fixing the issue not allowing ignoring threads when overriding retention policy
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const EditRoomInfo = ({ room, onClickClose, onClickBack }: EditRoomInfoProps) =>
retentionMaxAge,
retentionExcludePinned,
retentionFilesOnly,
retentionIgnoreThreads,
...formData
}) => {
const data = getDirtyFields(formData, dirtyFields);
Expand All @@ -172,6 +173,7 @@ const EditRoomInfo = ({ room, onClickClose, onClickBack }: EditRoomInfoProps) =>
retentionMaxAge,
retentionExcludePinned,
retentionFilesOnly,
retentionIgnoreThreads,
}),
});

Expand Down Expand Up @@ -218,6 +220,7 @@ const EditRoomInfo = ({ room, onClickClose, onClickBack }: EditRoomInfoProps) =>
const retentionMaxAgeField = useUniqueId();
const retentionExcludePinnedField = useUniqueId();
const retentionFilesOnlyField = useUniqueId();
const retentionIgnoreThreads = useUniqueId();

return (
<>
Expand Down Expand Up @@ -538,6 +541,18 @@ const EditRoomInfo = ({ room, onClickClose, onClickBack }: EditRoomInfoProps) =>
/>
</FieldRow>
</Field>
<Field>
<FieldRow>
<FieldLabel htmlFor={retentionIgnoreThreads}>{t('RetentionPolicy_DoNotPruneThreads')}</FieldLabel>
<Controller
control={control}
name='retentionIgnoreThreads'
render={({ field: { value, ...field } }) => (
<ToggleSwitch id={retentionIgnoreThreads} {...field} checked={value} />
)}
/>
</FieldRow>
</Field>
{canViewEncrypted && (
<Field>
<FieldRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const useEditRoomInitialValues = (room: IRoomWithRetentionPolicy) => {
retentionMaxAge: retention?.maxAge ?? retentionPolicy.maxAge,
retentionExcludePinned: retention?.excludePinned ?? retentionPolicy.excludePinned,
retentionFilesOnly: retention?.filesOnly ?? retentionPolicy.filesOnly,
retentionIgnoreThreads: retention?.ignoreThreads ?? retentionPolicy.ignoreThreads,
}),
}),
[
Expand Down
12 changes: 12 additions & 0 deletions apps/meteor/client/views/room/hooks/useRetentionPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type RetentionPolicySettings = {
enabled: boolean;
filesOnly: boolean;
doNotPrunePinned: boolean;
ignoreThreads: boolean;
appliesToChannels: boolean;
maxAgeChannels: number;
appliesToGroups: boolean;
Expand Down Expand Up @@ -55,6 +56,14 @@ const extractExcludePinned = (room: IRoom, { doNotPrunePinned }: RetentionPolicy
return doNotPrunePinned;
};

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

return ignoreThreads;
};

const getMaxAge = (room: IRoom, { maxAgeChannels, maxAgeGroups, maxAgeDMs }: RetentionPolicySettings): number => {
if (hasRetentionPolicy(room) && room.retention.overrideGlobal) {
return room.retention.maxAge;
Expand All @@ -81,13 +90,15 @@ export const useRetentionPolicy = (
isActive: boolean;
filesOnly: boolean;
excludePinned: boolean;
ignoreThreads: boolean;
maxAge: number;
}
| undefined => {
const settings = {
enabled: useSetting('RetentionPolicy_Enabled') as boolean,
filesOnly: useSetting('RetentionPolicy_FilesOnly') as boolean,
doNotPrunePinned: useSetting('RetentionPolicy_DoNotPrunePinned') as boolean,
ignoreThreads: useSetting('RetentionPolicy_DoNotPruneThreads') as boolean,
appliesToChannels: useSetting('RetentionPolicy_AppliesToChannels') as boolean,
maxAgeChannels: useSetting('RetentionPolicy_MaxAge_Channels') as number,
appliesToGroups: useSetting('RetentionPolicy_AppliesToGroups') as boolean,
Expand All @@ -105,6 +116,7 @@ export const useRetentionPolicy = (
isActive: isActive(room, settings),
filesOnly: extractFilesOnly(room, settings),
excludePinned: extractExcludePinned(room, settings),
ignoreThreads: extractIgnoreThreads(room, settings),
maxAge: getMaxAge(room, settings),
};
};
5 changes: 2 additions & 3 deletions apps/meteor/server/models/raw/Rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1838,13 +1838,12 @@ export class RoomsRaw extends BaseRaw<IRoom> implements IRoomsModel {
return this.updateOne(query, update);
}

// 5
saveRetentionIgnoreThreadsById(_id: IRoom['_id'], value: boolean): Promise<UpdateResult> {
const query: Filter<IRoom> = { _id };

const update: UpdateFilter<IRoom> = {
[value === true ? '$set' : '$unset']: {
'retention.ignoreThreads': true,
$set: {
'retention.ignoreThreads': value === true,
},
};

Expand Down
12 changes: 10 additions & 2 deletions apps/meteor/tests/e2e/page-objects/fragments/home-flextab-room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ export class HomeFlextabRoom {
}

get checkboxPruneMessages(): Locator {
return this.page.locator('label', { has: this.page.getByRole('checkbox', { name: 'Automatically prune old messages' }) });
return this.page
.getByRole('dialog')
.locator('label', { has: this.page.getByRole('checkbox', { name: 'Automatically prune old messages' }) });
}

get checkboxOverrideGlobalRetention(): Locator {
return this.page.locator('label', { has: this.page.getByRole('checkbox', { name: 'Override global retention policy' }) });
return this.page
.getByRole('dialog')
.locator('label', { has: this.page.getByRole('checkbox', { name: 'Override global retention policy' }) });
}

get checkboxIgnoreThreads(): Locator {
return this.page.getByRole('dialog').locator('label', { has: this.page.getByRole('checkbox', { name: 'Do not prune Threads' }) });
}
}
30 changes: 29 additions & 1 deletion apps/meteor/tests/e2e/retention-policy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { faker } from '@faker-js/faker';
import { createAuxContext } from './fixtures/createAuxContext';
import { Users } from './fixtures/userStates';
import { HomeChannel } from './page-objects';
import { createTargetPrivateChannel, createTargetTeam, setSettingValueById } from './utils';
import { createTargetTeam, createTargetPrivateChannel, getSettingValueById, setSettingValueById } from './utils';
import { test, expect } from './utils/test';

test.use({ storageState: Users.admin.state });
Expand Down Expand Up @@ -155,7 +155,10 @@ test.describe.serial('retention-policy', () => {
});

test.describe('retention policy override', () => {
let ignoreThreadsSetting: boolean;

test.beforeAll(async ({ api }) => {
ignoreThreadsSetting = (await getSettingValueById(api, 'RetentionPolicy_DoNotPruneThreads')) as boolean;
expect((await setSettingValueById(api, 'RetentionPolicy_MaxAge_Channels', 15)).status()).toBe(200);
});

Expand Down Expand Up @@ -186,6 +189,31 @@ test.describe.serial('retention-policy', () => {
await expect(poHomeChannel.tabs.room.getMaxAgeLabel('15')).toBeVisible();
await expect(poHomeChannel.tabs.room.inputRetentionMaxAge).toHaveValue('365');
});

test('should ignore threads be checked accordingly with the global default value', async () => {
await poHomeChannel.sidenav.openChat(targetChannel);
await poHomeChannel.tabs.btnRoomInfo.click();
await poHomeChannel.tabs.room.btnEdit.click();
await poHomeChannel.tabs.room.pruneAccordion.click();

await expect(poHomeChannel.tabs.room.checkboxIgnoreThreads).toBeChecked({ checked: ignoreThreadsSetting });
});

test('should override ignore threads default value', async () => {
await poHomeChannel.sidenav.openChat(targetChannel);
await poHomeChannel.tabs.btnRoomInfo.click();
await poHomeChannel.tabs.room.btnEdit.click();
await poHomeChannel.tabs.room.pruneAccordion.click();
await poHomeChannel.tabs.room.checkboxIgnoreThreads.click();
await poHomeChannel.tabs.room.btnSave.click();
await poHomeChannel.dismissToast();

await poHomeChannel.tabs.btnRoomInfo.click();
await poHomeChannel.tabs.room.btnEdit.click();
await poHomeChannel.tabs.room.pruneAccordion.click();

await expect(poHomeChannel.tabs.room.checkboxIgnoreThreads).toBeChecked({ checked: !ignoreThreadsSetting });
});
});
});
});

0 comments on commit 4a0480b

Please sign in to comment.