🛂(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.
This commit is contained in:
Anthony LC
2025-07-09 11:43:21 +02:00
parent d15285d385
commit cd366213ca
8 changed files with 65 additions and 12 deletions

View File

@@ -70,7 +70,6 @@ export interface Doc {
numchild: number;
updated_at: string;
user_role: Role;
user_roles: Role[];
abilities: {
accesses_manage: boolean;
accesses_view: boolean;

View File

@@ -11,7 +11,12 @@ import { css } from 'styled-components';
import { Box, BoxButton, Icon } from '@/components';
import { Doc, ModalRemoveDoc, useCopyDocLink } from '../../doc-management';
import {
Doc,
ModalRemoveDoc,
Role,
useCopyDocLink,
} from '../../doc-management';
import { useCreateChildrenDoc } from '../api/useCreateChildren';
import { useDetachDoc } from '../api/useDetach';
import MoveDocIcon from '../assets/doc-extract-bold.svg';
@@ -70,7 +75,7 @@ export const DocTreeItemActions = ({
? [
{
label: t('Move to my docs'),
isDisabled: !doc.abilities.move,
isDisabled: doc.user_role !== Role.OWNER,
icon: (
<Box
$css={css`

View File

@@ -136,7 +136,7 @@ export const DocGridContentList = ({ docs }: DocGridContentListProps) => {
const overlayText = useMemo(() => {
if (!canDrag) {
return t('You must have admin rights to move the document');
return t('You must be the owner to move the document');
}
if (!canDrop) {
return t('You must be at least the editor of the target document');

View File

@@ -9,7 +9,7 @@ import {
} from '@dnd-kit/core';
import { useState } from 'react';
import { Doc } from '@/docs/doc-management';
import { Doc, Role } from '@/docs/doc-management';
export type DocDragEndData = {
sourceDocumentId: string;
@@ -26,7 +26,7 @@ export function useDragAndDrop(onDrag: (data: DocDragEndData) => void) {
const [selectedDoc, setSelectedDoc] = useState<Doc>();
const [canDrop, setCanDrop] = useState<boolean>();
const canDrag = !!selectedDoc?.abilities.move;
const canDrag = selectedDoc?.user_role === Role.OWNER;
const mouseSensor = useSensor(MouseSensor, { activationConstraint });
const touchSensor = useSensor(TouchSensor, { activationConstraint });

View File

@@ -209,7 +209,6 @@ export class ApiPlugin implements WorkboxPlugin {
},
link_reach: LinkReach.RESTRICTED,
link_role: LinkRole.READER,
user_roles: [Role.OWNER],
user_role: Role.OWNER,
path: '',
computed_link_reach: LinkReach.RESTRICTED,