Prevent users from attempting to delete pending approvals

This commit is contained in:
mabashian 2020-11-13 13:16:34 -05:00
parent 929be1652a
commit b8b3424c1f
2 changed files with 11 additions and 5 deletions

View File

@ -61,10 +61,6 @@ const ItemToDelete = shape({
}).isRequired,
});
function cannotDelete(item) {
return !item.summary_fields.user_capabilities.delete;
}
function ToolbarDeleteButton({
itemsToDelete,
pluralizedItemName,
@ -72,6 +68,7 @@ function ToolbarDeleteButton({
onDelete,
warningMessage,
i18n,
cannotDelete,
}) {
const { isKebabified, onKebabModalChange } = useContext(KebabifiedContext);
const [isModalOpen, setIsModalOpen] = useState(false);
@ -100,7 +97,7 @@ function ToolbarDeleteButton({
return (
<div>
{errorMessage.length > 0
? errorMessage
? `${errorMessage}: ${itemsUnableToDelete}`
: i18n._(
t`You do not have permission to delete ${pluralizedItemName}: ${itemsUnableToDelete}`
)}
@ -193,12 +190,14 @@ ToolbarDeleteButton.propTypes = {
pluralizedItemName: string,
errorMessage: string,
warningMessage: node,
cannotDelete: func,
};
ToolbarDeleteButton.defaultProps = {
pluralizedItemName: 'Items',
errorMessage: '',
warningMessage: null,
cannotDelete: item => !item.summary_fields.user_capabilities.delete,
};
export default withI18n()(ToolbarDeleteButton);

View File

@ -212,6 +212,13 @@ function WorkflowApprovalsList({ i18n }) {
onDelete={handleDelete}
itemsToDelete={selected}
pluralizedItemName={i18n._(t`Workflow Approvals`)}
cannotDelete={item =>
item.status === 'pending' ||
!item.summary_fields.user_capabilities.delete
}
errorMessage={i18n._(
t`These approvals cannot be deleted due to insufficient permissions or a pending job status`
)}
/>,
]}
/>