Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix login ilike bug. Fixes #1920 #1921

Merged
merged 2 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/db_schema/src/impls/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
source::person::{Person, PersonForm},
traits::Crud,
};
use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl, *};
use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
use url::Url;

mod safe_type {
Expand Down Expand Up @@ -194,7 +194,7 @@ impl Person {
person
.filter(deleted.eq(false))
.filter(local.eq(true))
.filter(name.ilike(from_name))
.filter(name.eq(from_name))
.first::<Person>(conn)
}

Expand Down
9 changes: 6 additions & 3 deletions crates/db_schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn from_opt_str_to_opt_enum<T: std::str::FromStr>(opt: &Option<String>) -> O
}

pub fn fuzzy_search(q: &str) -> String {
let replaced = q.replace(" ", "%");
let replaced = q.replace("%", "\\%").replace("_", "\\_").replace(" ", "%");
format!("%{}%", replaced)
}

Expand Down Expand Up @@ -154,8 +154,11 @@ mod tests {

#[test]
fn test_fuzzy_search() {
let test = "This is a fuzzy search";
assert_eq!(fuzzy_search(test), "%This%is%a%fuzzy%search%".to_string());
let test = "This %is% _a_ fuzzy search";
assert_eq!(
fuzzy_search(test),
"%This%\\%is\\%%\\_a\\_%fuzzy%search%".to_string()
);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions crates/db_views/src/local_user_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ impl LocalUserView {
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
.filter(
person::name
.ilike(name_or_email)
.or(local_user::email.ilike(name_or_email)),
.eq(name_or_email)
.or(local_user::email.eq(name_or_email)),
)
.select((
local_user::all_columns,
Expand Down