From 1a17d3e69bfdae0cdf45758c83a4ec30e911fd31 Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Mon, 15 Nov 2021 20:57:38 +0100 Subject: [PATCH] Automatically set the homeserver for a new user (#184) and enhance form validation --- src/components/users.js | 26 +++++++++++++++++++------- src/i18n/de.js | 3 +-- src/i18n/en.js | 3 +-- src/synapse/dataProvider.js | 4 +++- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/components/users.js b/src/components/users.js index cdd8768..7a471d4 100644 --- a/src/components/users.js +++ b/src/components/users.js @@ -36,6 +36,7 @@ import { BulkDeleteButton, DeleteButton, SaveButton, + maxLength, regex, required, useTranslate, @@ -181,10 +182,16 @@ export const UserList = props => { }; // https://matrix.org/docs/spec/appendices#user-identifiers -const validateUser = regex( - /^@[a-z0-9._=\-/]+:.*/, - "synapseadmin.users.invalid_user_id" -); +// here only local part of user_id +// maxLength = 255 - "@" - ":" - localStorage.getItem("home_server").length +// localStorage.getItem("home_server").length is not valid here +const validateUser = [ + required(), + maxLength(253), + regex(/^[a-z0-9._=\-/]+$/, "synapseadmin.users.invalid_user_id"), +]; + +const validateAddress = [required(), maxLength(255)]; export function generateRandomUser() { const homeserver = localStorage.getItem("home_server"); @@ -248,8 +255,12 @@ export const UserCreate = props => ( - - + + @@ -259,8 +270,9 @@ export const UserCreate = props => ( { id: "email", name: "resources.users.email" }, { id: "msisdn", name: "resources.users.msisdn" }, ]} + validate={required()} /> - + diff --git a/src/i18n/de.js b/src/i18n/de.js index f7b0bb1..66a8a05 100644 --- a/src/i18n/de.js +++ b/src/i18n/de.js @@ -12,8 +12,7 @@ const de = { url_error: "Keine gültige Matrix Server URL", }, users: { - invalid_user_id: - "Muss eine vollständige Matrix Benutzer-ID sein, z.B. @benutzer_id:homeserver", + invalid_user_id: "Lokaler Anteil der Matrix Benutzer-ID ohne Homeserver.", tabs: { sso: "SSO" }, }, rooms: { diff --git a/src/i18n/en.js b/src/i18n/en.js index e669a1a..51ba6ca 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -12,8 +12,7 @@ const en = { url_error: "Not a valid Matrix server URL", }, users: { - invalid_user_id: - "Must be a fully qualified Matrix user-id, e.g. @user_id:homeserver", + invalid_user_id: "Localpart of a Matrix user-id without homeserver.", tabs: { sso: "SSO" }, }, rooms: { diff --git a/src/synapse/dataProvider.js b/src/synapse/dataProvider.js index b37af45..5b11139 100644 --- a/src/synapse/dataProvider.js +++ b/src/synapse/dataProvider.js @@ -41,7 +41,9 @@ const resourceMap = { data: "users", total: json => json.total, create: data => ({ - endpoint: `/_synapse/admin/v2/users/${data.id}`, + endpoint: `/_synapse/admin/v2/users/@${data.id}:${localStorage.getItem( + "home_server" + )}`, body: data, method: "PUT", }),