Skip to content

Commit cd36621

Browse files
committed
🛂(frontend) only owner can make a child doc a main doc
We get some side effects when an admin tries to make a child doc a main doc. We ensure that only the owner can do this.
1 parent d15285d commit cd36621

File tree

8 files changed

+65
-12
lines changed

8 files changed

+65
-12
lines changed

src/frontend/apps/e2e/__tests__/app-impress/common.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ export const mockedDocument = async (page: Page, data: object) => {
276276
ancestors_link_role: null,
277277
created_at: '2021-09-01T09:00:00Z',
278278
user_role: 'owner',
279-
user_roles: ['owner'],
280279
...doc,
281280
},
282281
});

src/frontend/apps/e2e/__tests__/app-impress/doc-grid-dnd.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ test.describe('Doc grid dnd', () => {
158158

159159
await expect(dragOverlay).toBeVisible();
160160
await expect(dragOverlay).toHaveText(
161-
'You must have admin rights to move the document',
161+
'You must be the owner to move the document',
162162
);
163163

164164
await page.mouse.up();

src/frontend/apps/e2e/__tests__/app-impress/doc-tree.spec.ts

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { expect, test } from '@playwright/test';
33

44
import {
5+
addNewMember,
56
createDoc,
67
expectLoginPage,
78
keyCloakSignIn,
@@ -12,8 +13,11 @@ import {
1213
import { clickOnAddRootSubPage, createRootSubPage } from './sub-pages-utils';
1314

1415
test.describe('Doc Tree', () => {
15-
test('create new sub pages', async ({ page, browserName }) => {
16+
test.beforeEach(async ({ page }) => {
1617
await page.goto('/');
18+
});
19+
20+
test('create new sub pages', async ({ page, browserName }) => {
1721
const [titleParent] = await createDoc(
1822
page,
1923
'doc-tree-content',
@@ -58,7 +62,6 @@ test.describe('Doc Tree', () => {
5862
});
5963

6064
test('check the reorder of sub pages', async ({ page, browserName }) => {
61-
await page.goto('/');
6265
await createDoc(page, 'doc-tree-content', browserName, 1);
6366
const addButton = page.getByRole('button', { name: 'New doc' });
6467
await expect(addButton).toBeVisible();
@@ -165,7 +168,6 @@ test.describe('Doc Tree', () => {
165168
});
166169

167170
test('it detaches a document', async ({ page, browserName }) => {
168-
await page.goto('/');
169171
const [docParent] = await createDoc(
170172
page,
171173
'doc-tree-detach',
@@ -202,6 +204,55 @@ test.describe('Doc Tree', () => {
202204
await header.locator('h2').getByText('Docs').click();
203205
await expect(page.getByText(docChild)).toBeVisible();
204206
});
207+
208+
test('Only owner can detaches a document', async ({ page, browserName }) => {
209+
const [docParent] = await createDoc(
210+
page,
211+
'doc-tree-detach',
212+
browserName,
213+
1,
214+
);
215+
216+
await verifyDocName(page, docParent);
217+
218+
await page.getByRole('button', { name: 'Share' }).click();
219+
220+
await addNewMember(page, 0, 'Owner', 'impress');
221+
222+
const list = page.getByTestId('doc-share-quick-search');
223+
const currentUser = list.getByTestId(
224+
`doc-share-member-row-user@${browserName}.test`,
225+
);
226+
const currentUserRole = currentUser.getByLabel('doc-role-dropdown');
227+
await currentUserRole.click();
228+
await page.getByLabel('Administrator').click();
229+
await list.click();
230+
231+
await page.getByRole('button', { name: 'Ok' }).click();
232+
233+
const { name: docChild } = await createRootSubPage(
234+
page,
235+
browserName,
236+
'doc-tree-detach-child',
237+
);
238+
239+
const docTree = page.getByTestId('doc-tree');
240+
await expect(docTree.getByText(docChild)).toBeVisible();
241+
await docTree.click();
242+
const child = docTree
243+
.getByRole('treeitem')
244+
.locator('.--docs-sub-page-item')
245+
.filter({
246+
hasText: docChild,
247+
});
248+
await child.hover();
249+
const menu = child.getByText(`more_horiz`);
250+
await menu.click();
251+
252+
await expect(
253+
page.getByRole('menuitem', { name: 'Move to my docs' }),
254+
).toHaveAttribute('aria-disabled', 'true');
255+
});
205256
});
206257

207258
test.describe('Doc Tree: Inheritance', () => {

src/frontend/apps/impress/src/features/docs/doc-management/types.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export interface Doc {
7070
numchild: number;
7171
updated_at: string;
7272
user_role: Role;
73-
user_roles: Role[];
7473
abilities: {
7574
accesses_manage: boolean;
7675
accesses_view: boolean;

src/frontend/apps/impress/src/features/docs/doc-tree/components/DocTreeItemActions.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import { css } from 'styled-components';
1111

1212
import { Box, BoxButton, Icon } from '@/components';
1313

14-
import { Doc, ModalRemoveDoc, useCopyDocLink } from '../../doc-management';
14+
import {
15+
Doc,
16+
ModalRemoveDoc,
17+
Role,
18+
useCopyDocLink,
19+
} from '../../doc-management';
1520
import { useCreateChildrenDoc } from '../api/useCreateChildren';
1621
import { useDetachDoc } from '../api/useDetach';
1722
import MoveDocIcon from '../assets/doc-extract-bold.svg';
@@ -70,7 +75,7 @@ export const DocTreeItemActions = ({
7075
? [
7176
{
7277
label: t('Move to my docs'),
73-
isDisabled: !doc.abilities.move,
78+
isDisabled: doc.user_role !== Role.OWNER,
7479
icon: (
7580
<Box
7681
$css={css`

src/frontend/apps/impress/src/features/docs/docs-grid/components/DocGridContentList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export const DocGridContentList = ({ docs }: DocGridContentListProps) => {
136136

137137
const overlayText = useMemo(() => {
138138
if (!canDrag) {
139-
return t('You must have admin rights to move the document');
139+
return t('You must be the owner to move the document');
140140
}
141141
if (!canDrop) {
142142
return t('You must be at least the editor of the target document');

src/frontend/apps/impress/src/features/docs/docs-grid/hooks/useDragAndDrop.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '@dnd-kit/core';
1010
import { useState } from 'react';
1111

12-
import { Doc } from '@/docs/doc-management';
12+
import { Doc, Role } from '@/docs/doc-management';
1313

1414
export type DocDragEndData = {
1515
sourceDocumentId: string;
@@ -26,7 +26,7 @@ export function useDragAndDrop(onDrag: (data: DocDragEndData) => void) {
2626
const [selectedDoc, setSelectedDoc] = useState<Doc>();
2727
const [canDrop, setCanDrop] = useState<boolean>();
2828

29-
const canDrag = !!selectedDoc?.abilities.move;
29+
const canDrag = selectedDoc?.user_role === Role.OWNER;
3030

3131
const mouseSensor = useSensor(MouseSensor, { activationConstraint });
3232
const touchSensor = useSensor(TouchSensor, { activationConstraint });

src/frontend/apps/impress/src/features/service-worker/plugins/ApiPlugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ export class ApiPlugin implements WorkboxPlugin {
209209
},
210210
link_reach: LinkReach.RESTRICTED,
211211
link_role: LinkRole.READER,
212-
user_roles: [Role.OWNER],
213212
user_role: Role.OWNER,
214213
path: '',
215214
computed_link_reach: LinkReach.RESTRICTED,

0 commit comments

Comments
 (0)