mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
model: inline the UserDetailsRequest
This commit is contained in:
parent
6efafa99c8
commit
0dd05e5771
@ -67,11 +67,6 @@ pub mod registration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
|
|
||||||
pub struct UserDetailsRequest {
|
|
||||||
pub user_id: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
|
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||||
#[cfg_attr(not(target_arch = "wasm32"), derive(sqlx::FromRow))]
|
#[cfg_attr(not(target_arch = "wasm32"), derive(sqlx::FromRow))]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
|
@ -5,7 +5,6 @@ use std::collections::HashSet;
|
|||||||
|
|
||||||
pub use lldap_model::{
|
pub use lldap_model::{
|
||||||
AddUserToGroupRequest, CreateGroupRequest, CreateUserRequest, DeleteUserRequest, Group, User,
|
AddUserToGroupRequest, CreateGroupRequest, CreateUserRequest, DeleteUserRequest, Group, User,
|
||||||
UserDetailsRequest,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
|
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
|
||||||
@ -31,7 +30,7 @@ pub trait LoginHandler: Clone + Send {
|
|||||||
pub trait BackendHandler: Clone + Send {
|
pub trait BackendHandler: Clone + Send {
|
||||||
async fn list_users(&self, filters: Option<RequestFilter>) -> Result<Vec<User>>;
|
async fn list_users(&self, filters: Option<RequestFilter>) -> Result<Vec<User>>;
|
||||||
async fn list_groups(&self) -> Result<Vec<Group>>;
|
async fn list_groups(&self) -> Result<Vec<Group>>;
|
||||||
async fn get_user_details(&self, request: UserDetailsRequest) -> Result<User>;
|
async fn get_user_details(&self, user_id: &str) -> Result<User>;
|
||||||
async fn create_user(&self, request: CreateUserRequest) -> Result<()>;
|
async fn create_user(&self, request: CreateUserRequest) -> Result<()>;
|
||||||
async fn delete_user(&self, request: DeleteUserRequest) -> Result<()>;
|
async fn delete_user(&self, request: DeleteUserRequest) -> Result<()>;
|
||||||
async fn create_group(&self, request: CreateGroupRequest) -> Result<i32>;
|
async fn create_group(&self, request: CreateGroupRequest) -> Result<i32>;
|
||||||
@ -49,7 +48,7 @@ mockall::mock! {
|
|||||||
impl BackendHandler for TestBackendHandler {
|
impl BackendHandler for TestBackendHandler {
|
||||||
async fn list_users(&self, filters: Option<RequestFilter>) -> Result<Vec<User>>;
|
async fn list_users(&self, filters: Option<RequestFilter>) -> Result<Vec<User>>;
|
||||||
async fn list_groups(&self) -> Result<Vec<Group>>;
|
async fn list_groups(&self) -> Result<Vec<Group>>;
|
||||||
async fn get_user_details(&self, request: UserDetailsRequest) -> Result<User>;
|
async fn get_user_details(&self, user_id: &str) -> Result<User>;
|
||||||
async fn create_user(&self, request: CreateUserRequest) -> Result<()>;
|
async fn create_user(&self, request: CreateUserRequest) -> Result<()>;
|
||||||
async fn delete_user(&self, request: DeleteUserRequest) -> Result<()>;
|
async fn delete_user(&self, request: DeleteUserRequest) -> Result<()>;
|
||||||
async fn create_group(&self, request: CreateGroupRequest) -> Result<i32>;
|
async fn create_group(&self, request: CreateGroupRequest) -> Result<i32>;
|
||||||
|
@ -117,7 +117,7 @@ impl BackendHandler for SqlBackendHandler {
|
|||||||
Ok(groups)
|
Ok(groups)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_user_details(&self, request: UserDetailsRequest) -> Result<User> {
|
async fn get_user_details(&self, user_id: &str) -> Result<User> {
|
||||||
let query = Query::select()
|
let query = Query::select()
|
||||||
.column(Users::UserId)
|
.column(Users::UserId)
|
||||||
.column(Users::Email)
|
.column(Users::Email)
|
||||||
@ -127,7 +127,7 @@ impl BackendHandler for SqlBackendHandler {
|
|||||||
.column(Users::Avatar)
|
.column(Users::Avatar)
|
||||||
.column(Users::CreationDate)
|
.column(Users::CreationDate)
|
||||||
.from(Users::Table)
|
.from(Users::Table)
|
||||||
.and_where(Expr::col(Users::UserId).eq(request.user_id))
|
.and_where(Expr::col(Users::UserId).eq(user_id))
|
||||||
.to_string(DbQueryBuilder {});
|
.to_string(DbQueryBuilder {});
|
||||||
|
|
||||||
Ok(sqlx::query_as::<_, User>(&query)
|
Ok(sqlx::query_as::<_, User>(&query)
|
||||||
@ -470,21 +470,11 @@ mod tests {
|
|||||||
let handler = SqlBackendHandler::new(config, sql_pool);
|
let handler = SqlBackendHandler::new(config, sql_pool);
|
||||||
insert_user(&handler, "bob", "bob00").await;
|
insert_user(&handler, "bob", "bob00").await;
|
||||||
{
|
{
|
||||||
let user = handler
|
let user = handler.get_user_details("bob").await.unwrap();
|
||||||
.get_user_details(UserDetailsRequest {
|
|
||||||
user_id: String::from("bob"),
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(user.user_id, "bob".to_string());
|
assert_eq!(user.user_id, "bob".to_string());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
handler
|
handler.get_user_details("John").await.unwrap_err();
|
||||||
.get_user_details(UserDetailsRequest {
|
|
||||||
user_id: String::from("John"),
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.unwrap_err();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::domain::handler::BackendHandler;
|
use crate::domain::handler::BackendHandler;
|
||||||
use juniper::{graphql_object, FieldResult, GraphQLInputObject};
|
use juniper::{graphql_object, FieldResult, GraphQLInputObject};
|
||||||
use lldap_model::UserDetailsRequest;
|
|
||||||
|
|
||||||
use super::api::Context;
|
use super::api::Context;
|
||||||
|
|
||||||
@ -49,7 +48,7 @@ impl<Handler: BackendHandler + Sync> Mutation<Handler> {
|
|||||||
.await?;
|
.await?;
|
||||||
Ok(context
|
Ok(context
|
||||||
.handler
|
.handler
|
||||||
.get_user_details(UserDetailsRequest { user_id: user.id })
|
.get_user_details(&user.id)
|
||||||
.await
|
.await
|
||||||
.map(Into::into)?)
|
.map(Into::into)?)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::domain::handler::BackendHandler;
|
use crate::domain::handler::BackendHandler;
|
||||||
use juniper::{graphql_object, FieldResult, GraphQLInputObject};
|
use juniper::{graphql_object, FieldResult, GraphQLInputObject};
|
||||||
use lldap_model::UserDetailsRequest;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
@ -95,7 +94,7 @@ impl<Handler: BackendHandler + Sync> Query<Handler> {
|
|||||||
}
|
}
|
||||||
Ok(context
|
Ok(context
|
||||||
.handler
|
.handler
|
||||||
.get_user_details(UserDetailsRequest { user_id })
|
.get_user_details(&user_id)
|
||||||
.await
|
.await
|
||||||
.map(Into::into)?)
|
.map(Into::into)?)
|
||||||
}
|
}
|
||||||
@ -242,9 +241,7 @@ mod tests {
|
|||||||
|
|
||||||
let mut mock = MockTestBackendHandler::new();
|
let mut mock = MockTestBackendHandler::new();
|
||||||
mock.expect_get_user_details()
|
mock.expect_get_user_details()
|
||||||
.with(eq(UserDetailsRequest {
|
.with(eq("bob"))
|
||||||
user_id: "bob".to_string(),
|
|
||||||
}))
|
|
||||||
.return_once(|_| {
|
.return_once(|_| {
|
||||||
Ok(lldap_model::User {
|
Ok(lldap_model::User {
|
||||||
user_id: "bob".to_string(),
|
user_id: "bob".to_string(),
|
||||||
|
@ -28,7 +28,7 @@ mockall::mock! {
|
|||||||
impl BackendHandler for TestTcpBackendHandler {
|
impl BackendHandler for TestTcpBackendHandler {
|
||||||
async fn list_users(&self, filters: Option<RequestFilter>) -> DomainResult<Vec<User>>;
|
async fn list_users(&self, filters: Option<RequestFilter>) -> DomainResult<Vec<User>>;
|
||||||
async fn list_groups(&self) -> DomainResult<Vec<Group>>;
|
async fn list_groups(&self) -> DomainResult<Vec<Group>>;
|
||||||
async fn get_user_details(&self, request: UserDetailsRequest) -> DomainResult<User>;
|
async fn get_user_details(&self, user_id: &str) -> DomainResult<User>;
|
||||||
async fn get_user_groups(&self, user: &str) -> DomainResult<HashSet<String>>;
|
async fn get_user_groups(&self, user: &str) -> DomainResult<HashSet<String>>;
|
||||||
async fn create_user(&self, request: CreateUserRequest) -> DomainResult<()>;
|
async fn create_user(&self, request: CreateUserRequest) -> DomainResult<()>;
|
||||||
async fn delete_user(&self, request: DeleteUserRequest) -> DomainResult<()>;
|
async fn delete_user(&self, request: DeleteUserRequest) -> DomainResult<()>;
|
||||||
|
Loading…
Reference in New Issue
Block a user