🐛(frontend) fix toolbar not activated when reader
When user was a reader of the document, the toolbar of the BlockNote editor was not activated, making it impossible to download resources like images. We add the toolbar even in viewer mode. We block as well automatic document mutation from custom blocks when the editor is in viewer mode to avoid unwanted modifications.
This commit is contained in:
10
CHANGELOG.md
10
CHANGELOG.md
@@ -6,10 +6,17 @@ and this project adheres to
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- ✨ Add comments feature to the editor #1330
|
||||||
|
- ✨(backend) Comments on text editor #1330
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- ♿(frontend) improve accessibility:
|
- ♿(frontend) improve accessibility:
|
||||||
- ♿(frontend) improve share modal button accessibility #1626
|
- ♿(frontend) improve share modal button accessibility #1626
|
||||||
|
- 🐛(frontend) fix toolbar not activated when reader #1640
|
||||||
|
- 🐛(frontend) preserve left panel width on window resize #1588
|
||||||
|
|
||||||
## [3.10.0] - 2025-11-18
|
## [3.10.0] - 2025-11-18
|
||||||
|
|
||||||
@@ -40,7 +47,6 @@ and this project adheres to
|
|||||||
### Security
|
### Security
|
||||||
|
|
||||||
- mitigate role escalation in the ask_for_access viewset #1580
|
- mitigate role escalation in the ask_for_access viewset #1580
|
||||||
- 🐛(frontend) preserve left panel width on window resize #1588
|
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
@@ -54,7 +60,6 @@ and this project adheres to
|
|||||||
- ✨(frontend) create skeleton component for DocEditor #1491
|
- ✨(frontend) create skeleton component for DocEditor #1491
|
||||||
- ✨(frontend) add an EmojiPicker in the document tree and title #1381
|
- ✨(frontend) add an EmojiPicker in the document tree and title #1381
|
||||||
- ✨(frontend) ajustable left panel #1456
|
- ✨(frontend) ajustable left panel #1456
|
||||||
- ✨ Add comments feature to the editor #1330
|
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
@@ -183,7 +188,6 @@ and this project adheres to
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- ✨(backend) Comments on text editor #1309
|
|
||||||
- 👷(CI) add bundle size check job #1268
|
- 👷(CI) add bundle size check job #1268
|
||||||
- ✨(frontend) use title first emoji as doc icon in tree #1289
|
- ✨(frontend) use title first emoji as doc icon in tree #1289
|
||||||
|
|
||||||
|
|||||||
@@ -241,20 +241,66 @@ test.describe('Doc Editor', () => {
|
|||||||
await expect(editor.getByText('Hello World Doc persisted 2')).toBeVisible();
|
await expect(editor.getByText('Hello World Doc persisted 2')).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it cannot edit if viewer', async ({ page }) => {
|
test('it cannot edit if viewer but see and can get resources', async ({
|
||||||
await mockedDocument(page, {
|
page,
|
||||||
user_role: 'reader',
|
browserName,
|
||||||
|
}) => {
|
||||||
|
const [docTitle] = await createDoc(page, 'doc-viewer', browserName, 1);
|
||||||
|
await verifyDocName(page, docTitle);
|
||||||
|
|
||||||
|
await writeInEditor({ page, text: 'Hello World' });
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: 'Share' }).click();
|
||||||
|
await updateShareLink(page, 'Public', 'Reading');
|
||||||
|
|
||||||
|
// Close the modal
|
||||||
|
await page.getByRole('button', { name: 'close' }).first().click();
|
||||||
|
|
||||||
|
const { otherPage, cleanup } = await connectOtherUserToDoc({
|
||||||
|
browserName,
|
||||||
|
docUrl: page.url(),
|
||||||
|
withoutSignIn: true,
|
||||||
|
docTitle,
|
||||||
});
|
});
|
||||||
|
|
||||||
await goToGridDoc(page);
|
await expect(
|
||||||
|
otherPage.getByLabel('It is the card information').getByText('Reader'),
|
||||||
|
).toBeVisible();
|
||||||
|
|
||||||
const card = page.getByLabel('It is the card information');
|
// Cannot edit
|
||||||
await expect(card).toBeVisible();
|
const editor = otherPage.locator('.ProseMirror');
|
||||||
|
|
||||||
await expect(card.getByText('Reader')).toBeVisible();
|
|
||||||
|
|
||||||
const editor = page.locator('.ProseMirror');
|
|
||||||
await expect(editor).toHaveAttribute('contenteditable', 'false');
|
await expect(editor).toHaveAttribute('contenteditable', 'false');
|
||||||
|
|
||||||
|
// Owner add a image
|
||||||
|
const fileChooserPromise = page.waitForEvent('filechooser');
|
||||||
|
await page.locator('.bn-block-outer').last().fill('/');
|
||||||
|
await page.getByText('Resizable image with caption').click();
|
||||||
|
await page.getByText('Upload image').click();
|
||||||
|
|
||||||
|
const fileChooser = await fileChooserPromise;
|
||||||
|
await fileChooser.setFiles(
|
||||||
|
path.join(__dirname, 'assets/logo-suite-numerique.png'),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Owner see the image
|
||||||
|
await expect(
|
||||||
|
page.locator('.--docs--editor-container img.bn-visual-media').first(),
|
||||||
|
).toBeVisible();
|
||||||
|
|
||||||
|
// Viewser see the image
|
||||||
|
const viewerImg = otherPage
|
||||||
|
.locator('.--docs--editor-container img.bn-visual-media')
|
||||||
|
.first();
|
||||||
|
await expect(viewerImg).toBeVisible();
|
||||||
|
|
||||||
|
// Viewer can download the image
|
||||||
|
await viewerImg.click();
|
||||||
|
const downloadPromise = otherPage.waitForEvent('download');
|
||||||
|
await otherPage.getByRole('button', { name: 'Download image' }).click();
|
||||||
|
const download = await downloadPromise;
|
||||||
|
expect(download.suggestedFilename()).toBe('logo-suite-numerique.png');
|
||||||
|
|
||||||
|
await cleanup();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it adds an image to the doc editor', async ({ page, browserName }) => {
|
test('it adds an image to the doc editor', async ({ page, browserName }) => {
|
||||||
|
|||||||
@@ -289,11 +289,13 @@ export const BlockNoteReader = ({
|
|||||||
editor={editor}
|
editor={editor}
|
||||||
editable={false}
|
editable={false}
|
||||||
theme="light"
|
theme="light"
|
||||||
aria-label={t('Document version viewer')}
|
aria-label={t('Document viewer')}
|
||||||
formattingToolbar={false}
|
formattingToolbar={false}
|
||||||
slashMenu={false}
|
slashMenu={false}
|
||||||
comments={false}
|
comments={false}
|
||||||
/>
|
>
|
||||||
|
<BlockNoteToolbar />
|
||||||
|
</BlockNoteView>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -59,9 +59,15 @@ const UploadLoaderBlockComponent = ({
|
|||||||
editor,
|
editor,
|
||||||
}: UploadLoaderBlockComponentProps) => {
|
}: UploadLoaderBlockComponentProps) => {
|
||||||
const mediaUrl = useMediaUrl();
|
const mediaUrl = useMediaUrl();
|
||||||
|
const isEditable = editor.isEditable;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!block.props.blockUploadUrl || block.props.type !== 'loading') {
|
const shouldCheckStatus =
|
||||||
|
block.props.blockUploadUrl &&
|
||||||
|
block.props.type === 'loading' &&
|
||||||
|
isEditable;
|
||||||
|
|
||||||
|
if (!shouldCheckStatus) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +114,7 @@ const UploadLoaderBlockComponent = ({
|
|||||||
/* During collaboration, another user might have updated the block */
|
/* During collaboration, another user might have updated the block */
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [block, editor, mediaUrl]);
|
}, [block, editor, mediaUrl, isEditable]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className="bn-visual-media-wrapper" $direction="row" $gap="0.5rem">
|
<Box className="bn-visual-media-wrapper" $direction="row" $gap="0.5rem">
|
||||||
|
|||||||
@@ -26,14 +26,19 @@ export const InterlinkingLinkInlineContent = createReactInlineContentSpec(
|
|||||||
content: 'none',
|
content: 'none',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
render: ({ inlineContent, updateInlineContent }) => {
|
render: ({ editor, inlineContent, updateInlineContent }) => {
|
||||||
const { data: doc } = useDoc({ id: inlineContent.props.docId });
|
const { data: doc } = useDoc({ id: inlineContent.props.docId });
|
||||||
|
const isEditable = editor.isEditable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the content title if the referenced doc title changes
|
* Update the content title if the referenced doc title changes
|
||||||
*/
|
*/
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (doc?.title && doc.title !== inlineContent.props.title) {
|
if (
|
||||||
|
isEditable &&
|
||||||
|
doc?.title &&
|
||||||
|
doc.title !== inlineContent.props.title
|
||||||
|
) {
|
||||||
updateInlineContent({
|
updateInlineContent({
|
||||||
type: 'interlinkingLinkInline',
|
type: 'interlinkingLinkInline',
|
||||||
props: {
|
props: {
|
||||||
@@ -50,7 +55,7 @@ export const InterlinkingLinkInlineContent = createReactInlineContentSpec(
|
|||||||
* not when inlineContent.props.title changes.
|
* not when inlineContent.props.title changes.
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [doc?.title]);
|
}, [doc?.title, isEditable]);
|
||||||
|
|
||||||
return <LinkSelected {...inlineContent.props} />;
|
return <LinkSelected {...inlineContent.props} />;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ export const SearchPage = ({
|
|||||||
const [search, setSearch] = useState('');
|
const [search, setSearch] = useState('');
|
||||||
const { isDesktop } = useResponsiveStore();
|
const { isDesktop } = useResponsiveStore();
|
||||||
const { untitledDocument } = useTrans();
|
const { untitledDocument } = useTrans();
|
||||||
|
const isEditable = editor.isEditable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* createReactInlineContentSpec add automatically the focus after
|
* createReactInlineContentSpec add automatically the focus after
|
||||||
@@ -101,6 +102,10 @@ export const SearchPage = ({
|
|||||||
}, [inputRef]);
|
}, [inputRef]);
|
||||||
|
|
||||||
const closeSearch = (insertContent: string) => {
|
const closeSearch = (insertContent: string) => {
|
||||||
|
if (!isEditable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
updateInlineContent({
|
updateInlineContent({
|
||||||
type: 'interlinkingSearchInline',
|
type: 'interlinkingSearchInline',
|
||||||
props: {
|
props: {
|
||||||
@@ -223,6 +228,10 @@ export const SearchPage = ({
|
|||||||
search={search}
|
search={search}
|
||||||
filters={{ target: DocSearchTarget.CURRENT }}
|
filters={{ target: DocSearchTarget.CURRENT }}
|
||||||
onSelect={(doc) => {
|
onSelect={(doc) => {
|
||||||
|
if (!isEditable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
updateInlineContent({
|
updateInlineContent({
|
||||||
type: 'interlinkingSearchInline',
|
type: 'interlinkingSearchInline',
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
Reference in New Issue
Block a user