Search by any alias in member search
Diff
chartered-db/src/users.rs | 11 +++++++++++
chartered-frontend/src/pages/crate/Members.tsx | 11 ++++++++---
chartered-web/src/endpoints/web_api/users/search.rs | 6 ++++--
3 files changed, 19 insertions(+), 9 deletions(-)
@@ -28,13 +28,20 @@
given_query: String,
limit: i64,
) -> Result<Vec<User>> {
use crate::schema::users::dsl::username;
use crate::schema::users::dsl::{name, nick, username};
tokio::task::spawn_blocking(move || {
let conn = conn.get()?;
let query = format!("%{}%", given_query);
Ok(crate::schema::users::table
.filter(username.like(format!("%{}%", given_query)))
.filter(
username
.like(&query)
.or(name.like(&query))
.or(nick.like(&query)),
)
.limit(limit)
.load(&conn)?)
})
@@ -83,12 +83,13 @@
{possiblePermissions ? (
<MemberListInserter
onInsert={(username, userUuid) =>
onInsert={(displayName, pictureUrl, userUuid) =>
setProspectiveMembers([
...prospectiveMembers,
{
uuid: userUuid,
username,
display_name: displayName,
picture_url: pictureUrl,
permissions: ["VISIBLE"],
},
])
@@ -257,7 +258,7 @@
existingMembers,
}: {
existingMembers: Member[];
onInsert: (username, user_uuid) => any;
onInsert: (username, picture_url, user_uuid) => any;
}) {
const auth = useAuth();
const searchRef = React.useRef(null);
@@ -291,7 +292,7 @@
};
const handleChange = (selected) => {
onInsert(selected[0].username, selected[0].user_uuid);
onInsert(selected[0].display_name, selected[0].picture_url, selected[0].user_uuid);
searchRef.current.clear();
};
@@ -321,7 +322,7 @@
(existing) => option.user_uuid === existing.uuid
) === -1
}
labelKey="username"
labelKey="display_name"
options={options}
isLoading={loading}
placeholder="Search for User"
@@ -16,7 +16,8 @@
#[derive(Serialize)]
pub struct ResponseUser {
user_uuid: chartered_db::uuid::Uuid,
username: String,
display_name: String,
picture_url: Option<String>,
}
pub async fn handle(
@@ -28,7 +29,8 @@
.into_iter()
.map(|user| ResponseUser {
user_uuid: user.uuid.0,
username: user.username,
display_name: user.display_name().to_string(),
picture_url: user.picture_url,
})
.collect();