mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-21 19:11:04 +00:00
Define User::search_local_by_name() method
This commit is contained in:
parent
ec030d500d
commit
a1a19e091a
1 changed files with 25 additions and 1 deletions
|
@ -15,7 +15,10 @@ use activitystreams::{
|
|||
prelude::*,
|
||||
};
|
||||
use chrono::{NaiveDateTime, Utc};
|
||||
use diesel::{self, BelongingToDsl, ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl};
|
||||
use diesel::{
|
||||
self, BelongingToDsl, BoolExpressionMethods, ExpressionMethods, OptionalExtension, QueryDsl,
|
||||
RunQueryDsl, TextExpressionMethods,
|
||||
};
|
||||
use ldap3::{LdapConn, Scope, SearchEntry};
|
||||
use openssl::{
|
||||
hash::MessageDigest,
|
||||
|
@ -204,6 +207,27 @@ impl User {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn search_local_by_name(
|
||||
conn: &Connection,
|
||||
name: &str,
|
||||
(min, max): (i32, i32),
|
||||
) -> Result<Vec<User>> {
|
||||
users::table
|
||||
.filter(users::instance_id.eq(Instance::get_local()?.id))
|
||||
.filter(users::role.ne(Role::Instance as i32))
|
||||
// TODO: use `ilike` instead of `like` for PostgreSQL
|
||||
.filter(
|
||||
users::username
|
||||
.like(format!("%{}%", name))
|
||||
.or(users::display_name.like(format!("%{}%", name))),
|
||||
)
|
||||
.order(users::username.asc())
|
||||
.offset(min.into())
|
||||
.limit((max - min).into())
|
||||
.load::<User>(conn)
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Should create user record with normalized(lowercased) email
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue