graphql: Add a method to update group details
This commit is contained in:
committed by
nitnelave
parent
3b70762b42
commit
c0d866b77b
@@ -1,4 +1,6 @@
|
||||
use crate::domain::handler::{BackendHandler, CreateUserRequest, GroupId, UpdateUserRequest};
|
||||
use crate::domain::handler::{
|
||||
BackendHandler, CreateUserRequest, GroupId, UpdateGroupRequest, UpdateUserRequest,
|
||||
};
|
||||
use juniper::{graphql_object, FieldResult, GraphQLInputObject, GraphQLObject};
|
||||
|
||||
use super::api::Context;
|
||||
@@ -37,6 +39,13 @@ pub struct UpdateUserInput {
|
||||
last_name: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, GraphQLInputObject)]
|
||||
/// The fields that can be updated for a group.
|
||||
pub struct UpdateGroupInput {
|
||||
id: i32,
|
||||
display_name: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, GraphQLObject)]
|
||||
pub struct Success {
|
||||
ok: bool,
|
||||
@@ -94,6 +103,23 @@ impl<Handler: BackendHandler + Sync> Mutation<Handler> {
|
||||
Ok(Success::new())
|
||||
}
|
||||
|
||||
async fn update_group(
|
||||
context: &Context<Handler>,
|
||||
group: UpdateGroupInput,
|
||||
) -> FieldResult<Success> {
|
||||
if !context.validation_result.is_admin {
|
||||
return Err("Unauthorized group update".into());
|
||||
}
|
||||
context
|
||||
.handler
|
||||
.update_group(UpdateGroupRequest {
|
||||
group_id: GroupId(group.id),
|
||||
display_name: group.display_name,
|
||||
})
|
||||
.await?;
|
||||
Ok(Success::new())
|
||||
}
|
||||
|
||||
async fn add_user_to_group(
|
||||
context: &Context<Handler>,
|
||||
user_id: String,
|
||||
|
||||
@@ -32,6 +32,7 @@ mockall::mock! {
|
||||
async fn get_user_groups(&self, user: &str) -> DomainResult<HashSet<GroupIdAndName>>;
|
||||
async fn create_user(&self, request: CreateUserRequest) -> DomainResult<()>;
|
||||
async fn update_user(&self, request: UpdateUserRequest) -> DomainResult<()>;
|
||||
async fn update_group(&self, request: UpdateGroupRequest) -> DomainResult<()>;
|
||||
async fn delete_user(&self, user_id: &str) -> DomainResult<()>;
|
||||
async fn create_group(&self, group_name: &str) -> DomainResult<GroupId>;
|
||||
async fn delete_group(&self, group_id: GroupId) -> DomainResult<()>;
|
||||
|
||||
Reference in New Issue
Block a user