Implemented ui option to block deleted rooms from being rejoined

This commit is contained in:
Johannes Kanefendt 2021-07-07 14:35:22 +02:00
parent 5262518699
commit b2fb2496ca
4 changed files with 128 additions and 10 deletions

View File

@ -1,4 +1,6 @@
import React, { Fragment } from "react"; import React, { Fragment, useState } from "react";
import classnames from "classnames";
import { fade } from "@material-ui/core/styles/colorManipulator";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { import {
BooleanField, BooleanField,
@ -21,6 +23,14 @@ import {
TopToolbar, TopToolbar,
useRecordContext, useRecordContext,
useTranslate, useTranslate,
useRedirect,
Toolbar,
SaveButton,
Button,
SimpleForm,
BooleanInput,
useDelete,
useNotify,
} from "react-admin"; } from "react-admin";
import get from "lodash/get"; import get from "lodash/get";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
@ -33,7 +43,13 @@ import PageviewIcon from "@material-ui/icons/Pageview";
import UserIcon from "@material-ui/icons/Group"; import UserIcon from "@material-ui/icons/Group";
import ViewListIcon from "@material-ui/icons/ViewList"; import ViewListIcon from "@material-ui/icons/ViewList";
import VisibilityIcon from "@material-ui/icons/Visibility"; import VisibilityIcon from "@material-ui/icons/Visibility";
import IconCancel from "@material-ui/icons/Cancel";
import EventIcon from "@material-ui/icons/Event"; import EventIcon from "@material-ui/icons/Event";
import Dialog from "@material-ui/core/Dialog";
import DialogContent from "@material-ui/core/DialogContent";
import DialogContentText from "@material-ui/core/DialogContentText";
import DialogTitle from "@material-ui/core/DialogTitle";
import DeleteIcon from "@material-ui/icons/Delete";
import { import {
RoomDirectoryBulkDeleteButton, RoomDirectoryBulkDeleteButton,
RoomDirectoryBulkSaveButton, RoomDirectoryBulkSaveButton,
@ -46,6 +62,16 @@ const useStyles = makeStyles(theme => ({
fontFamily: "Roboto, Helvetica, Arial, sans-serif", fontFamily: "Roboto, Helvetica, Arial, sans-serif",
margin: "0.5em", margin: "0.5em",
}, },
deleteButton: {
color: theme.palette.error.main,
"&:hover": {
backgroundColor: fade(theme.palette.error.main, 0.12),
// Reset on mouse devices
"@media (hover: none)": {
backgroundColor: "transparent",
},
},
},
})); }));
const RoomPagination = props => ( const RoomPagination = props => (
@ -106,14 +132,7 @@ const RoomShowActions = ({ basePath, data, resource }) => {
{roomDirectoryStatus === true && ( {roomDirectoryStatus === true && (
<RoomDirectoryDeleteButton record={data} /> <RoomDirectoryDeleteButton record={data} />
)} )}
<DeleteButton <DeleteRoomButton record={data} />
basePath={basePath}
record={data}
resource={resource}
mutationMode="pessimistic"
confirmTitle="resources.rooms.action.erase.title"
confirmContent="resources.rooms.action.erase.content"
/>
</TopToolbar> </TopToolbar>
); );
}; };
@ -408,3 +427,92 @@ function mapStateToProps(state) {
} }
export const RoomList = connect(mapStateToProps)(FilterableRoomList); export const RoomList = connect(mapStateToProps)(FilterableRoomList);
const DeleteRoomDialog = ({ open, loading, onClose, onSend }) => {
const translate = useTranslate();
const DeleteRoomToolbar = props => {
return (
<Toolbar {...props}>
<SaveButton
label="resources.rooms.action.erase.title"
icon={<DeleteIcon />}
/>
<Button label="ra.action.cancel" onClick={onClose}>
<IconCancel />
</Button>
</Toolbar>
);
};
return (
<Dialog open={open} onClose={onClose} loading={loading}>
<DialogTitle>
{translate("resources.rooms.action.erase.title")}
</DialogTitle>
<DialogContent>
<DialogContentText>
{translate("resources.rooms.action.erase.content")}
</DialogContentText>
<SimpleForm
toolbar={<DeleteRoomToolbar />}
submitOnEnter={false}
redirect={false}
save={onSend}
>
<BooleanInput
fullWidth
source="block"
label="resources.rooms.action.erase.fields.block"
defaultValue={true}
/>
</SimpleForm>
</DialogContent>
</Dialog>
);
};
export const DeleteRoomButton = props => {
const classes = useStyles(props);
const [open, setOpen] = useState(false);
const notify = useNotify();
const redirect = useRedirect();
const [deleteOne, { loading }] = useDelete("rooms");
const record = useRecordContext(props);
const handleDialogOpen = () => setOpen(true);
const handleDialogClose = () => setOpen(false);
const handleSend = values => {
deleteOne(
{ payload: { id: record.id, ...values } },
{
onSuccess: () => {
notify("resources.rooms.action.erase.send_success");
handleDialogClose();
redirect('/rooms');
},
onFailure: () =>
notify("resources.rooms.action.erase.send_failure", "error"),
}
);
};
return (
<Fragment>
<Button
label="resources.rooms.action.erase.title"
onClick={handleDialogOpen}
disabled={loading}
className={classnames("ra-delete-button", classes.deleteButton)}
>
<DeleteIcon />
</Button>
<DeleteRoomDialog
open={open}
onClose={handleDialogClose}
onSend={handleSend}
/>
</Fragment>
);
};

View File

@ -180,6 +180,11 @@ const de = {
title: "Raum löschen", title: "Raum löschen",
content: content:
"Sind Sie sicher dass Sie den Raum löschen möchten? Diese Aktion kann nicht rückgängig gemacht werden. Alle Nachrichten und Medien, die der Raum beinhaltet werden vom Server gelöscht!", "Sind Sie sicher dass Sie den Raum löschen möchten? Diese Aktion kann nicht rückgängig gemacht werden. Alle Nachrichten und Medien, die der Raum beinhaltet werden vom Server gelöscht!",
fields: {
block: "Raum für erneute Beitritte sperren",
},
send_success: "Der Raum wurde gelöscht",
send_failure: "Der Raum konnte nicht gelöscht werden",
}, },
}, },
}, },

View File

@ -177,6 +177,11 @@ const en = {
title: "Delete room", title: "Delete room",
content: content:
"Are you sure you want to delete the room? This cannot be undone. All messages and shared media in the room will be deleted from the server!", "Are you sure you want to delete the room? This cannot be undone. All messages and shared media in the room will be deleted from the server!",
fields: {
block: "Block room from being rejoined",
},
send_success: "The room has been deleted",
send_failure: "The room could not be deleted",
}, },
}, },
reports: { reports: {

View File

@ -68,7 +68,7 @@ const resourceMap = {
}, },
delete: params => ({ delete: params => ({
endpoint: `/_synapse/admin/v1/rooms/${params.id}`, endpoint: `/_synapse/admin/v1/rooms/${params.id}`,
body: { block: false }, body: { block: !!params.block },
}), }),
}, },
reports: { reports: {