From e8831f607bca1edf9e21a3b9109943af3965b899 Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Fri, 24 Sep 2021 09:14:18 +0200 Subject: [PATCH] graphql: Add a method to delete a user --- schema.graphql | 1 + server/src/infra/graphql/mutation.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/schema.graphql b/schema.graphql index c167e30..d002ceb 100644 --- a/schema.graphql +++ b/schema.graphql @@ -8,6 +8,7 @@ type Mutation { updateUser(user: UpdateUserInput!): Success! addUserToGroup(userId: String!, groupId: Int!): Success! removeUserFromGroup(userId: String!, groupId: Int!): Success! + deleteUser(userId: String!): Success! } type Group { diff --git a/server/src/infra/graphql/mutation.rs b/server/src/infra/graphql/mutation.rs index 1ec4d29..b803ae9 100644 --- a/server/src/infra/graphql/mutation.rs +++ b/server/src/infra/graphql/mutation.rs @@ -123,4 +123,12 @@ impl Mutation { .await?; Ok(Success::new()) } + + async fn delete_user(context: &Context, user_id: String) -> FieldResult { + if !context.validation_result.is_admin { + return Err("Unauthorized user deletion".into()); + } + context.handler.delete_user(&user_id).await?; + Ok(Success::new()) + } }