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>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||
pub struct CreateGroupRequest {
|
||||
pub display_name: String,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||
pub struct AddUserToGroupRequest {
|
||||
pub user_id: String,
|
||||
|
@ -3,7 +3,7 @@ use async_trait::async_trait;
|
||||
use serde::{Deserialize, Serialize};
|
||||
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)]
|
||||
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 create_user(&self, request: CreateUserRequest) -> 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 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 create_user(&self, request: CreateUserRequest) -> 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 add_user_to_group(&self, request: AddUserToGroupRequest) -> Result<()>;
|
||||
}
|
||||
|
@ -202,17 +202,17 @@ impl BackendHandler for SqlBackendHandler {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn create_group(&self, request: CreateGroupRequest) -> Result<i32> {
|
||||
async fn create_group(&self, group_name: &str) -> Result<i32> {
|
||||
let query = Query::insert()
|
||||
.into_table(Groups::Table)
|
||||
.columns(vec![Groups::DisplayName])
|
||||
.values_panic(vec![request.display_name.as_str().into()])
|
||||
.values_panic(vec![group_name.into()])
|
||||
.to_string(DbQueryBuilder {});
|
||||
sqlx::query(&query).execute(&self.sql_pool).await?;
|
||||
let query = Query::select()
|
||||
.column(Groups::GroupId)
|
||||
.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 {});
|
||||
let row = sqlx::query(&query).fetch_one(&self.sql_pool).await?;
|
||||
Ok(row.get::<i32, _>(&*Groups::GroupId.to_string()))
|
||||
@ -293,12 +293,7 @@ mod tests {
|
||||
}
|
||||
|
||||
async fn insert_group(handler: &SqlBackendHandler, name: &str) -> i32 {
|
||||
handler
|
||||
.create_group(CreateGroupRequest {
|
||||
display_name: name.to_string(),
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
handler.create_group(name).await.unwrap()
|
||||
}
|
||||
|
||||
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 create_user(&self, request: CreateUserRequest) -> 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_trait]
|
||||
|
@ -28,9 +28,7 @@ async fn create_admin_user(handler: &SqlBackendHandler, config: &Configuration)
|
||||
.await
|
||||
.context("Error creating admin user")?;
|
||||
let admin_group_id = handler
|
||||
.create_group(lldap_model::CreateGroupRequest {
|
||||
display_name: "lldap_admin".to_string(),
|
||||
})
|
||||
.create_group("lldap_admin")
|
||||
.await
|
||||
.context("Error creating admin group")?;
|
||||
handler
|
||||
|
Loading…
Reference in New Issue
Block a user