Skip to content

Commit 1e36091

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 b2ef219 commit 1e36091

File tree

6 files changed

+11
-8
lines changed

6 files changed

+11
-8
lines changed

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/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)