tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
UserGroupMutations.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4
5using HotChocolate;
6using HotChocolate.Types;
7using HotChocolate.Types.Relay;
8
14
16{
20 [ExtendObjectType(typeof(Mutation))]
21 [GraphQLDescription(Mutation.GraphQLDescription)]
22 public sealed class UserGroupMutations
23 {
29 static Models.PermissionSet? TransformApiPermissionSet(PermissionSetInput? permissionSet)
30 => permissionSet != null
32 {
33 InstanceManagerRights = permissionSet?.InstanceManagerRights,
34 AdministrationRights = permissionSet?.AdministrationRights,
35 }
36 : null;
37
46 [TgsGraphQLAuthorize<IUserGroupAuthority>(nameof(IUserGroupAuthority.Create))]
47 [Error(typeof(ErrorMessageException))]
48 public ValueTask<UserGroup> CreateUserGroup(
49 string name,
50 PermissionSetInput? permissionSet,
51 [Service] IGraphQLAuthorityInvoker<IUserGroupAuthority> userGroupAuthority,
52 CancellationToken cancellationToken)
53 {
54 ArgumentNullException.ThrowIfNull(name);
55 ArgumentNullException.ThrowIfNull(userGroupAuthority);
56
57 return userGroupAuthority.InvokeTransformable<Models.UserGroup, UserGroup, UserGroupGraphQLTransformer>(
58 authority => authority.Create(name, TransformApiPermissionSet(permissionSet), cancellationToken));
59 }
60
70 [TgsGraphQLAuthorize<IUserGroupAuthority>(nameof(IUserGroupAuthority.Update))]
71 [Error(typeof(ErrorMessageException))]
72 public ValueTask<UserGroup> UpdateUserGroup(
73 [ID(nameof(UserGroup))] long id,
74 string? newName,
75 PermissionSetInput? newPermissionSet,
76 [Service] IGraphQLAuthorityInvoker<IUserGroupAuthority> userGroupAuthority,
77 CancellationToken cancellationToken)
78 {
79 ArgumentNullException.ThrowIfNull(userGroupAuthority);
80 return userGroupAuthority.InvokeTransformable<Models.UserGroup, UserGroup, UserGroupGraphQLTransformer>(
81 authority => authority.Update(id, newName, TransformApiPermissionSet(newPermissionSet), cancellationToken));
82 }
83
91 [TgsGraphQLAuthorize<IUserGroupAuthority>(nameof(IUserGroupAuthority.DeleteEmpty))]
92 [Error(typeof(ErrorMessageException))]
93 public async ValueTask<Query> DeleteEmptyUserGroup(
94 [ID(nameof(UserGroup))] long id,
95 [Service] IGraphQLAuthorityInvoker<IUserGroupAuthority> userGroupAuthority,
96 CancellationToken cancellationToken)
97 {
98 ArgumentNullException.ThrowIfNull(userGroupAuthority);
99 await userGroupAuthority.Invoke(
100 authority => authority.DeleteEmpty(id, cancellationToken));
101
102 return new Query();
103 }
104 }
105}
Exception representing ErrorMessageResponses.
Root type for GraphQL mutations.
Definition Mutation.cs:19
const string GraphQLDescription
Description to show on the Mutation type.
Definition Mutation.cs:23
Updates a set of permissions for the server. null values default to their "None" variants.
static Models.? PermissionSet TransformApiPermissionSet(PermissionSetInput? permissionSet)
Transform a Api.Models.PermissionSet into a PermissionSet.
ValueTask< UserGroup > UpdateUserGroup([ID(nameof(UserGroup))] long id, string? newName, PermissionSetInput? newPermissionSet, [Service] IGraphQLAuthorityInvoker< IUserGroupAuthority > userGroupAuthority, CancellationToken cancellationToken)
Updates a UserGroup.
async ValueTask< Query > DeleteEmptyUserGroup([ID(nameof(UserGroup))] long id, [Service] IGraphQLAuthorityInvoker< IUserGroupAuthority > userGroupAuthority, CancellationToken cancellationToken)
Deletes a UserGroup.
ValueTask< UserGroup > CreateUserGroup(string name, PermissionSetInput? permissionSet, [Service] IGraphQLAuthorityInvoker< IUserGroupAuthority > userGroupAuthority, CancellationToken cancellationToken)
Creates a UserGroup.
GraphQL query global::System.Type.
Definition Query.cs:12
ITransformer<TInput, TOutput> for GraphQL.Types.UserGroups.
ValueTask< AuthorityResponse< UserGroup > > Update(long id, string? newName, PermissionSet? newPermissionSet, CancellationToken cancellationToken)
Updates a UserGroup.
ValueTask< AuthorityResponse< UserGroup > > Create(string name, PermissionSet? permissionSet, CancellationToken cancellationToken)
Create a UserGroup.
ValueTask< AuthorityResponse > DeleteEmpty(long id, CancellationToken cancellationToken)
Deletes an empty UserGroup.