graphql: Add methods to add/remove group memberships
This commit is contained in:
committed by
nitnelave
parent
a54e73bded
commit
e4d6b122c5
@@ -1,4 +1,4 @@
|
||||
use crate::domain::handler::{BackendHandler, CreateUserRequest, UpdateUserRequest};
|
||||
use crate::domain::handler::{BackendHandler, CreateUserRequest, GroupId, UpdateUserRequest};
|
||||
use juniper::{graphql_object, FieldResult, GraphQLInputObject, GraphQLObject};
|
||||
|
||||
use super::api::Context;
|
||||
@@ -93,4 +93,34 @@ impl<Handler: BackendHandler + Sync> Mutation<Handler> {
|
||||
.await?;
|
||||
Ok(Success::new())
|
||||
}
|
||||
|
||||
async fn add_user_to_group(
|
||||
context: &Context<Handler>,
|
||||
user_id: String,
|
||||
group_id: i32,
|
||||
) -> FieldResult<Success> {
|
||||
if !context.validation_result.is_admin {
|
||||
return Err("Unauthorized group membership modification".into());
|
||||
}
|
||||
context
|
||||
.handler
|
||||
.add_user_to_group(&user_id, GroupId(group_id))
|
||||
.await?;
|
||||
Ok(Success::new())
|
||||
}
|
||||
|
||||
async fn remove_user_from_group(
|
||||
context: &Context<Handler>,
|
||||
user_id: String,
|
||||
group_id: i32,
|
||||
) -> FieldResult<Success> {
|
||||
if !context.validation_result.is_admin {
|
||||
return Err("Unauthorized group membership modification".into());
|
||||
}
|
||||
context
|
||||
.handler
|
||||
.remove_user_from_group(&user_id, GroupId(group_id))
|
||||
.await?;
|
||||
Ok(Success::new())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ mockall::mock! {
|
||||
async fn delete_user(&self, user_id: &str) -> DomainResult<()>;
|
||||
async fn create_group(&self, group_name: &str) -> DomainResult<GroupId>;
|
||||
async fn add_user_to_group(&self, user_id: &str, group_id: GroupId) -> DomainResult<()>;
|
||||
async fn remove_user_from_group(&self, user_id: &str, group_id: GroupId) -> DomainResult<()>;
|
||||
}
|
||||
#[async_trait]
|
||||
impl TcpBackendHandler for TestTcpBackendHandler {
|
||||
|
||||
Reference in New Issue
Block a user