mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
model: remove CreateGroupRequest
This commit is contained in:
parent
4af60e5668
commit
54f973e349
@ -98,11 +98,6 @@ pub struct Group {
|
|||||||
pub users: Vec<String>,
|
pub users: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct CreateGroupRequest {
|
|
||||||
pub display_name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
|
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||||
pub struct AddUserToGroupRequest {
|
pub struct AddUserToGroupRequest {
|
||||||
pub user_id: String,
|
pub user_id: String,
|
||||||
|
@ -3,7 +3,7 @@ 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::{AddUserToGroupRequest, CreateGroupRequest, Group, User};
|
pub use lldap_model::{AddUserToGroupRequest, Group, User};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
|
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct BindRequest {
|
pub struct BindRequest {
|
||||||
@ -41,7 +41,7 @@ pub trait BackendHandler: Clone + Send {
|
|||||||
async fn get_user_details(&self, user_id: &str) -> 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, user_id: &str) -> Result<()>;
|
async fn delete_user(&self, user_id: &str) -> Result<()>;
|
||||||
async fn create_group(&self, request: CreateGroupRequest) -> Result<i32>;
|
async fn create_group(&self, group_name: &str) -> Result<i32>;
|
||||||
async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> Result<()>;
|
async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> Result<()>;
|
||||||
async fn get_user_groups(&self, user: &str) -> Result<HashSet<String>>;
|
async fn get_user_groups(&self, user: &str) -> Result<HashSet<String>>;
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ mockall::mock! {
|
|||||||
async fn get_user_details(&self, user_id: &str) -> 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, user_id: &str) -> Result<()>;
|
async fn delete_user(&self, user_id: &str) -> Result<()>;
|
||||||
async fn create_group(&self, request: CreateGroupRequest) -> Result<i32>;
|
async fn create_group(&self, group_name: &str) -> Result<i32>;
|
||||||
async fn get_user_groups(&self, user: &str) -> Result<HashSet<String>>;
|
async fn get_user_groups(&self, user: &str) -> Result<HashSet<String>>;
|
||||||
async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> Result<()>;
|
async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
@ -202,17 +202,17 @@ impl BackendHandler for SqlBackendHandler {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_group(&self, request: CreateGroupRequest) -> Result<i32> {
|
async fn create_group(&self, group_name: &str) -> Result<i32> {
|
||||||
let query = Query::insert()
|
let query = Query::insert()
|
||||||
.into_table(Groups::Table)
|
.into_table(Groups::Table)
|
||||||
.columns(vec![Groups::DisplayName])
|
.columns(vec![Groups::DisplayName])
|
||||||
.values_panic(vec![request.display_name.as_str().into()])
|
.values_panic(vec![group_name.into()])
|
||||||
.to_string(DbQueryBuilder {});
|
.to_string(DbQueryBuilder {});
|
||||||
sqlx::query(&query).execute(&self.sql_pool).await?;
|
sqlx::query(&query).execute(&self.sql_pool).await?;
|
||||||
let query = Query::select()
|
let query = Query::select()
|
||||||
.column(Groups::GroupId)
|
.column(Groups::GroupId)
|
||||||
.from(Groups::Table)
|
.from(Groups::Table)
|
||||||
.and_where(Expr::col(Groups::DisplayName).eq(request.display_name.as_str()))
|
.and_where(Expr::col(Groups::DisplayName).eq(group_name))
|
||||||
.to_string(DbQueryBuilder {});
|
.to_string(DbQueryBuilder {});
|
||||||
let row = sqlx::query(&query).fetch_one(&self.sql_pool).await?;
|
let row = sqlx::query(&query).fetch_one(&self.sql_pool).await?;
|
||||||
Ok(row.get::<i32, _>(&*Groups::GroupId.to_string()))
|
Ok(row.get::<i32, _>(&*Groups::GroupId.to_string()))
|
||||||
@ -293,12 +293,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn insert_group(handler: &SqlBackendHandler, name: &str) -> i32 {
|
async fn insert_group(handler: &SqlBackendHandler, name: &str) -> i32 {
|
||||||
handler
|
handler.create_group(name).await.unwrap()
|
||||||
.create_group(CreateGroupRequest {
|
|
||||||
display_name: name.to_string(),
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn insert_membership(handler: &SqlBackendHandler, group_id: i32, user_id: &str) {
|
async fn insert_membership(handler: &SqlBackendHandler, group_id: i32, user_id: &str) {
|
||||||
|
@ -32,7 +32,7 @@ mockall::mock! {
|
|||||||
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, user_id: &str) -> DomainResult<()>;
|
async fn delete_user(&self, user_id: &str) -> DomainResult<()>;
|
||||||
async fn create_group(&self, request: CreateGroupRequest) -> DomainResult<i32>;
|
async fn create_group(&self, group_name: &str) -> DomainResult<i32>;
|
||||||
async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> DomainResult<()>;
|
async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> DomainResult<()>;
|
||||||
}
|
}
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
@ -28,9 +28,7 @@ async fn create_admin_user(handler: &SqlBackendHandler, config: &Configuration)
|
|||||||
.await
|
.await
|
||||||
.context("Error creating admin user")?;
|
.context("Error creating admin user")?;
|
||||||
let admin_group_id = handler
|
let admin_group_id = handler
|
||||||
.create_group(lldap_model::CreateGroupRequest {
|
.create_group("lldap_admin")
|
||||||
display_name: "lldap_admin".to_string(),
|
|
||||||
})
|
|
||||||
.await
|
.await
|
||||||
.context("Error creating admin group")?;
|
.context("Error creating admin group")?;
|
||||||
handler
|
handler
|
||||||
|
Loading…
Reference in New Issue
Block a user