mirror of
https://github.com/UA-Fediland/synapse-admin.git
synced 2024-11-22 06:21:28 +00:00
Automatically set the homeserver for a new user (#184)
and enhance form validation
This commit is contained in:
parent
79ef38ee6b
commit
1a17d3e69b
4 changed files with 24 additions and 12 deletions
|
@ -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 => (
|
|||
<Create {...props}>
|
||||
<SimpleForm>
|
||||
<TextInput source="id" autoComplete="off" validate={validateUser} />
|
||||
<TextInput source="displayname" />
|
||||
<PasswordInput source="password" autoComplete="new-password" />
|
||||
<TextInput source="displayname" validate={maxLength(256)} />
|
||||
<PasswordInput
|
||||
source="password"
|
||||
autoComplete="new-password"
|
||||
validate={maxLength(512)}
|
||||
/>
|
||||
<BooleanInput source="admin" />
|
||||
<ArrayInput source="threepids">
|
||||
<SimpleFormIterator>
|
||||
|
@ -259,8 +270,9 @@ export const UserCreate = props => (
|
|||
{ id: "email", name: "resources.users.email" },
|
||||
{ id: "msisdn", name: "resources.users.msisdn" },
|
||||
]}
|
||||
validate={required()}
|
||||
/>
|
||||
<TextInput source="address" />
|
||||
<TextInput source="address" validate={validateAddress} />
|
||||
</SimpleFormIterator>
|
||||
</ArrayInput>
|
||||
<ArrayInput source="external_ids" label="synapseadmin.users.tabs.sso">
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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",
|
||||
}),
|
||||
|
|
Loading…
Reference in a new issue