From 437fd70d6d0eb53e0857a2bbc87fe0fdc357d521 Mon Sep 17 00:00:00 2001 From: Manuel Stahl Date: Thu, 23 Apr 2020 10:44:52 +0200 Subject: [PATCH] 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 --- src/synapse/dataProvider.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/synapse/dataProvider.js b/src/synapse/dataProvider.js index 7e60414..7a1500a 100644 --- a/src/synapse/dataProvider.js +++ b/src/synapse/dataProvider.js @@ -30,6 +30,11 @@ const resourceMap = { ? parseInt(json.next_token, 10) + perPage : from + json.users.length; }, + create: data => ({ + endpoint: `/_synapse/admin/v2/users/${data.id}`, + body: data, + method: "PUT", + }), delete: id => ({ endpoint: `/_synapse/admin/v1/deactivate/${id}`, body: { erase: true }, @@ -190,11 +195,13 @@ const dataProvider = { if (!homeserver || !(resource in resourceMap)) return Promise.reject(); const res = resourceMap[resource]; + if (!("create" in res)) return Promise.reject(); - const endpoint_url = homeserver + res.path; - return jsonClient(`${endpoint_url}/${params.data.id}`, { - method: "PUT", - body: JSON.stringify(params.data, filterNullValues), + const create = res["create"](params.data); + const endpoint_url = homeserver + create.endpoint; + return jsonClient(endpoint_url, { + method: create.method, + body: JSON.stringify(create.body, filterNullValues), }).then(({ json }) => ({ data: res.map(json), }));