Allow searching for users

Change-Id: Icf4a3b05b24c66971f55b22e7540a1dc904a3a92
This commit is contained in:
Michael Albert 2020-04-15 15:31:10 +02:00
parent d2a3f07a59
commit 7aec6f9369
2 changed files with 21 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import {
PasswordInput,
TextField,
TextInput,
SearchInput,
ReferenceField,
SaveButton,
Toolbar,
@ -21,6 +22,7 @@ import SaveQrButton from "./SaveQrButton";
const UserFilter = props => (
<Filter {...props}>
<SearchInput source="q" alwaysOn />
<BooleanInput source="guests" alwaysOn />
<BooleanInput
label="resources.users.fields.show_deactivated"

View File

@ -70,6 +70,25 @@ const dataProvider = {
const homeserver_url = "https://" + homeserver + res.path;
const url = `${homeserver_url}?${stringify(query)}`;
// searching for users is not implemented in admin api
if (params.filter.q) {
console.log("searching");
const search_query = { limit: perPage, search_term: params.filter.q };
const search_url =
homeserver + `/_matrix/client/r0/user_directory/search`;
return jsonClient(search_url, {
method: "POST",
body: JSON.stringify(search_query),
}).then(({ json }) => ({
data: json["results"].map(u => ({
...u,
id: u.user_id,
name: u.user_id,
})),
total: json.limited ? perPage * 2 : json.results.length,
}));
}
return jsonClient(url).then(({ json }) => ({
data: json[res.data].map(res.map),
total: res.total(json, perPage),