mirror of
https://github.com/UA-Fediland/synapse-admin.git
synced 2024-11-09 16:24:51 +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,
|
BulkDeleteButton,
|
||||||
DeleteButton,
|
DeleteButton,
|
||||||
SaveButton,
|
SaveButton,
|
||||||
|
maxLength,
|
||||||
regex,
|
regex,
|
||||||
required,
|
required,
|
||||||
useTranslate,
|
useTranslate,
|
||||||
|
@ -181,10 +182,16 @@ export const UserList = props => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://matrix.org/docs/spec/appendices#user-identifiers
|
// https://matrix.org/docs/spec/appendices#user-identifiers
|
||||||
const validateUser = regex(
|
// here only local part of user_id
|
||||||
/^@[a-z0-9._=\-/]+:.*/,
|
// maxLength = 255 - "@" - ":" - localStorage.getItem("home_server").length
|
||||||
"synapseadmin.users.invalid_user_id"
|
// 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() {
|
export function generateRandomUser() {
|
||||||
const homeserver = localStorage.getItem("home_server");
|
const homeserver = localStorage.getItem("home_server");
|
||||||
|
@ -248,8 +255,12 @@ export const UserCreate = props => (
|
||||||
<Create {...props}>
|
<Create {...props}>
|
||||||
<SimpleForm>
|
<SimpleForm>
|
||||||
<TextInput source="id" autoComplete="off" validate={validateUser} />
|
<TextInput source="id" autoComplete="off" validate={validateUser} />
|
||||||
<TextInput source="displayname" />
|
<TextInput source="displayname" validate={maxLength(256)} />
|
||||||
<PasswordInput source="password" autoComplete="new-password" />
|
<PasswordInput
|
||||||
|
source="password"
|
||||||
|
autoComplete="new-password"
|
||||||
|
validate={maxLength(512)}
|
||||||
|
/>
|
||||||
<BooleanInput source="admin" />
|
<BooleanInput source="admin" />
|
||||||
<ArrayInput source="threepids">
|
<ArrayInput source="threepids">
|
||||||
<SimpleFormIterator>
|
<SimpleFormIterator>
|
||||||
|
@ -259,8 +270,9 @@ export const UserCreate = props => (
|
||||||
{ id: "email", name: "resources.users.email" },
|
{ id: "email", name: "resources.users.email" },
|
||||||
{ id: "msisdn", name: "resources.users.msisdn" },
|
{ id: "msisdn", name: "resources.users.msisdn" },
|
||||||
]}
|
]}
|
||||||
|
validate={required()}
|
||||||
/>
|
/>
|
||||||
<TextInput source="address" />
|
<TextInput source="address" validate={validateAddress} />
|
||||||
</SimpleFormIterator>
|
</SimpleFormIterator>
|
||||||
</ArrayInput>
|
</ArrayInput>
|
||||||
<ArrayInput source="external_ids" label="synapseadmin.users.tabs.sso">
|
<ArrayInput source="external_ids" label="synapseadmin.users.tabs.sso">
|
||||||
|
|
|
@ -12,8 +12,7 @@ const de = {
|
||||||
url_error: "Keine gültige Matrix Server URL",
|
url_error: "Keine gültige Matrix Server URL",
|
||||||
},
|
},
|
||||||
users: {
|
users: {
|
||||||
invalid_user_id:
|
invalid_user_id: "Lokaler Anteil der Matrix Benutzer-ID ohne Homeserver.",
|
||||||
"Muss eine vollständige Matrix Benutzer-ID sein, z.B. @benutzer_id:homeserver",
|
|
||||||
tabs: { sso: "SSO" },
|
tabs: { sso: "SSO" },
|
||||||
},
|
},
|
||||||
rooms: {
|
rooms: {
|
||||||
|
|
|
@ -12,8 +12,7 @@ const en = {
|
||||||
url_error: "Not a valid Matrix server URL",
|
url_error: "Not a valid Matrix server URL",
|
||||||
},
|
},
|
||||||
users: {
|
users: {
|
||||||
invalid_user_id:
|
invalid_user_id: "Localpart of a Matrix user-id without homeserver.",
|
||||||
"Must be a fully qualified Matrix user-id, e.g. @user_id:homeserver",
|
|
||||||
tabs: { sso: "SSO" },
|
tabs: { sso: "SSO" },
|
||||||
},
|
},
|
||||||
rooms: {
|
rooms: {
|
||||||
|
|
|
@ -41,7 +41,9 @@ const resourceMap = {
|
||||||
data: "users",
|
data: "users",
|
||||||
total: json => json.total,
|
total: json => json.total,
|
||||||
create: data => ({
|
create: data => ({
|
||||||
endpoint: `/_synapse/admin/v2/users/${data.id}`,
|
endpoint: `/_synapse/admin/v2/users/@${data.id}:${localStorage.getItem(
|
||||||
|
"home_server"
|
||||||
|
)}`,
|
||||||
body: data,
|
body: data,
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in a new issue