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: Hide prune section based on permission #32531

Merged
merged 2 commits into from
May 31, 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
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ const EditRoomInfo = ({ room, onClickClose, onClickBack }: EditRoomInfoProps) =>
</Field>
)}
</FieldGroup>
{retentionPolicy?.enabled && (
{canEditRoomRetentionPolicy && retentionPolicy?.enabled && (
<Accordion>
<Accordion.Item title={t('Prune')}>
<FieldGroup>
Expand All @@ -486,12 +486,7 @@ const EditRoomInfo = ({ room, onClickClose, onClickBack }: EditRoomInfoProps) =>
control={control}
name='retentionOverrideGlobal'
render={({ field: { value, ...field } }) => (
<ToggleSwitch
id={retentionOverrideGlobalField}
{...field}
disabled={!retentionEnabled || !canEditRoomRetentionPolicy}
checked={value}
/>
<ToggleSwitch id={retentionOverrideGlobalField} {...field} disabled={!retentionEnabled} checked={value} />
)}
/>
</FieldRow>
Expand Down
25 changes: 21 additions & 4 deletions apps/meteor/tests/e2e/retention-policy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { faker } from '@faker-js/faker';

import { createAuxContext } from './fixtures/createAuxContext';
import { Users } from './fixtures/userStates';
import { HomeChannel } from './page-objects';
import { createTargetChannel, createTargetPrivateChannel, createTargetTeam, setSettingValueById } from './utils';
import { 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;
const targetChannel = faker.string.uuid();
let targetTeam: string;
let targetGroup: string;

test.beforeAll(async ({ api }) => {
targetChannel = await createTargetChannel(api);
const response = await api.post('/channels.create', { name: targetChannel, members: ['user1'] });
const { channel } = await response.json();
await api.post('/channels.addOwner', { roomId: channel._id, userId: Users.user1.data._id });

targetGroup = await createTargetPrivateChannel(api);
targetTeam = await createTargetTeam(api);
})
Expand Down Expand Up @@ -48,7 +54,7 @@ test.describe.serial('retention-policy', () => {
test.describe('retention policy enabled', () => {
test.beforeAll(async ({ api }) => {
await setSettingValueById(api, 'RetentionPolicy_Enabled', true);
})
});
test.afterAll(async ({ api }) => {
await setSettingValueById(api, 'RetentionPolicy_Enabled', false);
await setSettingValueById(api, 'RetentionPolicy_AppliesToChannels', false);
Expand Down Expand Up @@ -79,6 +85,17 @@ test.describe.serial('retention-policy', () => {
await expect(poHomeChannel.tabs.room.pruneAccordion).toBeVisible();
});

test('should not show prune section in edit channel for users without permission', async ({ browser }) => {
const { page } = await createAuxContext(browser, Users.user1);
const auxContext = { page, poHomeChannel: new HomeChannel(page) };
await auxContext.poHomeChannel.sidenav.openChat(targetChannel);
await auxContext.poHomeChannel.tabs.btnRoomInfo.click();
await auxContext.poHomeChannel.tabs.room.btnEdit.click();

await expect(poHomeChannel.tabs.room.pruneAccordion).not.toBeVisible();
await auxContext.page.close();
})

test.describe('retention policy applies enabled by default', () => {
test.beforeAll(async ({ api }) => {
await setSettingValueById(api, 'RetentionPolicy_AppliesToChannels', true);
Expand Down
Loading