Add button to quarantine media (#180)
Change-Id: I6496826fdf75ab8b7b3ed5a9056abf86a50caea3
This commit is contained in:
		
							parent
							
								
									aaf782d24f
								
							
						
					
					
						commit
						8536f552d4
					
				| @ -17,6 +17,7 @@ import { | |||||||
|   useRefresh, |   useRefresh, | ||||||
|   useTranslate, |   useTranslate, | ||||||
| } from "react-admin"; | } from "react-admin"; | ||||||
|  | import BlockIcon from "@material-ui/icons/Block"; | ||||||
| import ClearIcon from "@material-ui/icons/Clear"; | import ClearIcon from "@material-ui/icons/Clear"; | ||||||
| import DeleteSweepIcon from "@material-ui/icons/DeleteSweep"; | import DeleteSweepIcon from "@material-ui/icons/DeleteSweep"; | ||||||
| import Dialog from "@material-ui/core/Dialog"; | import Dialog from "@material-ui/core/Dialog"; | ||||||
| @ -241,3 +242,86 @@ export const ProtectMediaButton = props => { | |||||||
|     </Fragment> |     </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 { Link } from "react-router-dom"; | ||||||
| import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices"; | import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices"; | ||||||
| import { DeviceRemoveButton } from "./devices"; | import { DeviceRemoveButton } from "./devices"; | ||||||
| import { ProtectMediaButton } from "./media"; | import { ProtectMediaButton, QuarantineMediaButton } from "./media"; | ||||||
| import { makeStyles } from "@material-ui/core/styles"; | import { makeStyles } from "@material-ui/core/styles"; | ||||||
| 
 | 
 | ||||||
| const redirect = () => { | const redirect = () => { | ||||||
| @ -466,6 +466,7 @@ export const UserEdit = props => { | |||||||
|               <TextField source="media_type" /> |               <TextField source="media_type" /> | ||||||
|               <TextField source="upload_name" /> |               <TextField source="upload_name" /> | ||||||
|               <TextField source="quarantined_by" /> |               <TextField source="quarantined_by" /> | ||||||
|  |               <QuarantineMediaButton label="resources.quarantine_media.action.name" /> | ||||||
|               <ProtectMediaButton label="resources.users_media.fields.safe_from_quarantine" /> |               <ProtectMediaButton label="resources.users_media.fields.safe_from_quarantine" /> | ||||||
|               <DeleteButton mutationMode="pessimistic" redirect={false} /> |               <DeleteButton mutationMode="pessimistic" redirect={false} /> | ||||||
|             </Datagrid> |             </Datagrid> | ||||||
|  | |||||||
| @ -242,7 +242,7 @@ const de = { | |||||||
|         media_type: "Typ", |         media_type: "Typ", | ||||||
|         upload_name: "Dateiname", |         upload_name: "Dateiname", | ||||||
|         quarantined_by: "Zur Quarantäne hinzugefügt", |         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", |         created_ts: "Erstellt", | ||||||
|         last_access_ts: "Letzter Zugriff", |         last_access_ts: "Letzter Zugriff", | ||||||
|       }, |       }, | ||||||
| @ -272,6 +272,16 @@ const de = { | |||||||
|         send_failure: "Beim Versenden ist ein Fehler aufgetreten.", |         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: { |     pushers: { | ||||||
|       name: "Pusher |||| Pushers", |       name: "Pusher |||| Pushers", | ||||||
|       fields: { |       fields: { | ||||||
|  | |||||||
| @ -268,6 +268,16 @@ const en = { | |||||||
|         send_failure: "An error has occurred.", |         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: { |     pushers: { | ||||||
|       name: "Pusher |||| Pushers", |       name: "Pusher |||| Pushers", | ||||||
|       fields: { |       fields: { | ||||||
|  | |||||||
| @ -193,6 +193,21 @@ const resourceMap = { | |||||||
|       method: "POST", |       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: { |   servernotices: { | ||||||
|     map: n => ({ id: n.event_id }), |     map: n => ({ id: n.event_id }), | ||||||
|     create: data => ({ |     create: data => ({ | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 dklimpel
						dklimpel