Skip to content

Commit ecd2f97

Browse files
committed
🐛(frontend) fix legacy role computation
Before the subpages feature, the user_role was computed thanks to the abilities. This is not the correct way to do it anymore, the abilities are now different. We now have "user_role" in the doc response which is the correct way to get the user role for the current document.
1 parent 90624e8 commit ecd2f97

File tree

6 files changed

+14
-76
lines changed

6 files changed

+14
-76
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ and this project adheres to
5353
### Fixed
5454

5555
- 🐛(frontend) fix callout emoji list #1366
56+
- 🐛(frontend) fix legacy role computation #1376
5657

5758
## [3.6.0] - 2025-09-04
5859

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,7 @@ test.describe('Doc Editor', () => {
238238

239239
test('it cannot edit if viewer', async ({ page }) => {
240240
await mockedDocument(page, {
241-
abilities: {
242-
destroy: false, // Means not owner
243-
link_configuration: false,
244-
versions_destroy: false,
245-
versions_list: true,
246-
versions_retrieve: true,
247-
accesses_manage: false, // Means not admin
248-
update: false,
249-
partial_update: false, // Means not editor
250-
retrieve: true,
251-
},
241+
user_role: 'reader',
252242
});
253243

254244
await goToGridDoc(page);
@@ -257,6 +247,9 @@ test.describe('Doc Editor', () => {
257247
await expect(card).toBeVisible();
258248

259249
await expect(card.getByText('Reader')).toBeVisible();
250+
251+
const editor = page.locator('.ProseMirror');
252+
await expect(editor).toHaveAttribute('contenteditable', 'false');
260253
});
261254

262255
test('it adds an image to the doc editor', async ({ page, browserName }) => {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ test.describe('Doc Tree', () => {
235235
'doc-tree-detach-child',
236236
);
237237

238+
await expect(
239+
page
240+
.getByLabel('It is the card information about the document.')
241+
.getByText('Administrator ·'),
242+
).toBeVisible();
243+
238244
const docTree = page.getByTestId('doc-tree');
239245
await expect(docTree.getByText(docChild)).toBeVisible();
240246
await docTree.click();

src/frontend/apps/impress/src/features/docs/doc-header/components/DocHeader.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
Doc,
88
LinkReach,
99
Role,
10-
currentDocRole,
1110
getDocLinkReach,
1211
useIsCollaborativeEditable,
1312
useTrans,
@@ -73,7 +72,7 @@ export const DocHeader = ({ doc }: DocHeaderProps) => {
7372
>
7473
{transRole(
7574
isEditable
76-
? currentDocRole(doc.abilities)
75+
? doc.user_role || doc.link_role
7776
: Role.READER,
7877
)}
7978
 · 

src/frontend/apps/impress/src/features/docs/doc-management/__tests__/utils.test.tsx

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { beforeEach, describe, expect, it, vi } from 'vitest';
22
import * as Y from 'yjs';
33

4-
import { LinkReach, LinkRole, Role } from '../types';
4+
import { LinkReach, LinkRole } from '../types';
55
import {
66
base64ToBlocknoteXmlFragment,
77
base64ToYDoc,
8-
currentDocRole,
98
getDocLinkReach,
109
getDocLinkRole,
1110
getEmojiAndTitle,
@@ -24,56 +23,6 @@ describe('doc-management utils', () => {
2423
vi.clearAllMocks();
2524
});
2625

27-
describe('currentDocRole', () => {
28-
it('should return OWNER when destroy ability is true', () => {
29-
const abilities = {
30-
destroy: true,
31-
accesses_manage: false,
32-
partial_update: false,
33-
} as any;
34-
35-
const result = currentDocRole(abilities);
36-
37-
expect(result).toBe(Role.OWNER);
38-
});
39-
40-
it('should return ADMIN when accesses_manage ability is true and destroy is false', () => {
41-
const abilities = {
42-
destroy: false,
43-
accesses_manage: true,
44-
partial_update: false,
45-
} as any;
46-
47-
const result = currentDocRole(abilities);
48-
49-
expect(result).toBe(Role.ADMIN);
50-
});
51-
52-
it('should return EDITOR when partial_update ability is true and higher abilities are false', () => {
53-
const abilities = {
54-
destroy: false,
55-
accesses_manage: false,
56-
partial_update: true,
57-
} as any;
58-
59-
const result = currentDocRole(abilities);
60-
61-
expect(result).toBe(Role.EDITOR);
62-
});
63-
64-
it('should return READER when no higher abilities are true', () => {
65-
const abilities = {
66-
destroy: false,
67-
accesses_manage: false,
68-
partial_update: false,
69-
} as any;
70-
71-
const result = currentDocRole(abilities);
72-
73-
expect(result).toBe(Role.READER);
74-
});
75-
});
76-
7726
describe('base64ToYDoc', () => {
7827
it('should convert base64 string to Y.Doc', () => {
7928
const base64String = 'dGVzdA=='; // "test" in base64

src/frontend/apps/impress/src/features/docs/doc-management/utils.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
import emojiRegex from 'emoji-regex';
22
import * as Y from 'yjs';
33

4-
import { Doc, LinkReach, LinkRole, Role } from './types';
5-
6-
export const currentDocRole = (abilities: Doc['abilities']): Role => {
7-
return abilities.destroy
8-
? Role.OWNER
9-
: abilities.accesses_manage
10-
? Role.ADMIN
11-
: abilities.partial_update
12-
? Role.EDITOR
13-
: Role.READER;
14-
};
4+
import { Doc, LinkReach, LinkRole } from './types';
155

166
export const base64ToYDoc = (base64: string) => {
177
const uint8Array = Buffer.from(base64, 'base64');

0 commit comments

Comments
 (0)