Add functions for delete rooms and users
This commit is contained in:
parent
7eeb60539f
commit
3e6f4d8aca
@ -32,7 +32,6 @@ export const UserList = props => (
|
||||
{...props}
|
||||
filters={<UserFilter />}
|
||||
filterDefaultValues={{ guests: true, deactivated: false }}
|
||||
bulkActionButtons={false}
|
||||
>
|
||||
<Datagrid rowClick="edit">
|
||||
<ReferenceField
|
||||
|
||||
@ -28,6 +28,7 @@ const resourceMap = {
|
||||
total: (json, from, perPage) => {
|
||||
return json.next_token ? parseInt(json.next_token, 10) + perPage : from + json.users.length;
|
||||
},
|
||||
delete_path: "/_synapse/admin/v1/deactivate",
|
||||
},
|
||||
rooms: {
|
||||
path: "/_synapse/admin/v1/rooms",
|
||||
@ -41,6 +42,7 @@ const resourceMap = {
|
||||
total: json => {
|
||||
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();
|
||||
|
||||
const res = resourceMap[resource];
|
||||
const homeserver_url = homeserver + res.delete_path;
|
||||
|
||||
const homeserver_url = homeserver + res.path;
|
||||
return jsonClient(`${homeserver_url}/${params.id}`, {
|
||||
method: "DELETE",
|
||||
var request_url;
|
||||
var request_body;
|
||||
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 }) => ({
|
||||
data: json,
|
||||
}));
|
||||
@ -212,18 +225,31 @@ const dataProvider = {
|
||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||
|
||||
const res = resourceMap[resource];
|
||||
const homeserver_url = homeserver + res.delete_path;
|
||||
|
||||
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),
|
||||
}))
|
||||
)
|
||||
);
|
||||
if (res.data === "users") {
|
||||
return Promise.all(
|
||||
params.ids.map(id =>
|
||||
jsonClient(`${homeserver_url}/${id}`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ erase: true }),
|
||||
}).then(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,
|
||||
}))
|
||||
)
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user