Add functions for delete rooms and users

This commit is contained in:
dklimpel 2020-04-05 13:06:18 +02:00
parent 7eeb60539f
commit 3e6f4d8aca
2 changed files with 40 additions and 15 deletions

View File

@ -32,7 +32,6 @@ export const UserList = props => (
{...props} {...props}
filters={<UserFilter />} filters={<UserFilter />}
filterDefaultValues={{ guests: true, deactivated: false }} filterDefaultValues={{ guests: true, deactivated: false }}
bulkActionButtons={false}
> >
<Datagrid rowClick="edit"> <Datagrid rowClick="edit">
<ReferenceField <ReferenceField

View File

@ -28,6 +28,7 @@ const resourceMap = {
total: (json, from, perPage) => { total: (json, from, perPage) => {
return json.next_token ? parseInt(json.next_token, 10) + perPage : from + json.users.length; return json.next_token ? parseInt(json.next_token, 10) + perPage : from + json.users.length;
}, },
delete_path: "/_synapse/admin/v1/deactivate",
}, },
rooms: { rooms: {
path: "/_synapse/admin/v1/rooms", path: "/_synapse/admin/v1/rooms",
@ -41,6 +42,7 @@ const resourceMap = {
total: json => { total: json => {
return json.total_rooms; return json.total_rooms;
}, },
delete_path: "/_synapse/admin/v1/purge_room",
}, },
}; };
@ -197,10 +199,21 @@ const dataProvider = {
if (!homeserver || !(resource in resourceMap)) return Promise.reject(); if (!homeserver || !(resource in resourceMap)) return Promise.reject();
const res = resourceMap[resource]; const res = resourceMap[resource];
const homeserver_url = homeserver + res.delete_path;
const homeserver_url = homeserver + res.path; var request_url;
return jsonClient(`${homeserver_url}/${params.id}`, { var request_body;
method: "DELETE", if (res.data === "users") {
request_url = `${homeserver_url}/${params.id}`;
request_body = { erase: true };
} else if (res.data === "rooms") {
request_url = `${homeserver_url}`;
request_body = { room_id: `${params.id}` };
}
return jsonClient(request_url, {
method: "POST",
body: JSON.stringify(request_body),
}).then(({ json }) => ({ }).then(({ json }) => ({
data: json, data: json,
})); }));
@ -212,18 +225,31 @@ const dataProvider = {
if (!homeserver || !(resource in resourceMap)) return Promise.reject(); if (!homeserver || !(resource in resourceMap)) return Promise.reject();
const res = resourceMap[resource]; const res = resourceMap[resource];
const homeserver_url = homeserver + res.delete_path;
const homeserver_url = homeserver + res.path; if (res.data === "users") {
return Promise.all( return Promise.all(
params.ids.map(id => params.ids.map(id =>
jsonClient(`${homeserver_url}/${id}`, { jsonClient(`${homeserver_url}/${id}`, {
method: "DELETE", method: "POST",
body: JSON.stringify(params.data, filterNullValues), body: JSON.stringify({ erase: true }),
}).then(responses => ({ }).then(json => ({
data: responses.map(({ json }) => json), data: json,
})) }))
) )
); );
} else if (res.data === "rooms") {
return Promise.all(
params.ids.map(id =>
jsonClient(`${homeserver_url}`, {
method: "POST",
body: JSON.stringify({ room_id: `${id}` }),
}).then(json => ({
data: json,
}))
)
);
}
}, },
}; };