mirror of
				https://github.com/nitnelave/lldap.git
				synced 2023-04-12 14:25:13 +00:00 
			
		
		
		
	model: move User and Group definition to backend
This commit is contained in:
		
							parent
							
								
									e2fc06af62
								
							
						
					
					
						commit
						593b7010e6
					
				@ -67,37 +67,6 @@ pub mod registration {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
 | 
					 | 
				
			||||||
#[cfg_attr(not(target_arch = "wasm32"), derive(sqlx::FromRow))]
 | 
					 | 
				
			||||||
pub struct User {
 | 
					 | 
				
			||||||
    pub user_id: String,
 | 
					 | 
				
			||||||
    pub email: String,
 | 
					 | 
				
			||||||
    pub display_name: Option<String>,
 | 
					 | 
				
			||||||
    pub first_name: Option<String>,
 | 
					 | 
				
			||||||
    pub last_name: Option<String>,
 | 
					 | 
				
			||||||
    // pub avatar: ?,
 | 
					 | 
				
			||||||
    pub creation_date: chrono::DateTime<chrono::Utc>,
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
impl Default for User {
 | 
					 | 
				
			||||||
    fn default() -> Self {
 | 
					 | 
				
			||||||
        User {
 | 
					 | 
				
			||||||
            user_id: String::new(),
 | 
					 | 
				
			||||||
            email: String::new(),
 | 
					 | 
				
			||||||
            display_name: None,
 | 
					 | 
				
			||||||
            first_name: None,
 | 
					 | 
				
			||||||
            last_name: None,
 | 
					 | 
				
			||||||
            creation_date: Utc.timestamp(0, 0),
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
 | 
					 | 
				
			||||||
pub struct Group {
 | 
					 | 
				
			||||||
    pub display_name: String,
 | 
					 | 
				
			||||||
    pub users: Vec<String>,
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[derive(Clone, Serialize, Deserialize)]
 | 
					#[derive(Clone, Serialize, Deserialize)]
 | 
				
			||||||
pub struct JWTClaims {
 | 
					pub struct JWTClaims {
 | 
				
			||||||
    pub exp: DateTime<Utc>,
 | 
					    pub exp: DateTime<Utc>,
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,37 @@ use async_trait::async_trait;
 | 
				
			|||||||
use serde::{Deserialize, Serialize};
 | 
					use serde::{Deserialize, Serialize};
 | 
				
			||||||
use std::collections::HashSet;
 | 
					use std::collections::HashSet;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub use lldap_model::{Group, User};
 | 
					#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
 | 
				
			||||||
 | 
					#[cfg_attr(not(target_arch = "wasm32"), derive(sqlx::FromRow))]
 | 
				
			||||||
 | 
					pub struct User {
 | 
				
			||||||
 | 
					    pub user_id: String,
 | 
				
			||||||
 | 
					    pub email: String,
 | 
				
			||||||
 | 
					    pub display_name: Option<String>,
 | 
				
			||||||
 | 
					    pub first_name: Option<String>,
 | 
				
			||||||
 | 
					    pub last_name: Option<String>,
 | 
				
			||||||
 | 
					    // pub avatar: ?,
 | 
				
			||||||
 | 
					    pub creation_date: chrono::DateTime<chrono::Utc>,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Default for User {
 | 
				
			||||||
 | 
					    fn default() -> Self {
 | 
				
			||||||
 | 
					        use chrono::TimeZone;
 | 
				
			||||||
 | 
					        User {
 | 
				
			||||||
 | 
					            user_id: String::new(),
 | 
				
			||||||
 | 
					            email: String::new(),
 | 
				
			||||||
 | 
					            display_name: None,
 | 
				
			||||||
 | 
					            first_name: None,
 | 
				
			||||||
 | 
					            last_name: None,
 | 
				
			||||||
 | 
					            creation_date: chrono::Utc.timestamp(0, 0),
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
 | 
				
			||||||
 | 
					pub struct Group {
 | 
				
			||||||
 | 
					    pub display_name: String,
 | 
				
			||||||
 | 
					    pub users: Vec<String>,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
 | 
					#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
 | 
				
			||||||
pub struct BindRequest {
 | 
					pub struct BindRequest {
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
 | 
				
			|||||||
use std::convert::TryInto;
 | 
					use std::convert::TryInto;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type DomainRequestFilter = crate::domain::handler::RequestFilter;
 | 
					type DomainRequestFilter = crate::domain::handler::RequestFilter;
 | 
				
			||||||
 | 
					type DomainUser = crate::domain::handler::User;
 | 
				
			||||||
use super::api::Context;
 | 
					use super::api::Context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(PartialEq, Eq, Debug, GraphQLInputObject)]
 | 
					#[derive(PartialEq, Eq, Debug, GraphQLInputObject)]
 | 
				
			||||||
@ -117,14 +118,14 @@ impl<Handler: BackendHandler + Sync> Query<Handler> {
 | 
				
			|||||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
 | 
					#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
 | 
				
			||||||
/// Represents a single user.
 | 
					/// Represents a single user.
 | 
				
			||||||
pub struct User<Handler: BackendHandler> {
 | 
					pub struct User<Handler: BackendHandler> {
 | 
				
			||||||
    user: lldap_model::User,
 | 
					    user: DomainUser,
 | 
				
			||||||
    _phantom: std::marker::PhantomData<Box<Handler>>,
 | 
					    _phantom: std::marker::PhantomData<Box<Handler>>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl<Handler: BackendHandler> Default for User<Handler> {
 | 
					impl<Handler: BackendHandler> Default for User<Handler> {
 | 
				
			||||||
    fn default() -> Self {
 | 
					    fn default() -> Self {
 | 
				
			||||||
        Self {
 | 
					        Self {
 | 
				
			||||||
            user: lldap_model::User::default(),
 | 
					            user: DomainUser::default(),
 | 
				
			||||||
            _phantom: std::marker::PhantomData,
 | 
					            _phantom: std::marker::PhantomData,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -166,8 +167,8 @@ impl<Handler: BackendHandler + Sync> User<Handler> {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl<Handler: BackendHandler> From<lldap_model::User> for User<Handler> {
 | 
					impl<Handler: BackendHandler> From<DomainUser> for User<Handler> {
 | 
				
			||||||
    fn from(user: lldap_model::User) -> Self {
 | 
					    fn from(user: DomainUser) -> Self {
 | 
				
			||||||
        Self {
 | 
					        Self {
 | 
				
			||||||
            user,
 | 
					            user,
 | 
				
			||||||
            _phantom: std::marker::PhantomData,
 | 
					            _phantom: std::marker::PhantomData,
 | 
				
			||||||
@ -243,7 +244,7 @@ mod tests {
 | 
				
			|||||||
        mock.expect_get_user_details()
 | 
					        mock.expect_get_user_details()
 | 
				
			||||||
            .with(eq("bob"))
 | 
					            .with(eq("bob"))
 | 
				
			||||||
            .return_once(|_| {
 | 
					            .return_once(|_| {
 | 
				
			||||||
                Ok(lldap_model::User {
 | 
					                Ok(DomainUser {
 | 
				
			||||||
                    user_id: "bob".to_string(),
 | 
					                    user_id: "bob".to_string(),
 | 
				
			||||||
                    email: "bob@bobbers.on".to_string(),
 | 
					                    email: "bob@bobbers.on".to_string(),
 | 
				
			||||||
                    ..Default::default()
 | 
					                    ..Default::default()
 | 
				
			||||||
@ -298,7 +299,6 @@ mod tests {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        let mut mock = MockTestBackendHandler::new();
 | 
					        let mut mock = MockTestBackendHandler::new();
 | 
				
			||||||
        use crate::domain::handler::RequestFilter;
 | 
					        use crate::domain::handler::RequestFilter;
 | 
				
			||||||
        use lldap_model::User;
 | 
					 | 
				
			||||||
        mock.expect_list_users()
 | 
					        mock.expect_list_users()
 | 
				
			||||||
            .with(eq(Some(RequestFilter::Or(vec![
 | 
					            .with(eq(Some(RequestFilter::Or(vec![
 | 
				
			||||||
                RequestFilter::Equality("id".to_string(), "bob".to_string()),
 | 
					                RequestFilter::Equality("id".to_string(), "bob".to_string()),
 | 
				
			||||||
@ -306,12 +306,12 @@ mod tests {
 | 
				
			|||||||
            ]))))
 | 
					            ]))))
 | 
				
			||||||
            .return_once(|_| {
 | 
					            .return_once(|_| {
 | 
				
			||||||
                Ok(vec![
 | 
					                Ok(vec![
 | 
				
			||||||
                    User {
 | 
					                    DomainUser {
 | 
				
			||||||
                        user_id: "bob".to_string(),
 | 
					                        user_id: "bob".to_string(),
 | 
				
			||||||
                        email: "bob@bobbers.on".to_string(),
 | 
					                        email: "bob@bobbers.on".to_string(),
 | 
				
			||||||
                        ..Default::default()
 | 
					                        ..Default::default()
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                    User {
 | 
					                    DomainUser {
 | 
				
			||||||
                        user_id: "robert".to_string(),
 | 
					                        user_id: "robert".to_string(),
 | 
				
			||||||
                        email: "robert@bobbers.on".to_string(),
 | 
					                        email: "robert@bobbers.on".to_string(),
 | 
				
			||||||
                        ..Default::default()
 | 
					                        ..Default::default()
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user