Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions for delete rooms and users #32

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/components/rooms.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import React from "react";
import { Datagrid, List, TextField, Pagination } from "react-admin";
import React, { Fragment } from "react";
import {
Datagrid,
List,
TextField,
BulkDeleteButton,
Pagination,
} from "react-admin";

const RoomBulkActionButtons = props => (
<Fragment>
<BulkDeleteButton {...props} label="resources.rooms.action.purge" />
</Fragment>
);

const RoomPagination = props => (
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
);

export const RoomList = props => (
<List {...props} pagination={<RoomPagination />}>
<List
{...props}
pagination={<RoomPagination />}
bulkActionButtons={<RoomBulkActionButtons />}
>
<Datagrid>
<TextField source="room_id" />
<TextField source="name" />
Expand Down
33 changes: 30 additions & 3 deletions src/components/users.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { Fragment } from "react";
import PersonPinIcon from "@material-ui/icons/PersonPin";
import SettingsInputComponentIcon from "@material-ui/icons/SettingsInputComponent";
import {
Expand All @@ -23,6 +23,11 @@ import {
ReferenceField,
SelectInput,
regex,
Toolbar,
SaveButton,
DeleteButton,
ListButton,
BulkDeleteButton,
Pagination,
} from "react-admin";

Expand All @@ -41,12 +46,34 @@ const UserFilter = props => (
</Filter>
);

const UserEditToolbar = props => (
<Toolbar {...props}>
<SaveButton submitOnEnter={true} />
<DeleteButton
label="resources.users.action.deactivate"
submitOnEnter={false}
variant="flat"
/>
<ListButton
label="resources.users.action.backtolist"
submitOnEnter={false}
variant="flat"
/>
</Toolbar>
);

const UserBulkActionButtons = props => (
<Fragment>
<BulkDeleteButton {...props} label="resources.users.action.deactivate" />
</Fragment>
);

export const UserList = props => (
<List
{...props}
filters={<UserFilter />}
filterDefaultValues={{ guests: true, deactivated: false }}
bulkActionButtons={false}
bulkActionButtons={<UserBulkActionButtons />}
pagination={<UserPagination />}
>
<Datagrid rowClick="edit">
Expand Down Expand Up @@ -106,7 +133,7 @@ export const UserCreate = props => (

export const UserEdit = props => (
<Edit {...props}>
<TabbedForm>
<TabbedForm toolbar={<UserEditToolbar />}>
<FormTab label="resources.users.name" icon={<PersonPinIcon />}>
<TextInput source="id" disabled />
<TextInput source="displayname" />
Expand Down
7 changes: 7 additions & 0 deletions src/i18n/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default {
helper: {
deactivate: "Deaktivierte Nutzer können nicht wieder aktiviert werden.",
},
action: {
deactivate: "Deaktiviere Benutzer",
backtolist: "Zurück zur Liste",
},
},
rooms: {
name: "Raum |||| Räume",
Expand All @@ -47,6 +51,9 @@ export default {
canonical_alias: "Alias",
joined_members: "Mitglieder",
},
action: {
purge: "Säubere Raum",
},
},
connections: {
name: "Verbindungen",
Expand Down
7 changes: 7 additions & 0 deletions src/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default {
helper: {
deactivate: "Deactivated users cannot be reactivated",
},
action: {
deactivate: "Deactivate user",
backtolist: "Back to list",
},
},
rooms: {
name: "Room |||| Rooms",
Expand All @@ -47,6 +51,9 @@ export default {
canonical_alias: "Alias",
joined_members: "Members",
},
action: {
purge: "Säubere Raum",
},
},
connections: {
name: "Connections",
Expand Down
43 changes: 33 additions & 10 deletions src/synapse/dataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ const resourceMap = {
? parseInt(json.next_token, 10) + perPage
: from + json.users.length;
},
delete_path: id => {
return "/_synapse/admin/v1/deactivate/" + id;
},
delete_body: () => {
return JSON.stringify({ erase: true });
},
},
rooms: {
path: "/_synapse/admin/v1/rooms",
Expand All @@ -43,6 +49,12 @@ const resourceMap = {
total: json => {
return json.total_rooms;
},
delete_path: () => {
return "/_synapse/admin/v1/purge_room";
},
delete_body: id => {
return JSON.stringify({ room_id: `${id}` });
},
},
connections: {
path: "/_synapse/admin/v1/whois",
Expand Down Expand Up @@ -201,11 +213,17 @@ const dataProvider = {
if (!homeserver || !(resource in resourceMap)) return Promise.reject();

const res = resourceMap[resource];

const homeserver_url = homeserver + res.path;
return jsonClient(`${homeserver_url}/${params.id}`, {
method: "DELETE",
}).then(({ json }) => ({

return jsonClient(
res.delete_path(params.id)
? `${homeserver}` + res.delete_path(params.id)
: `${homeserver_url}/${params.id}`,
{
method: res.delete_path(params.id) ? "POST" : "DELETE",
body: res.delete_body(params.id),
}
).then(({ json }) => ({
data: json,
}));
},
Expand All @@ -216,15 +234,20 @@ const dataProvider = {
if (!homeserver || !(resource in resourceMap)) return Promise.reject();

const res = resourceMap[resource];

const homeserver_url = homeserver + res.path;

return Promise.all(
params.ids.map(id =>
jsonClient(`${homeserver_url}/${id}`, {
method: "DELETE",
body: JSON.stringify(params.data, filterNullValues),
}).then(responses => ({
data: responses.map(({ json }) => json),
jsonClient(
res.delete_path(id)
? `${homeserver}` + res.delete_path(id)
: `${homeserver_url}/${id}`,
{
method: res.delete_path(id) ? "POST" : "DELETE",
body: res.delete_body(id),
}
).then(json => ({
data: json,
}))
)
);
Expand Down