Skip to content

Commit 0a10642

Browse files
committed
🛂(frontend) blocked edition if multiple ancestors
With child documents we need to check the parent documents to know if the parent doc are collaborative or not.
1 parent 1d01f65 commit 0a10642

File tree

3 files changed

+48
-32
lines changed

3 files changed

+48
-32
lines changed

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
overrideConfig,
1111
verifyDocName,
1212
} from './common';
13+
import { createRootSubPage } from './sub-pages-utils';
1314

1415
test.beforeEach(async ({ page }) => {
1516
await page.goto('/');
@@ -524,6 +525,8 @@ test.describe('Doc Editor', () => {
524525
page,
525526
browserName,
526527
}) => {
528+
test.slow();
529+
527530
/**
528531
* The good port is 4444, but we want to simulate a not connected
529532
* collaborative server.
@@ -536,7 +539,12 @@ test.describe('Doc Editor', () => {
536539

537540
await page.goto('/');
538541

539-
const [title] = await createDoc(page, 'editing-blocking', browserName, 1);
542+
const [parentTitle] = await createDoc(
543+
page,
544+
'editing-blocking',
545+
browserName,
546+
1,
547+
);
540548

541549
const card = page.getByLabel('It is the card information');
542550
await expect(
@@ -571,12 +579,20 @@ test.describe('Doc Editor', () => {
571579
// Close the modal
572580
await page.getByRole('button', { name: 'close' }).first().click();
573581

582+
const urlParentDoc = page.url();
583+
584+
const { name: childTitle } = await createRootSubPage(
585+
page,
586+
browserName,
587+
'editing-blocking - child',
588+
);
589+
574590
let responseCanEdit = await responseCanEditPromise;
575591
expect(responseCanEdit.ok()).toBeTruthy();
576592
let jsonCanEdit = (await responseCanEdit.json()) as { can_edit: boolean };
577593
expect(jsonCanEdit.can_edit).toBeTruthy();
578594

579-
const urlDoc = page.url();
595+
const urlChildDoc = page.url();
580596

581597
/**
582598
* We open another browser that will connect to the collaborative server
@@ -603,14 +619,14 @@ test.describe('Doc Editor', () => {
603619
},
604620
);
605621

606-
await otherPage.goto(urlDoc);
622+
await otherPage.goto(urlChildDoc);
607623

608624
const webSocket = await webSocketPromise;
609625
expect(webSocket.url()).toContain(
610626
'ws://localhost:4444/collaboration/ws/?room=',
611627
);
612628

613-
await verifyDocName(otherPage, title);
629+
await verifyDocName(otherPage, childTitle);
614630

615631
await page.reload();
616632

@@ -633,6 +649,10 @@ test.describe('Doc Editor', () => {
633649

634650
await expect(editor).toHaveAttribute('contenteditable', 'false');
635651

652+
await page.goto(urlParentDoc);
653+
654+
await verifyDocName(page, parentTitle);
655+
636656
await page.getByRole('button', { name: 'Share' }).click();
637657

638658
await page.getByLabel('Visibility mode').click();
@@ -641,18 +661,9 @@ test.describe('Doc Editor', () => {
641661
// Close the modal
642662
await page.getByRole('button', { name: 'close' }).first().click();
643663

644-
await page.reload();
645-
646-
responseCanEditPromise = page.waitForResponse(
647-
(response) =>
648-
response.url().includes(`/can-edit/`) && response.status() === 200,
649-
);
664+
await page.goto(urlChildDoc);
650665

651-
responseCanEdit = await responseCanEditPromise;
652-
expect(responseCanEdit.ok()).toBeTruthy();
653-
654-
jsonCanEdit = (await responseCanEdit.json()) as { can_edit: boolean };
655-
expect(jsonCanEdit.can_edit).toBeTruthy();
666+
await expect(editor).toHaveAttribute('contenteditable', 'true');
656667

657668
await expect(
658669
card.getByText('Others are editing. Your network prevent changes.'),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ test.describe('Doc Visibility: Authenticated', () => {
441441
const { name: childTitle } = await createRootSubPage(
442442
page,
443443
browserName,
444-
'Authenticated read onlyc - child',
444+
'Authenticated read only - child',
445445
);
446446

447447
const urlChildDoc = page.url();

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,44 @@ import { useIsOffline } from '@/features/service-worker';
55

66
import { KEY_CAN_EDIT, useDocCanEdit } from '../api/useDocCanEdit';
77
import { useProviderStore } from '../stores';
8-
import { Doc, LinkReach } from '../types';
8+
import { Doc, LinkReach, LinkRole } from '../types';
99

1010
export const useIsCollaborativeEditable = (doc: Doc) => {
1111
const { isConnected } = useProviderStore();
1212
const { data: conf } = useConfig();
1313

14-
const docIsPublic = doc.link_reach === LinkReach.PUBLIC;
15-
const docIsAuth = doc.link_reach === LinkReach.AUTHENTICATED;
16-
const docHasMember = doc.nb_accesses_direct > 1;
14+
const docIsPublic =
15+
doc.computed_link_reach === LinkReach.PUBLIC &&
16+
doc.computed_link_role === LinkRole.EDITOR;
17+
const docIsAuth =
18+
doc.computed_link_reach === LinkReach.AUTHENTICATED &&
19+
doc.computed_link_role === LinkRole.EDITOR;
20+
const docHasMember =
21+
doc.nb_accesses_direct > 1 || doc.nb_accesses_ancestors > 1;
1722
const isUserReader = !doc.abilities.partial_update;
1823
const isShared = docIsPublic || docIsAuth || docHasMember;
1924
const { isOffline } = useIsOffline();
2025
const _isEditable = isUserReader || isConnected || !isShared || isOffline;
2126
const [isEditable, setIsEditable] = useState(true);
2227
const [isLoading, setIsLoading] = useState(!_isEditable);
2328
const timeout = useRef<NodeJS.Timeout | null>(null);
24-
const {
25-
data: { can_edit } = { can_edit: _isEditable },
26-
isLoading: isLoadingCanEdit,
27-
} = useDocCanEdit(doc.id, {
28-
enabled: !_isEditable,
29-
queryKey: [KEY_CAN_EDIT, doc.id],
30-
staleTime: 0,
31-
});
29+
const { data: editingRight, isLoading: isLoadingCanEdit } = useDocCanEdit(
30+
doc.id,
31+
{
32+
enabled: !_isEditable,
33+
queryKey: [KEY_CAN_EDIT, doc.id],
34+
staleTime: 0,
35+
},
36+
);
3237

3338
useEffect(() => {
34-
if (isLoadingCanEdit) {
39+
if (isLoadingCanEdit || _isEditable || !editingRight) {
3540
return;
3641
}
3742

3843
// Connection to the WebSocket can take some time, so we set a timeout to ensure the loading state is cleared after a reasonable time.
3944
timeout.current = setTimeout(() => {
40-
setIsEditable(can_edit);
45+
setIsEditable(editingRight.can_edit);
4146
setIsLoading(false);
4247
}, 1500);
4348

@@ -46,7 +51,7 @@ export const useIsCollaborativeEditable = (doc: Doc) => {
4651
clearTimeout(timeout.current);
4752
}
4853
};
49-
}, [can_edit, isLoadingCanEdit]);
54+
}, [editingRight, isLoadingCanEdit, _isEditable]);
5055

5156
useEffect(() => {
5257
if (!_isEditable) {
@@ -59,7 +64,7 @@ export const useIsCollaborativeEditable = (doc: Doc) => {
5964

6065
setIsEditable(true);
6166
setIsLoading(false);
62-
}, [_isEditable, isLoading]);
67+
}, [_isEditable]);
6368

6469
if (!conf?.COLLABORATION_WS_NOT_CONNECTED_READY_ONLY) {
6570
return {

0 commit comments

Comments
 (0)