mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
model: remove AddUserToGroupRequest
This commit is contained in:
parent
54f973e349
commit
641018ff56
@ -98,12 +98,6 @@ pub struct Group {
|
|||||||
pub users: Vec<String>,
|
pub users: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct AddUserToGroupRequest {
|
|
||||||
pub user_id: String,
|
|
||||||
pub group_id: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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,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, Group, User};
|
pub use lldap_model::{Group, User};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
|
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct BindRequest {
|
pub struct BindRequest {
|
||||||
@ -34,6 +34,9 @@ pub trait LoginHandler: Clone + Send {
|
|||||||
async fn bind(&self, request: BindRequest) -> Result<()>;
|
async fn bind(&self, request: BindRequest) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
|
pub struct GroupId(pub i32);
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
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>>;
|
||||||
@ -41,8 +44,8 @@ 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, group_name: &str) -> Result<i32>;
|
async fn create_group(&self, group_name: &str) -> Result<GroupId>;
|
||||||
async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> Result<()>;
|
async fn add_user_to_group(&self, user_id: &str, group_id: GroupId) -> Result<()>;
|
||||||
async fn get_user_groups(&self, user: &str) -> Result<HashSet<String>>;
|
async fn get_user_groups(&self, user: &str) -> Result<HashSet<String>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,9 +62,9 @@ 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, group_name: &str) -> Result<i32>;
|
async fn create_group(&self, group_name: &str) -> Result<GroupId>;
|
||||||
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, user_id: &str, group_id: GroupId) -> Result<()>;
|
||||||
}
|
}
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl LoginHandler for TestBackendHandler {
|
impl LoginHandler for TestBackendHandler {
|
||||||
|
@ -202,7 +202,7 @@ impl BackendHandler for SqlBackendHandler {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_group(&self, group_name: &str) -> Result<i32> {
|
async fn create_group(&self, group_name: &str) -> Result<GroupId> {
|
||||||
let query = Query::insert()
|
let query = Query::insert()
|
||||||
.into_table(Groups::Table)
|
.into_table(Groups::Table)
|
||||||
.columns(vec![Groups::DisplayName])
|
.columns(vec![Groups::DisplayName])
|
||||||
@ -215,14 +215,14 @@ impl BackendHandler for SqlBackendHandler {
|
|||||||
.and_where(Expr::col(Groups::DisplayName).eq(group_name))
|
.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(GroupId(row.get::<i32, _>(&*Groups::GroupId.to_string())))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> Result<()> {
|
async fn add_user_to_group(&self, user_id: &str, group_id: GroupId) -> Result<()> {
|
||||||
let query = Query::insert()
|
let query = Query::insert()
|
||||||
.into_table(Memberships::Table)
|
.into_table(Memberships::Table)
|
||||||
.columns(vec![Memberships::UserId, Memberships::GroupId])
|
.columns(vec![Memberships::UserId, Memberships::GroupId])
|
||||||
.values_panic(vec![request.user_id.into(), request.group_id.into()])
|
.values_panic(vec![user_id.into(), group_id.0.into()])
|
||||||
.to_string(DbQueryBuilder {});
|
.to_string(DbQueryBuilder {});
|
||||||
sqlx::query(&query).execute(&self.sql_pool).await?;
|
sqlx::query(&query).execute(&self.sql_pool).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -292,18 +292,12 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn insert_group(handler: &SqlBackendHandler, name: &str) -> i32 {
|
async fn insert_group(handler: &SqlBackendHandler, name: &str) -> GroupId {
|
||||||
handler.create_group(name).await.unwrap()
|
handler.create_group(name).await.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn insert_membership(handler: &SqlBackendHandler, group_id: i32, user_id: &str) {
|
async fn insert_membership(handler: &SqlBackendHandler, group_id: GroupId, user_id: &str) {
|
||||||
handler
|
handler.add_user_to_group(user_id, group_id).await.unwrap();
|
||||||
.add_user_to_group(AddUserToGroupRequest {
|
|
||||||
user_id: user_id.to_string(),
|
|
||||||
group_id,
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -32,8 +32,8 @@ 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, group_name: &str) -> DomainResult<i32>;
|
async fn create_group(&self, group_name: &str) -> DomainResult<GroupId>;
|
||||||
async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> DomainResult<()>;
|
async fn add_user_to_group(&self, user_id: &str, group_id: GroupId) -> DomainResult<()>;
|
||||||
}
|
}
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl TcpBackendHandler for TestTcpBackendHandler {
|
impl TcpBackendHandler for TestTcpBackendHandler {
|
||||||
|
@ -32,10 +32,7 @@ async fn create_admin_user(handler: &SqlBackendHandler, config: &Configuration)
|
|||||||
.await
|
.await
|
||||||
.context("Error creating admin group")?;
|
.context("Error creating admin group")?;
|
||||||
handler
|
handler
|
||||||
.add_user_to_group(lldap_model::AddUserToGroupRequest {
|
.add_user_to_group(&config.ldap_user_dn, admin_group_id)
|
||||||
user_id: config.ldap_user_dn.clone(),
|
|
||||||
group_id: admin_group_id,
|
|
||||||
})
|
|
||||||
.await
|
.await
|
||||||
.context("Error adding admin user to group")
|
.context("Error adding admin user to group")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user