🐛(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.
This commit is contained in:
@@ -53,6 +53,7 @@ and this project adheres to
|
|||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- 🐛(frontend) fix callout emoji list #1366
|
- 🐛(frontend) fix callout emoji list #1366
|
||||||
|
- 🐛(frontend) fix legacy role computation #1376
|
||||||
|
|
||||||
## [3.6.0] - 2025-09-04
|
## [3.6.0] - 2025-09-04
|
||||||
|
|
||||||
|
|||||||
@@ -238,17 +238,7 @@ test.describe('Doc Editor', () => {
|
|||||||
|
|
||||||
test('it cannot edit if viewer', async ({ page }) => {
|
test('it cannot edit if viewer', async ({ page }) => {
|
||||||
await mockedDocument(page, {
|
await mockedDocument(page, {
|
||||||
abilities: {
|
user_role: 'reader',
|
||||||
destroy: false, // Means not owner
|
|
||||||
link_configuration: false,
|
|
||||||
versions_destroy: false,
|
|
||||||
versions_list: true,
|
|
||||||
versions_retrieve: true,
|
|
||||||
accesses_manage: false, // Means not admin
|
|
||||||
update: false,
|
|
||||||
partial_update: false, // Means not editor
|
|
||||||
retrieve: true,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await goToGridDoc(page);
|
await goToGridDoc(page);
|
||||||
@@ -257,6 +247,9 @@ test.describe('Doc Editor', () => {
|
|||||||
await expect(card).toBeVisible();
|
await expect(card).toBeVisible();
|
||||||
|
|
||||||
await expect(card.getByText('Reader')).toBeVisible();
|
await expect(card.getByText('Reader')).toBeVisible();
|
||||||
|
|
||||||
|
const editor = page.locator('.ProseMirror');
|
||||||
|
await expect(editor).toHaveAttribute('contenteditable', 'false');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it adds an image to the doc editor', async ({ page, browserName }) => {
|
test('it adds an image to the doc editor', async ({ page, browserName }) => {
|
||||||
|
|||||||
@@ -235,6 +235,12 @@ test.describe('Doc Tree', () => {
|
|||||||
'doc-tree-detach-child',
|
'doc-tree-detach-child',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
page
|
||||||
|
.getByLabel('It is the card information about the document.')
|
||||||
|
.getByText('Administrator ·'),
|
||||||
|
).toBeVisible();
|
||||||
|
|
||||||
const docTree = page.getByTestId('doc-tree');
|
const docTree = page.getByTestId('doc-tree');
|
||||||
await expect(docTree.getByText(docChild)).toBeVisible();
|
await expect(docTree.getByText(docChild)).toBeVisible();
|
||||||
await docTree.click();
|
await docTree.click();
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
Doc,
|
Doc,
|
||||||
LinkReach,
|
LinkReach,
|
||||||
Role,
|
Role,
|
||||||
currentDocRole,
|
|
||||||
getDocLinkReach,
|
getDocLinkReach,
|
||||||
useIsCollaborativeEditable,
|
useIsCollaborativeEditable,
|
||||||
useTrans,
|
useTrans,
|
||||||
@@ -73,7 +72,7 @@ export const DocHeader = ({ doc }: DocHeaderProps) => {
|
|||||||
>
|
>
|
||||||
{transRole(
|
{transRole(
|
||||||
isEditable
|
isEditable
|
||||||
? currentDocRole(doc.abilities)
|
? doc.user_role || doc.link_role
|
||||||
: Role.READER,
|
: Role.READER,
|
||||||
)}
|
)}
|
||||||
·
|
·
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
import { LinkReach, LinkRole, Role } from '../types';
|
import { LinkReach, LinkRole } from '../types';
|
||||||
import {
|
import {
|
||||||
base64ToBlocknoteXmlFragment,
|
base64ToBlocknoteXmlFragment,
|
||||||
base64ToYDoc,
|
base64ToYDoc,
|
||||||
currentDocRole,
|
|
||||||
getDocLinkReach,
|
getDocLinkReach,
|
||||||
getDocLinkRole,
|
getDocLinkRole,
|
||||||
getEmojiAndTitle,
|
getEmojiAndTitle,
|
||||||
@@ -24,56 +23,6 @@ describe('doc-management utils', () => {
|
|||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('currentDocRole', () => {
|
|
||||||
it('should return OWNER when destroy ability is true', () => {
|
|
||||||
const abilities = {
|
|
||||||
destroy: true,
|
|
||||||
accesses_manage: false,
|
|
||||||
partial_update: false,
|
|
||||||
} as any;
|
|
||||||
|
|
||||||
const result = currentDocRole(abilities);
|
|
||||||
|
|
||||||
expect(result).toBe(Role.OWNER);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return ADMIN when accesses_manage ability is true and destroy is false', () => {
|
|
||||||
const abilities = {
|
|
||||||
destroy: false,
|
|
||||||
accesses_manage: true,
|
|
||||||
partial_update: false,
|
|
||||||
} as any;
|
|
||||||
|
|
||||||
const result = currentDocRole(abilities);
|
|
||||||
|
|
||||||
expect(result).toBe(Role.ADMIN);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return EDITOR when partial_update ability is true and higher abilities are false', () => {
|
|
||||||
const abilities = {
|
|
||||||
destroy: false,
|
|
||||||
accesses_manage: false,
|
|
||||||
partial_update: true,
|
|
||||||
} as any;
|
|
||||||
|
|
||||||
const result = currentDocRole(abilities);
|
|
||||||
|
|
||||||
expect(result).toBe(Role.EDITOR);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return READER when no higher abilities are true', () => {
|
|
||||||
const abilities = {
|
|
||||||
destroy: false,
|
|
||||||
accesses_manage: false,
|
|
||||||
partial_update: false,
|
|
||||||
} as any;
|
|
||||||
|
|
||||||
const result = currentDocRole(abilities);
|
|
||||||
|
|
||||||
expect(result).toBe(Role.READER);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('base64ToYDoc', () => {
|
describe('base64ToYDoc', () => {
|
||||||
it('should convert base64 string to Y.Doc', () => {
|
it('should convert base64 string to Y.Doc', () => {
|
||||||
const base64String = 'dGVzdA=='; // "test" in base64
|
const base64String = 'dGVzdA=='; // "test" in base64
|
||||||
|
|||||||
@@ -1,17 +1,7 @@
|
|||||||
import emojiRegex from 'emoji-regex';
|
import emojiRegex from 'emoji-regex';
|
||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
import { Doc, LinkReach, LinkRole, Role } from './types';
|
import { Doc, LinkReach, LinkRole } from './types';
|
||||||
|
|
||||||
export const currentDocRole = (abilities: Doc['abilities']): Role => {
|
|
||||||
return abilities.destroy
|
|
||||||
? Role.OWNER
|
|
||||||
: abilities.accesses_manage
|
|
||||||
? Role.ADMIN
|
|
||||||
: abilities.partial_update
|
|
||||||
? Role.EDITOR
|
|
||||||
: Role.READER;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const base64ToYDoc = (base64: string) => {
|
export const base64ToYDoc = (base64: string) => {
|
||||||
const uint8Array = Buffer.from(base64, 'base64');
|
const uint8Array = Buffer.from(base64, 'base64');
|
||||||
|
|||||||
Reference in New Issue
Block a user