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