Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regression: Incorrect retention policy banner's display rule for teams #32483

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions apps/meteor/client/views/teams/contextualBar/info/TeamsInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@ import RetentionPolicyCallout from '../../../../components/InfoPanel/RetentionPo
import MarkdownText from '../../../../components/MarkdownText';
import type { Action } from '../../../hooks/useActionSpread';
import { useActionSpread } from '../../../hooks/useActionSpread';

type RetentionPolicy = {
retentionPolicyEnabled: boolean;
maxAgeDefault: number;
retentionEnabledDefault: boolean;
excludePinnedDefault: boolean;
filesOnlyDefault: boolean;
};
import { useRetentionPolicy } from '../../../room/hooks/useRetentionPolicy';

type TeamsInfoProps = {
room: IRoom;
retentionPolicy: RetentionPolicy;
onClickHide: () => void;
onClickClose: () => void;
onClickLeave: () => void;
Expand All @@ -40,7 +32,6 @@ type TeamsInfoProps = {

const TeamsInfo = ({
room,
retentionPolicy,
onClickHide,
onClickClose,
onClickLeave,
Expand All @@ -51,7 +42,7 @@ const TeamsInfo = ({
}: TeamsInfoProps): ReactElement => {
const t = useTranslation();

const { retentionPolicyEnabled, filesOnlyDefault, excludePinnedDefault, maxAgeDefault } = retentionPolicy;
const retentionPolicy = useRetentionPolicy(room);

const memoizedActions = useMemo(
() => ({
Expand Down Expand Up @@ -199,8 +190,12 @@ const TeamsInfo = ({
</InfoPanel.Field>
)}

{retentionPolicyEnabled && (
<RetentionPolicyCallout filesOnly={filesOnlyDefault} excludePinned={excludePinnedDefault} maxAge={maxAgeDefault} />
{retentionPolicy?.isActive && (
<RetentionPolicyCallout
filesOnly={retentionPolicy.filesOnly}
excludePinned={retentionPolicy.excludePinned}
maxAge={retentionPolicy.maxAge}
/>
)}
</InfoPanel.Section>
</InfoPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
useSetModal,
useToastMessageDispatch,
useUserId,
useSetting,
usePermission,
useMethod,
useTranslation,
Expand All @@ -23,33 +22,12 @@ import ConvertToChannelModal from '../../ConvertToChannelModal';
import LeaveTeam from './LeaveTeam';
import TeamsInfo from './TeamsInfo';

const retentionPolicyMaxAge = {
c: 'RetentionPolicy_MaxAge_Channels',
p: 'RetentionPolicy_MaxAge_Groups',
d: 'RetentionPolicy_MaxAge_DMs',
};

const retentionPolicyAppliesTo = {
c: 'RetentionPolicy_AppliesToChannels',
p: 'RetentionPolicy_AppliesToGroups',
d: 'RetentionPolicy_AppliesToDMs',
};

const TeamsInfoWithLogic = ({ openEditing }) => {
const room = useRoom();
const { openTab, closeTab } = useRoomToolbox();
const t = useTranslation();
const userId = useUserId();

const retentionPolicyEnabled = useSetting('RetentionPolicy_Enabled');
const retentionPolicy = {
retentionPolicyEnabled,
maxAgeDefault: useSetting(retentionPolicyMaxAge[room.t]) || 30,
retentionEnabledDefault: useSetting(retentionPolicyAppliesTo[room.t]),
excludePinnedDefault: useSetting('RetentionPolicy_DoNotPrunePinned'),
filesOnlyDefault: useSetting('RetentionPolicy_FilesOnly'),
};

const dontAskHideRoom = useDontAskAgain('hideRoom');

const dispatchToastMessage = useToastMessageDispatch();
Expand Down Expand Up @@ -153,7 +131,6 @@ const TeamsInfoWithLogic = ({ openEditing }) => {
return (
<TeamsInfo
room={room}
retentionPolicy={retentionPolicyEnabled && retentionPolicy}
onClickEdit={canEdit && openEditing}
onClickClose={closeTab}
onClickDelete={canDeleteRoom && handleDelete}
Expand Down
23 changes: 22 additions & 1 deletion apps/meteor/tests/e2e/retention-policy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { Users } from './fixtures/userStates';
import { HomeChannel } from './page-objects';
import { createTargetChannel, createTargetPrivateChannel, setSettingValueById } from './utils';
import { createTargetChannel, createTargetPrivateChannel, createTargetTeam, setSettingValueById } from './utils';
import { test, expect } from './utils/test';

test.use({ storageState: Users.admin.state });

test.describe.serial('retention-policy', () => {
let poHomeChannel: HomeChannel;
let targetChannel: string;
let targetTeam: string;
let targetGroup: string;

test.beforeAll(async ({ api }) => {
targetChannel = await createTargetChannel(api);
targetGroup = await createTargetPrivateChannel(api);
targetTeam = await createTargetTeam(api);
})

test.beforeEach(async ({ page }) => {
Expand All @@ -28,6 +30,12 @@ test.describe.serial('retention-policy', () => {
await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible();
});

test('should not show prune banner in team', async () => {
await poHomeChannel.sidenav.openChat(targetTeam);

await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible();
});

test('should not show prune section on edit channel', async () => {
await poHomeChannel.sidenav.openChat(targetChannel);
await poHomeChannel.tabs.btnRoomInfo.click();
Expand All @@ -53,6 +61,9 @@ test.describe.serial('retention-policy', () => {
await poHomeChannel.sidenav.openChat(targetChannel);
await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible();

await poHomeChannel.sidenav.openChat(targetTeam);
await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible();

await poHomeChannel.sidenav.openChat(targetGroup);
await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible();

Expand Down Expand Up @@ -85,6 +96,16 @@ test.describe.serial('retention-policy', () => {
await expect(poHomeChannel.tabs.room.checkboxPruneMessages).toBeChecked();
});

test('should prune old messages checkbox enabled by default in team and show retention policy banner', async () => {
await poHomeChannel.sidenav.openChat(targetTeam);
await expect(poHomeChannel.content.channelRetentionPolicyWarning).toBeVisible();

await poHomeChannel.tabs.btnRoomInfo.click();
await poHomeChannel.tabs.room.btnEdit.click();
await poHomeChannel.tabs.room.pruneAccordion.click();
await expect(poHomeChannel.tabs.room.checkboxPruneMessages).toBeChecked();
});

test('should prune old messages checkbox enabled by default in group and show retention policy banner', async () => {
await poHomeChannel.sidenav.openChat(targetGroup);
await expect(poHomeChannel.content.channelRetentionPolicyWarning).toBeVisible();
Expand Down
Loading