diff --git a/src/components/media.js b/src/components/media.js index 095f1ad..a523fa2 100644 --- a/src/components/media.js +++ b/src/components/media.js @@ -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 => { ); }; + +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 ( + + {record.safe_from_quarantine && ( + +
+ +
+
+ )} + {record.quarantined_by && ( + +
+ +
+
+ )} + {!record.safe_from_quarantine && !record.quarantined_by && ( + +
+ +
+
+ )} +
+ ); +}; diff --git a/src/components/users.js b/src/components/users.js index 32cbdd6..c954416 100644 --- a/src/components/users.js +++ b/src/components/users.js @@ -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 => { + diff --git a/src/i18n/de.js b/src/i18n/de.js index 7a9139f..f7b0bb1 100644 --- a/src/i18n/de.js +++ b/src/i18n/de.js @@ -242,7 +242,7 @@ const de = { media_type: "Typ", upload_name: "Dateiname", quarantined_by: "Zur Quarantäne hinzugefügt", - safe_from_quarantine: "Geschützt vor Quarantäne", + safe_from_quarantine: "Schutz vor Quarantäne", created_ts: "Erstellt", last_access_ts: "Letzter Zugriff", }, @@ -272,6 +272,16 @@ const de = { send_failure: "Beim Versenden ist ein Fehler aufgetreten.", }, }, + quarantine_media: { + action: { + name: "Quarantäne", + create: "Zur Quarantäne hinzufügen", + delete: "In Quarantäne, Quarantäne aufheben", + none: "Geschützt vor Quarantäne", + send_success: "Erfolgreich den Quarantäne-Status geändert.", + send_failure: "Beim Versenden ist ein Fehler aufgetreten.", + }, + }, pushers: { name: "Pusher |||| Pushers", fields: { diff --git a/src/i18n/en.js b/src/i18n/en.js index 680fcc5..e669a1a 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -268,6 +268,16 @@ const en = { send_failure: "An error has occurred.", }, }, + quarantine_media: { + action: { + name: "Quarantine", + create: "Add to quarantine", + delete: "In quarantine, unquarantine", + none: "Protected from quarantine", + send_success: "Successfully changed the quarantine status.", + send_failure: "An error has occurred.", + }, + }, pushers: { name: "Pusher |||| Pushers", fields: { diff --git a/src/synapse/dataProvider.js b/src/synapse/dataProvider.js index d40640a..b37af45 100644 --- a/src/synapse/dataProvider.js +++ b/src/synapse/dataProvider.js @@ -193,6 +193,21 @@ const resourceMap = { method: "POST", }), }, + quarantine_media: { + map: qm => ({ id: qm.media_id }), + create: params => ({ + endpoint: `/_synapse/admin/v1/media/quarantine/${localStorage.getItem( + "home_server" + )}/${params.media_id}`, + method: "POST", + }), + delete: params => ({ + endpoint: `/_synapse/admin/v1/media/unquarantine/${localStorage.getItem( + "home_server" + )}/${params.media_id}`, + method: "POST", + }), + }, servernotices: { map: n => ({ id: n.event_id }), create: data => ({