mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-03 02:20:19 +08:00
fix(core): fix all docs permissions check (#12538)
This commit is contained in:
@@ -95,12 +95,14 @@ export const DocListItemComponent = memo(function DocListItemComponent({
|
|||||||
|
|
||||||
export const DocsExplorer = ({
|
export const DocsExplorer = ({
|
||||||
className,
|
className,
|
||||||
|
disableMultiSelectToolbar,
|
||||||
disableMultiDelete,
|
disableMultiDelete,
|
||||||
masonryItemWidthMin,
|
masonryItemWidthMin,
|
||||||
onRestore,
|
onRestore,
|
||||||
onDelete,
|
onDelete,
|
||||||
}: {
|
}: {
|
||||||
className?: string;
|
className?: string;
|
||||||
|
disableMultiSelectToolbar?: boolean;
|
||||||
disableMultiDelete?: boolean;
|
disableMultiDelete?: boolean;
|
||||||
masonryItemWidthMin?: number;
|
masonryItemWidthMin?: number;
|
||||||
onRestore?: (ids: string[]) => void;
|
onRestore?: (ids: string[]) => void;
|
||||||
@@ -244,7 +246,7 @@ export const DocsExplorer = ({
|
|||||||
paddingY={BUILD_CONFIG.isMobileEdition ? 12 : 0}
|
paddingY={BUILD_CONFIG.isMobileEdition ? 12 : 0}
|
||||||
paddingX={BUILD_CONFIG.isMobileEdition ? 16 : responsivePaddingX}
|
paddingX={BUILD_CONFIG.isMobileEdition ? 16 : responsivePaddingX}
|
||||||
/>
|
/>
|
||||||
{!disableMultiDelete || onRestore ? (
|
{!disableMultiSelectToolbar || onRestore ? (
|
||||||
<ListFloatingToolbar
|
<ListFloatingToolbar
|
||||||
open={!!selectMode}
|
open={!!selectMode}
|
||||||
onDelete={disableMultiDelete ? undefined : handleMultiDelete}
|
onDelete={disableMultiDelete ? undefined : handleMultiDelete}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
import { WorkspaceDialogService } from '@affine/core/modules/dialogs';
|
import { WorkspaceDialogService } from '@affine/core/modules/dialogs';
|
||||||
import { DocsService } from '@affine/core/modules/doc';
|
import { DocsService } from '@affine/core/modules/doc';
|
||||||
import { CompatibleFavoriteItemsAdapter } from '@affine/core/modules/favorite';
|
import { CompatibleFavoriteItemsAdapter } from '@affine/core/modules/favorite';
|
||||||
|
import { GuardService } from '@affine/core/modules/permissions';
|
||||||
import { WorkbenchService } from '@affine/core/modules/workbench';
|
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
import track from '@affine/track';
|
import track from '@affine/track';
|
||||||
@@ -142,6 +143,9 @@ const MoveToTrash = ({ docId }: DocOperationProps) => {
|
|||||||
const docsService = useService(DocsService);
|
const docsService = useService(DocsService);
|
||||||
const { openConfirmModal } = useConfirmModal();
|
const { openConfirmModal } = useConfirmModal();
|
||||||
const doc = useLiveData(docsService.list.doc$(docId));
|
const doc = useLiveData(docsService.list.doc$(docId));
|
||||||
|
const guardService = useService(GuardService);
|
||||||
|
|
||||||
|
const canTrash = useLiveData(guardService.can$('Doc_Trash', docId));
|
||||||
|
|
||||||
const onMoveToTrash = useCallback(() => {
|
const onMoveToTrash = useCallback(() => {
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
@@ -170,6 +174,7 @@ const MoveToTrash = ({ docId }: DocOperationProps) => {
|
|||||||
prefixIcon={<DeleteIcon />}
|
prefixIcon={<DeleteIcon />}
|
||||||
data-testid="doc-list-operation-trash"
|
data-testid="doc-list-operation-trash"
|
||||||
onClick={onMoveToTrash}
|
onClick={onMoveToTrash}
|
||||||
|
disabled={!canTrash}
|
||||||
>
|
>
|
||||||
{t['com.affine.moveToTrash.title']()}
|
{t['com.affine.moveToTrash.title']()}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import type { DocRecord } from '@affine/core/modules/doc';
|
|||||||
import { CompatibleFavoriteItemsAdapter } from '@affine/core/modules/favorite';
|
import { CompatibleFavoriteItemsAdapter } from '@affine/core/modules/favorite';
|
||||||
import { GuardService } from '@affine/core/modules/permissions';
|
import { GuardService } from '@affine/core/modules/permissions';
|
||||||
import { WorkbenchService } from '@affine/core/modules/workbench';
|
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||||
|
import { UserFriendlyError } from '@affine/error';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
import track from '@affine/track';
|
import track from '@affine/track';
|
||||||
import {
|
import {
|
||||||
@@ -135,6 +136,7 @@ export const QuickDelete = memo(function QuickDelete({
|
|||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const { openConfirmModal } = useConfirmModal();
|
const { openConfirmModal } = useConfirmModal();
|
||||||
const contextValue = useContext(DocExplorerContext);
|
const contextValue = useContext(DocExplorerContext);
|
||||||
|
const guardService = useService(GuardService);
|
||||||
const quickTrash = useLiveData(contextValue.quickTrash$);
|
const quickTrash = useLiveData(contextValue.quickTrash$);
|
||||||
|
|
||||||
const onMoveToTrash = useCallback(
|
const onMoveToTrash = useCallback(
|
||||||
@@ -157,12 +159,23 @@ export const QuickDelete = memo(function QuickDelete({
|
|||||||
confirmButtonOptions: {
|
confirmButtonOptions: {
|
||||||
variant: 'error',
|
variant: 'error',
|
||||||
},
|
},
|
||||||
onConfirm: () => {
|
onConfirm: async () => {
|
||||||
doc.moveToTrash();
|
try {
|
||||||
|
const canTrash = await guardService.can('Doc_Trash', doc.id);
|
||||||
|
if (!canTrash) {
|
||||||
|
toast(t['com.affine.no-permission']());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
doc.moveToTrash();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
const userFriendlyError = UserFriendlyError.fromAny(error);
|
||||||
|
toast(t[`error.${userFriendlyError.name}`](userFriendlyError.data));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[doc, onClick, openConfirmModal, t]
|
[doc, guardService, onClick, openConfirmModal, t]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!quickTrash) {
|
if (!quickTrash) {
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ export const SelectPage = memo(function SelectPage({
|
|||||||
) : null}
|
) : null}
|
||||||
{!isEmpty ? (
|
{!isEmpty ? (
|
||||||
<DocExplorerContext.Provider value={docExplorerContextValue}>
|
<DocExplorerContext.Provider value={docExplorerContextValue}>
|
||||||
<DocsExplorer disableMultiDelete />
|
<DocsExplorer disableMultiSelectToolbar />
|
||||||
</DocExplorerContext.Provider>
|
</DocExplorerContext.Provider>
|
||||||
) : (
|
) : (
|
||||||
<EmptyList search={searchText} />
|
<EmptyList search={searchText} />
|
||||||
|
|||||||
Reference in New Issue
Block a user