diff --git a/CHANGELOG.md b/CHANGELOG.md index aeac32e7..e3e489dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ and this project adheres to ### Fixed - ๐Ÿ›(frontend) fix callout emoji list #1366 +- ๐Ÿ›(frontend) fix legacy role computation #1376 ## [3.6.0] - 2025-09-04 diff --git a/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts index 06a273ae..552680be 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts @@ -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 }) => { diff --git a/src/frontend/apps/e2e/__tests__/app-impress/doc-tree.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/doc-tree.spec.ts index 0b065f68..afde7808 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/doc-tree.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/doc-tree.spec.ts @@ -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(); diff --git a/src/frontend/apps/impress/src/features/docs/doc-header/components/DocHeader.tsx b/src/frontend/apps/impress/src/features/docs/doc-header/components/DocHeader.tsx index bd152eb7..7074ad67 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-header/components/DocHeader.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-header/components/DocHeader.tsx @@ -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, )}  ยท  diff --git a/src/frontend/apps/impress/src/features/docs/doc-management/__tests__/utils.test.tsx b/src/frontend/apps/impress/src/features/docs/doc-management/__tests__/utils.test.tsx index 350673fb..37b911d8 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-management/__tests__/utils.test.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-management/__tests__/utils.test.tsx @@ -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 diff --git a/src/frontend/apps/impress/src/features/docs/doc-management/utils.ts b/src/frontend/apps/impress/src/features/docs/doc-management/utils.ts index 6a616007..1f1a68b9 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-management/utils.ts +++ b/src/frontend/apps/impress/src/features/docs/doc-management/utils.ts @@ -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');