fix(core): fix the permission check in peek view (#10213)
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
import { EditorOutlineViewer } from '@affine/core/components/blocksuite/outline-viewer';
|
import { EditorOutlineViewer } from '@affine/core/components/blocksuite/outline-viewer';
|
||||||
import { PageNotFound } from '@affine/core/desktop/pages/404';
|
import { PageNotFound } from '@affine/core/desktop/pages/404';
|
||||||
import { EditorService } from '@affine/core/modules/editor';
|
import { EditorService } from '@affine/core/modules/editor';
|
||||||
|
import { GuardService } from '@affine/core/modules/permissions';
|
||||||
import { DebugLogger } from '@affine/debug';
|
import { DebugLogger } from '@affine/debug';
|
||||||
import { GfxControllerIdentifier } from '@blocksuite/affine/block-std/gfx';
|
import { GfxControllerIdentifier } from '@blocksuite/affine/block-std/gfx';
|
||||||
import { RefNodeSlotsProvider } from '@blocksuite/affine/blocks';
|
import { RefNodeSlotsProvider } from '@blocksuite/affine/blocks';
|
||||||
@@ -83,8 +84,11 @@ function DocPeekPreviewEditor({
|
|||||||
const defaultOpenProperty = useLiveData(editor.defaultOpenProperty$);
|
const defaultOpenProperty = useLiveData(editor.defaultOpenProperty$);
|
||||||
const workbench = useService(WorkbenchService).workbench;
|
const workbench = useService(WorkbenchService).workbench;
|
||||||
const peekView = useService(PeekViewService).peekView;
|
const peekView = useService(PeekViewService).peekView;
|
||||||
|
const guardService = useService(GuardService);
|
||||||
const editorElement = useLiveData(editor.editorContainer$);
|
const editorElement = useLiveData(editor.editorContainer$);
|
||||||
|
|
||||||
|
const isInTrash = useLiveData(doc.record.trash$);
|
||||||
|
|
||||||
const handleOnEditorReady = useCallback(
|
const handleOnEditorReady = useCallback(
|
||||||
(editorContainer: AffineEditorContainer) => {
|
(editorContainer: AffineEditorContainer) => {
|
||||||
if (!editorContainer.host) {
|
if (!editorContainer.host) {
|
||||||
@@ -145,6 +149,10 @@ function DocPeekPreviewEditor({
|
|||||||
peekView.close();
|
peekView.close();
|
||||||
}, [doc, peekView, workbench]);
|
}, [doc, peekView, workbench]);
|
||||||
|
|
||||||
|
const canEdit = useLiveData(guardService.can$('Doc_Update', doc.id));
|
||||||
|
|
||||||
|
const readonly = !canEdit || isInTrash;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AffineErrorBoundary>
|
<AffineErrorBoundary>
|
||||||
<Scrollable.Root>
|
<Scrollable.Root>
|
||||||
@@ -156,6 +164,7 @@ function DocPeekPreviewEditor({
|
|||||||
className={styles.editor}
|
className={styles.editor}
|
||||||
mode={mode}
|
mode={mode}
|
||||||
page={doc.blockSuiteDoc}
|
page={doc.blockSuiteDoc}
|
||||||
|
readonly={readonly}
|
||||||
onEditorReady={handleOnEditorReady}
|
onEditorReady={handleOnEditorReady}
|
||||||
defaultOpenProperty={defaultOpenProperty}
|
defaultOpenProperty={defaultOpenProperty}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user