🐛(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:
@@ -238,17 +238,7 @@ test.describe('Doc Editor', () => {
|
||||
|
||||
test('it cannot edit if viewer', async ({ page }) => {
|
||||
await mockedDocument(page, {
|
||||
abilities: {
|
||||
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,
|
||||
},
|
||||
user_role: 'reader',
|
||||
});
|
||||
|
||||
await goToGridDoc(page);
|
||||
@@ -257,6 +247,9 @@ test.describe('Doc Editor', () => {
|
||||
await expect(card).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 }) => {
|
||||
|
||||
@@ -235,6 +235,12 @@ test.describe('Doc Tree', () => {
|
||||
'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');
|
||||
await expect(docTree.getByText(docChild)).toBeVisible();
|
||||
await docTree.click();
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
Doc,
|
||||
LinkReach,
|
||||
Role,
|
||||
currentDocRole,
|
||||
getDocLinkReach,
|
||||
useIsCollaborativeEditable,
|
||||
useTrans,
|
||||
@@ -73,7 +72,7 @@ export const DocHeader = ({ doc }: DocHeaderProps) => {
|
||||
>
|
||||
{transRole(
|
||||
isEditable
|
||||
? currentDocRole(doc.abilities)
|
||||
? doc.user_role || doc.link_role
|
||||
: Role.READER,
|
||||
)}
|
||||
·
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { LinkReach, LinkRole, Role } from '../types';
|
||||
import { LinkReach, LinkRole } from '../types';
|
||||
import {
|
||||
base64ToBlocknoteXmlFragment,
|
||||
base64ToYDoc,
|
||||
currentDocRole,
|
||||
getDocLinkReach,
|
||||
getDocLinkRole,
|
||||
getEmojiAndTitle,
|
||||
@@ -24,56 +23,6 @@ describe('doc-management utils', () => {
|
||||
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', () => {
|
||||
it('should convert base64 string to Y.Doc', () => {
|
||||
const base64String = 'dGVzdA=='; // "test" in base64
|
||||
|
||||
@@ -1,17 +1,7 @@
|
||||
import emojiRegex from 'emoji-regex';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { Doc, LinkReach, LinkRole, Role } 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;
|
||||
};
|
||||
import { Doc, LinkReach, LinkRole } from './types';
|
||||
|
||||
export const base64ToYDoc = (base64: string) => {
|
||||
const uint8Array = Buffer.from(base64, 'base64');
|
||||
|
||||
Reference in New Issue
Block a user