Skip to content

Commit

Permalink
add authcan check for deleting of process
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasMGo committed Oct 26, 2023
1 parent 9497f10 commit ddaf0a6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
29 changes: 16 additions & 13 deletions src/management-system-v2/components/process-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import classNames from 'classnames';
import { generateDateString } from '@/lib/utils';
import { ApiData, useDeleteAsset, useInvalidateAsset } from '@/lib/fetch-data';
import ProcessEditButton from './process-edit-button';
import { AuthCan } from '@/lib/iamComponents';

type Processes = ApiData<'/process', 'get'>;
type Process = Processes[number];
Expand Down Expand Up @@ -134,20 +135,22 @@ const ProcessList: FC<ProcessListProps> = ({
invalidateProcesses();
}}
/>
<Tooltip placement="top" title={'Delete'}>
<DeleteOutlined
onClick={async (event) => {
event.stopPropagation();
event.preventDefault();
<AuthCan resource="Process" action="delete">
<Tooltip placement="top" title={'Delete'}>
<DeleteOutlined
onClick={async (event) => {
event.stopPropagation();
event.preventDefault();

setSelection(
(selection as string[]).filter((id: string) => id !== record.definitionId),
);
await deleteProcess({ params: { path: { definitionId: record.definitionId } } });
await invalidateProcesses();
}}
/>
</Tooltip>
setSelection(
(selection as string[]).filter((id: string) => id !== record.definitionId),
);
await deleteProcess({ params: { path: { definitionId: record.definitionId } } });
await invalidateProcesses();
}}
/>
</Tooltip>
</AuthCan>
</>
);
}, []);
Expand Down
27 changes: 15 additions & 12 deletions src/management-system-v2/components/processes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ProcessExportModal from './process-export';
import Bar from './bar';
import ProcessEditButton from './process-edit-button';
import { asyncForEach } from '@/lib/helpers/javascriptHelpers';
import { AuthCan } from '@/lib/iamComponents';

type Processes = ApiData<'/process', 'get'>;
type Process = Processes[number];
Expand Down Expand Up @@ -103,18 +104,20 @@ const Processes: FC = () => {
}}
/>
)}
<Tooltip placement="top" title={'Delete'}>
<DeleteOutlined
onClick={async () => {
deselectAll();
await asyncForEach(selectedRowKeys as string[], async (selectedRowKey: string) => {
await deleteProcess({ params: { path: { definitionId: selectedRowKey } } });
});

await refetchProcesses();
}}
/>
</Tooltip>
<AuthCan resource="Process" action="delete">
<Tooltip placement="top" title={'Delete'}>
<DeleteOutlined
onClick={async () => {
deselectAll();
await asyncForEach(selectedRowKeys as string[], async (selectedRowKey: string) => {
await deleteProcess({ params: { path: { definitionId: selectedRowKey } } });
});

await refetchProcesses();
}}
/>
</Tooltip>
</AuthCan>
</>
);

Expand Down

0 comments on commit ddaf0a6

Please sign in to comment.