graphql: Add a method to delete a user

This commit is contained in:
Valentin Tolmer 2021-09-24 09:14:18 +02:00 committed by nitnelave
parent 9e3315e09f
commit e8831f607b
2 changed files with 9 additions and 0 deletions

View File

@ -8,6 +8,7 @@ type Mutation {
updateUser(user: UpdateUserInput!): Success! updateUser(user: UpdateUserInput!): Success!
addUserToGroup(userId: String!, groupId: Int!): Success! addUserToGroup(userId: String!, groupId: Int!): Success!
removeUserFromGroup(userId: String!, groupId: Int!): Success! removeUserFromGroup(userId: String!, groupId: Int!): Success!
deleteUser(userId: String!): Success!
} }
type Group { type Group {

View File

@ -123,4 +123,12 @@ impl<Handler: BackendHandler + Sync> Mutation<Handler> {
.await?; .await?;
Ok(Success::new()) Ok(Success::new())
} }
async fn delete_user(context: &Context<Handler>, user_id: String) -> FieldResult<Success> {
if !context.validation_result.is_admin {
return Err("Unauthorized user deletion".into());
}
context.handler.delete_user(&user_id).await?;
Ok(Success::new())
}
} }