diff --git a/app/src/user_details.rs b/app/src/user_details.rs index a2c2749..eb93e17 100644 --- a/app/src/user_details.rs +++ b/app/src/user_details.rs @@ -91,9 +91,9 @@ impl Component for UserDetails {
{"User ID: "} {&u.id}
{"Email: "}{&u.email}
-
{"Display name: "}{&u.display_name.as_ref().unwrap_or(&String::new())}
-
{"First name: "}{&u.first_name.as_ref().unwrap_or(&String::new())}
-
{"Last name: "}{&u.last_name.as_ref().unwrap_or(&String::new())}
+
{"Display name: "}{&u.display_name}
+
{"First name: "}{&u.first_name}
+
{"Last name: "}{&u.last_name}
{"Creation date: "}{&u.creation_date.with_timezone(&chrono::Local)}
} diff --git a/app/src/user_table.rs b/app/src/user_table.rs index 1fc4b90..a479a79 100644 --- a/app/src/user_table.rs +++ b/app/src/user_table.rs @@ -82,9 +82,9 @@ impl Component for UserTable { {&user.id} {&user.email} - {&user.display_name.as_ref().unwrap_or(&String::new())} - {&user.first_name.as_ref().unwrap_or(&String::new())} - {&user.last_name.as_ref().unwrap_or(&String::new())} + {&user.display_name} + {&user.first_name} + {&user.last_name} {&user.creation_date.with_timezone(&chrono::Local)} } diff --git a/schema.graphql b/schema.graphql index 36bcf11..6a22b94 100644 --- a/schema.graphql +++ b/schema.graphql @@ -45,9 +45,9 @@ type Query { type User { id: String! email: String! - displayName: String - firstName: String - lastName: String + displayName: String! + firstName: String! + lastName: String! creationDate: DateTimeUtc! "The groups to which this user belongs." groups: [Group!]! diff --git a/server/src/domain/handler.rs b/server/src/domain/handler.rs index 84bc640..72c3f21 100644 --- a/server/src/domain/handler.rs +++ b/server/src/domain/handler.rs @@ -8,9 +8,9 @@ use std::collections::HashSet; pub struct User { pub user_id: String, pub email: String, - pub display_name: Option, - pub first_name: Option, - pub last_name: Option, + pub display_name: String, + pub first_name: String, + pub last_name: String, // pub avatar: ?, pub creation_date: chrono::DateTime, } @@ -21,9 +21,9 @@ impl Default for User { User { user_id: String::new(), email: String::new(), - display_name: None, - first_name: None, - last_name: None, + display_name: String::new(), + first_name: String::new(), + last_name: String::new(), creation_date: chrono::Utc.timestamp(0, 0), } } diff --git a/server/src/domain/sql_backend_handler.rs b/server/src/domain/sql_backend_handler.rs index 165b627..8c6fbb6 100644 --- a/server/src/domain/sql_backend_handler.rs +++ b/server/src/domain/sql_backend_handler.rs @@ -3,7 +3,7 @@ use crate::infra::configuration::Configuration; use async_trait::async_trait; use futures_util::StreamExt; use futures_util::TryStreamExt; -use sea_query::{Expr, Iden, Order, Query, SimpleExpr, Value}; +use sea_query::{Expr, Iden, Order, Query, SimpleExpr}; use sqlx::Row; use std::collections::HashSet; @@ -179,9 +179,9 @@ impl BackendHandler for SqlBackendHandler { let values = vec![ request.user_id.clone().into(), request.email.into(), - request.display_name.map(Into::into).unwrap_or(Value::Null), - request.first_name.map(Into::into).unwrap_or(Value::Null), - request.last_name.map(Into::into).unwrap_or(Value::Null), + request.display_name.unwrap_or_default().into(), + request.first_name.unwrap_or_default().into(), + request.last_name.unwrap_or_default().into(), chrono::Utc::now().naive_utc().into(), ]; let query = Query::insert() diff --git a/server/src/domain/sql_tables.rs b/server/src/domain/sql_tables.rs index 6e17938..57d05d3 100644 --- a/server/src/domain/sql_tables.rs +++ b/server/src/domain/sql_tables.rs @@ -49,9 +49,13 @@ pub async fn init_table(pool: &Pool) -> sqlx::Result<()> { .primary_key(), ) .col(ColumnDef::new(Users::Email).string_len(255).not_null()) - .col(ColumnDef::new(Users::DisplayName).string_len(255)) - .col(ColumnDef::new(Users::FirstName).string_len(255)) - .col(ColumnDef::new(Users::LastName).string_len(255)) + .col( + ColumnDef::new(Users::DisplayName) + .string_len(255) + .not_null(), + ) + .col(ColumnDef::new(Users::FirstName).string_len(255).not_null()) + .col(ColumnDef::new(Users::LastName).string_len(255).not_null()) .col(ColumnDef::new(Users::Avatar).binary()) .col(ColumnDef::new(Users::CreationDate).date_time().not_null()) .col(ColumnDef::new(Users::PasswordHash).binary()) diff --git a/server/src/infra/graphql/query.rs b/server/src/infra/graphql/query.rs index 4fca1f1..2c9a29c 100644 --- a/server/src/infra/graphql/query.rs +++ b/server/src/infra/graphql/query.rs @@ -141,16 +141,16 @@ impl User { &self.user.email } - fn display_name(&self) -> Option<&String> { - self.user.display_name.as_ref() + fn display_name(&self) -> &str { + &self.user.display_name } - fn first_name(&self) -> Option<&String> { - self.user.first_name.as_ref() + fn first_name(&self) -> &str { + &self.user.first_name } - fn last_name(&self) -> Option<&String> { - self.user.last_name.as_ref() + fn last_name(&self) -> &str { + &self.user.last_name } fn creation_date(&self) -> chrono::DateTime { diff --git a/server/src/infra/ldap_handler.rs b/server/src/infra/ldap_handler.rs index 46149f1..6ac8608 100644 --- a/server/src/infra/ldap_handler.rs +++ b/server/src/infra/ldap_handler.rs @@ -69,12 +69,9 @@ fn get_attribute(user: &User, attribute: &str) -> Result> { ]), "uid" => Ok(vec![user.user_id.clone()]), "mail" => Ok(vec![user.email.clone()]), - "givenName" => Ok(vec![user.first_name.clone().unwrap_or_default()]), - "sn" => Ok(vec![user.last_name.clone().unwrap_or_default()]), - "cn" => Ok(vec![user - .display_name - .clone() - .unwrap_or_else(|| user.user_id.clone())]), + "givenName" => Ok(vec![user.first_name.clone()]), + "sn" => Ok(vec![user.last_name.clone()]), + "cn" => Ok(vec![user.display_name.clone()]), _ => bail!("Unsupported attribute: {}", attribute), } } @@ -479,17 +476,17 @@ mod tests { User { user_id: "bob_1".to_string(), email: "bob@bobmail.bob".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()), + display_name: "Bôb Böbberson".to_string(), + first_name: "Bôb".to_string(), + last_name: "Böbberson".to_string(), ..Default::default() }, User { user_id: "jim".to_string(), email: "jim@cricket.jim".to_string(), - display_name: Some("Jimminy Cricket".to_string()), - first_name: Some("Jim".to_string()), - last_name: Some("Cricket".to_string()), + display_name: "Jimminy Cricket".to_string(), + first_name: "Jim".to_string(), + last_name: "Cricket".to_string(), ..Default::default() }, ])