Make creating users a special case in dataProvider

Since users are created with PUT instead of POST, this is actually a
special case.

Change-Id: Ibe430fcac4d81de9723abd650804ffa93f87bf6d
This commit is contained in:
Manuel Stahl 2020-04-23 10:44:52 +02:00
parent 1e6e526e3c
commit 437fd70d6d

View file

@ -30,6 +30,11 @@ const resourceMap = {
? parseInt(json.next_token, 10) + perPage ? parseInt(json.next_token, 10) + perPage
: from + json.users.length; : from + json.users.length;
}, },
create: data => ({
endpoint: `/_synapse/admin/v2/users/${data.id}`,
body: data,
method: "PUT",
}),
delete: id => ({ delete: id => ({
endpoint: `/_synapse/admin/v1/deactivate/${id}`, endpoint: `/_synapse/admin/v1/deactivate/${id}`,
body: { erase: true }, body: { erase: true },
@ -190,11 +195,13 @@ 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];
if (!("create" in res)) return Promise.reject();
const endpoint_url = homeserver + res.path; const create = res["create"](params.data);
return jsonClient(`${endpoint_url}/${params.data.id}`, { const endpoint_url = homeserver + create.endpoint;
method: "PUT", return jsonClient(endpoint_url, {
body: JSON.stringify(params.data, filterNullValues), method: create.method,
body: JSON.stringify(create.body, filterNullValues),
}).then(({ json }) => ({ }).then(({ json }) => ({
data: res.map(json), data: res.map(json),
})); }));