From 85fc709fc76dd8935c247d8e04d416dbc81aa529 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 3 Aug 2024 16:13:28 +1000 Subject: [PATCH] Fix permission checks for bulk delete actions (#7796) --- src/frontend/src/tables/bom/BomTable.tsx | 2 +- src/frontend/src/tables/build/BuildAllocatedStockTable.tsx | 2 +- src/frontend/src/tables/settings/ErrorTable.tsx | 4 +++- src/frontend/src/tables/settings/FailedTasksTable.tsx | 4 +++- src/frontend/src/tables/settings/PendingTasksTable.tsx | 4 +++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/frontend/src/tables/bom/BomTable.tsx b/src/frontend/src/tables/bom/BomTable.tsx index d583cff857..a065c73aeb 100644 --- a/src/frontend/src/tables/bom/BomTable.tsx +++ b/src/frontend/src/tables/bom/BomTable.tsx @@ -554,7 +554,7 @@ export function BomTable({ modelField: 'sub_part', rowActions: rowActions, enableSelection: !partLocked, - enableBulkDelete: !partLocked, + enableBulkDelete: !partLocked && user.hasDeleteRole(UserRoles.part), enableDownload: true }} /> diff --git a/src/frontend/src/tables/build/BuildAllocatedStockTable.tsx b/src/frontend/src/tables/build/BuildAllocatedStockTable.tsx index f89939fe92..5452590fa9 100644 --- a/src/frontend/src/tables/build/BuildAllocatedStockTable.tsx +++ b/src/frontend/src/tables/build/BuildAllocatedStockTable.tsx @@ -154,7 +154,7 @@ export default function BuildAllocatedStockTable({ stock_detail: true, supplier_detail: true }, - enableBulkDelete: true, + enableBulkDelete: user.hasDeleteRole(UserRoles.build), enableDownload: true, enableSelection: true, rowActions: rowActions, diff --git a/src/frontend/src/tables/settings/ErrorTable.tsx b/src/frontend/src/tables/settings/ErrorTable.tsx index e313d0b542..b3090e4d1c 100644 --- a/src/frontend/src/tables/settings/ErrorTable.tsx +++ b/src/frontend/src/tables/settings/ErrorTable.tsx @@ -8,6 +8,7 @@ import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { useDeleteApiFormModal } from '../../hooks/UseForm'; import { useTable } from '../../hooks/UseTable'; import { apiUrl } from '../../states/ApiState'; +import { useUserState } from '../../states/UserState'; import { TableColumn } from '../Column'; import { InvenTreeTable } from '../InvenTreeTable'; import { RowAction, RowDeleteAction } from '../RowActions'; @@ -17,6 +18,7 @@ import { RowAction, RowDeleteAction } from '../RowActions'; */ export default function ErrorReportTable() { const table = useTable('error-report'); + const user = useUserState(); const [error, setError] = useState(''); @@ -90,7 +92,7 @@ export default function ErrorReportTable() { tableState={table} columns={columns} props={{ - enableBulkDelete: true, + enableBulkDelete: user.isStaff(), enableSelection: true, rowActions: rowActions, onRowClick: (row) => { diff --git a/src/frontend/src/tables/settings/FailedTasksTable.tsx b/src/frontend/src/tables/settings/FailedTasksTable.tsx index 13f740a64f..c7f1117388 100644 --- a/src/frontend/src/tables/settings/FailedTasksTable.tsx +++ b/src/frontend/src/tables/settings/FailedTasksTable.tsx @@ -7,11 +7,13 @@ import { StylishText } from '../../components/items/StylishText'; import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { useTable } from '../../hooks/UseTable'; import { apiUrl } from '../../states/ApiState'; +import { useUserState } from '../../states/UserState'; import { TableColumn } from '../Column'; import { InvenTreeTable } from '../InvenTreeTable'; export default function FailedTasksTable() { const table = useTable('tasks-failed'); + const user = useUserState(); const [error, setError] = useState(''); @@ -70,7 +72,7 @@ export default function FailedTasksTable() { tableState={table} columns={columns} props={{ - enableBulkDelete: true, + enableBulkDelete: user.isStaff(), enableSelection: true, onRowClick: (row: any) => { setError(row.result); diff --git a/src/frontend/src/tables/settings/PendingTasksTable.tsx b/src/frontend/src/tables/settings/PendingTasksTable.tsx index 7177427c7c..c82731cf62 100644 --- a/src/frontend/src/tables/settings/PendingTasksTable.tsx +++ b/src/frontend/src/tables/settings/PendingTasksTable.tsx @@ -4,11 +4,13 @@ import { useMemo } from 'react'; import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { useTable } from '../../hooks/UseTable'; import { apiUrl } from '../../states/ApiState'; +import { useUserState } from '../../states/UserState'; import { TableColumn } from '../Column'; import { InvenTreeTable } from '../InvenTreeTable'; export default function PendingTasksTable() { const table = useTable('tasks-pending'); + const user = useUserState(); const columns: TableColumn[] = useMemo(() => { return [ @@ -48,7 +50,7 @@ export default function PendingTasksTable() { tableState={table} columns={columns} props={{ - enableBulkDelete: true, + enableBulkDelete: user.isStaff(), enableSelection: true }} />