graphql: Add a method to create a group

This commit is contained in:
Valentin Tolmer 2021-10-11 18:45:25 +02:00 committed by nitnelave
parent 8bd1dec180
commit 35ee2834a3
2 changed files with 16 additions and 0 deletions

View File

@ -5,6 +5,7 @@ input EqualityConstraint {
type Mutation {
createUser(user: CreateUserInput!): User!
createGroup(name: String!): Group!
updateUser(user: UpdateUserInput!): Success!
updateGroup(group: UpdateGroupInput!): Success!
addUserToGroup(userId: String!, groupId: Int!): Success!

View File

@ -83,6 +83,21 @@ impl<Handler: BackendHandler + Sync> Mutation<Handler> {
.map(Into::into)?)
}
async fn create_group(
context: &Context<Handler>,
name: String,
) -> FieldResult<super::query::Group<Handler>> {
if !context.validation_result.is_admin {
return Err("Unauthorized group creation".into());
}
let group_id = context.handler.create_group(&name).await?;
Ok(context
.handler
.get_group_details(group_id)
.await
.map(Into::into)?)
}
async fn update_user(
context: &Context<Handler>,
user: UpdateUserInput,