Add button to quarantine media (#180)
Change-Id: I6496826fdf75ab8b7b3ed5a9056abf86a50caea3
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
useRefresh,
|
||||
useTranslate,
|
||||
} from "react-admin";
|
||||
import BlockIcon from "@material-ui/icons/Block";
|
||||
import ClearIcon from "@material-ui/icons/Clear";
|
||||
import DeleteSweepIcon from "@material-ui/icons/DeleteSweep";
|
||||
import Dialog from "@material-ui/core/Dialog";
|
||||
@@ -241,3 +242,86 @@ export const ProtectMediaButton = props => {
|
||||
</Fragment>
|
||||
);
|
||||
};
|
||||
|
||||
export const QuarantineMediaButton = props => {
|
||||
const { record } = props;
|
||||
const translate = useTranslate();
|
||||
const refresh = useRefresh();
|
||||
const notify = useNotify();
|
||||
const [create, { loading }] = useCreate("quarantine_media");
|
||||
const [deleteOne] = useDelete("quarantine_media");
|
||||
|
||||
if (!record) return null;
|
||||
|
||||
const handleQuarantaine = () => {
|
||||
create(
|
||||
{ payload: { data: record } },
|
||||
{
|
||||
onSuccess: () => {
|
||||
notify("resources.quarantine_media.action.send_success");
|
||||
refresh();
|
||||
},
|
||||
onFailure: () =>
|
||||
notify("resources.quarantine_media.action.send_failure", "error"),
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const handleRemoveQuarantaine = () => {
|
||||
deleteOne(
|
||||
{ payload: { ...record } },
|
||||
{
|
||||
onSuccess: () => {
|
||||
notify("resources.quarantine_media.action.send_success");
|
||||
refresh();
|
||||
},
|
||||
onFailure: () =>
|
||||
notify("resources.quarantine_media.action.send_failure", "error"),
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
{record.safe_from_quarantine && (
|
||||
<Tooltip
|
||||
title={translate("resources.quarantine_media.action.none", {
|
||||
_: "resources.quarantine_media.action.none",
|
||||
})}
|
||||
>
|
||||
<div>
|
||||
<Button disabled={true}>
|
||||
<ClearIcon />
|
||||
</Button>
|
||||
</div>
|
||||
</Tooltip>
|
||||
)}
|
||||
{record.quarantined_by && (
|
||||
<Tooltip
|
||||
title={translate("resources.quarantine_media.action.delete", {
|
||||
_: "resources.quarantine_media.action.delete",
|
||||
})}
|
||||
>
|
||||
<div>
|
||||
<Button onClick={handleRemoveQuarantaine} disabled={loading}>
|
||||
<BlockIcon color="error" />
|
||||
</Button>
|
||||
</div>
|
||||
</Tooltip>
|
||||
)}
|
||||
{!record.safe_from_quarantine && !record.quarantined_by && (
|
||||
<Tooltip
|
||||
title={translate("resources.quarantine_media.action.create", {
|
||||
_: "resources.quarantine_media.action.create",
|
||||
})}
|
||||
>
|
||||
<div>
|
||||
<Button onClick={handleQuarantaine} disabled={loading}>
|
||||
<BlockIcon />
|
||||
</Button>
|
||||
</div>
|
||||
</Tooltip>
|
||||
)}
|
||||
</Fragment>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -48,7 +48,7 @@ import {
|
||||
import { Link } from "react-router-dom";
|
||||
import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices";
|
||||
import { DeviceRemoveButton } from "./devices";
|
||||
import { ProtectMediaButton } from "./media";
|
||||
import { ProtectMediaButton, QuarantineMediaButton } from "./media";
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
|
||||
const redirect = () => {
|
||||
@@ -466,6 +466,7 @@ export const UserEdit = props => {
|
||||
<TextField source="media_type" />
|
||||
<TextField source="upload_name" />
|
||||
<TextField source="quarantined_by" />
|
||||
<QuarantineMediaButton label="resources.quarantine_media.action.name" />
|
||||
<ProtectMediaButton label="resources.users_media.fields.safe_from_quarantine" />
|
||||
<DeleteButton mutationMode="pessimistic" redirect={false} />
|
||||
</Datagrid>
|
||||
|
||||
Reference in New Issue
Block a user