Make display_name, first&last name optional

This commit is contained in:
Valentin Tolmer 2021-05-26 08:42:05 +02:00
parent e45cf1c2b5
commit d1a42b178a
3 changed files with 21 additions and 24 deletions

View File

@ -26,9 +26,9 @@ pub struct ListUsersRequest {
pub struct User {
pub user_id: String,
pub email: String,
pub display_name: String,
pub first_name: String,
pub last_name: String,
pub display_name: Option<String>,
pub first_name: Option<String>,
pub last_name: Option<String>,
// pub avatar: ?,
pub creation_date: chrono::NaiveDateTime,
}
@ -38,9 +38,9 @@ impl Default for User {
User {
user_id: String::new(),
email: String::new(),
display_name: String::new(),
first_name: String::new(),
last_name: String::new(),
display_name: None,
first_name: None,
last_name: None,
creation_date: chrono::NaiveDateTime::from_timestamp(0, 0),
}
}

View File

@ -4,7 +4,7 @@ use async_trait::async_trait;
use futures_util::StreamExt;
use futures_util::TryStreamExt;
use log::*;
use sea_query::{Expr, Iden, Order, Query, SimpleExpr};
use sea_query::{Expr, Iden, Order, Query, SimpleExpr, Value};
use sqlx::Row;
use std::collections::HashSet;
@ -205,18 +205,12 @@ mod tests {
.columns(vec![
Users::UserId,
Users::Email,
Users::DisplayName,
Users::FirstName,
Users::LastName,
Users::CreationDate,
Users::Password,
])
.values_panic(vec![
name.into(),
"bob@bob".into(),
"Bob Böbberson".into(),
"Bob".into(),
"Böbberson".into(),
chrono::NaiveDateTime::from_timestamp(0, 0).into(),
pass.into(),
])

View File

@ -67,11 +67,14 @@ fn get_attribute(user: &User, attribute: &str) -> Result<Vec<String>> {
"posixAccount".to_string(),
"mailAccount".to_string(),
]),
"uid" => Ok(vec![user.user_id.to_string()]),
"mail" => Ok(vec![user.email.to_string()]),
"givenName" => Ok(vec![user.first_name.to_string()]),
"sn" => Ok(vec![user.last_name.to_string()]),
"cn" => Ok(vec![user.display_name.to_string()]),
"uid" => Ok(vec![user.user_id.clone()]),
"mail" => Ok(vec![user.email.clone()]),
"givenName" => Ok(vec![user.first_name.clone().unwrap_or("".to_string())]),
"sn" => Ok(vec![user.last_name.clone().unwrap_or("".to_string())]),
"cn" => Ok(vec![user
.display_name
.clone()
.unwrap_or_else(|| user.user_id.clone())]),
_ => bail!("Unsupported attribute: {}", attribute),
}
}
@ -481,17 +484,17 @@ mod tests {
User {
user_id: "bob_1".to_string(),
email: "bob@bobmail.bob".to_string(),
display_name: "Bôb Böbberson".to_string(),
first_name: "Bôb".to_string(),
last_name: "Böbberson".to_string(),
display_name: Some("Bôb Böbberson".to_string()),
first_name: Some("Bôb".to_string()),
last_name: Some("Böbberson".to_string()),
creation_date: NaiveDateTime::from_timestamp(1_000_000, 0),
},
User {
user_id: "jim".to_string(),
email: "jim@cricket.jim".to_string(),
display_name: "Jimminy Cricket".to_string(),
first_name: "Jim".to_string(),
last_name: "Cricket".to_string(),
display_name: Some("Jimminy Cricket".to_string()),
first_name: Some("Jim".to_string()),
last_name: Some("Cricket".to_string()),
creation_date: NaiveDateTime::from_timestamp(1_500_000, 0),
},
])