model: remove CreateGroupRequest

This commit is contained in:
Valentin Tolmer 2021-08-31 15:57:01 +02:00 committed by nitnelave
parent 4af60e5668
commit 54f973e349
5 changed files with 9 additions and 21 deletions

View File

@ -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,

View File

@ -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<()>;
}

View File

@ -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) {

View File

@ -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]

View File

@ -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