tgstation-server 6.19.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
UserGroups.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3using System.Threading;
4using System.Threading.Tasks;
5
6using HotChocolate;
7using HotChocolate.Authorization;
8using HotChocolate.Data;
9using HotChocolate.Types;
10using HotChocolate.Types.Relay;
11
14
16{
20 [Authorize]
21 public sealed class UserGroups
22 {
29 public ValueTask<UserGroup?> Current(
30 [Service] IGraphQLAuthorityInvoker<IUserGroupAuthority> userGroupAuthority,
31 CancellationToken cancellationToken)
32 {
33 ArgumentNullException.ThrowIfNull(userGroupAuthority);
34 return userGroupAuthority.InvokeTransformableAllowMissing<Models.UserGroup, UserGroup, UserGroupGraphQLTransformer>(authority => authority.Read(cancellationToken));
35 }
36
44 public ValueTask<UserGroup?> ById(
45 [ID(nameof(UserGroup))] long id,
46 [Service] IGraphQLAuthorityInvoker<IUserGroupAuthority> userGroupAuthority,
47 CancellationToken cancellationToken)
48 => UserGroup.GetUserGroup(id, userGroupAuthority, cancellationToken);
49
55 [UsePaging]
56 [UseFiltering]
57 [UseSorting]
58 public async ValueTask<IQueryable<UserGroup>> QueryableGroups(
59 [Service] IGraphQLAuthorityInvoker<IUserGroupAuthority> userGroupAuthority)
60 {
61 ArgumentNullException.ThrowIfNull(userGroupAuthority);
62 var dtoQueryable = await userGroupAuthority.InvokeTransformableQueryable<Models.UserGroup, UserGroup, UserGroupGraphQLTransformer>(
63 authority => authority.Queryable(false));
64 return dtoQueryable;
65 }
66
73 [UsePaging]
74 [UseFiltering]
75 [UseSorting]
76 public async ValueTask<IQueryable<User>> QueryableUsersByGroupId(
77 [ID(nameof(UserGroup))]long groupId,
78 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority)
79 {
80 ArgumentNullException.ThrowIfNull(userAuthority);
81 var dtoQueryable = await userAuthority.InvokeTransformableQueryable<Models.User, User, UserGraphQLTransformer>(
82 authority => authority
83 .Queryable(false),
84 queryable => queryable.Where(user => user.GroupId == groupId));
85 return dtoQueryable;
86 }
87 }
88}
static ValueTask< UserGroup?> GetUserGroup(long id, [Service] IGraphQLAuthorityInvoker< IUserGroupAuthority > userGroupAuthority, CancellationToken cancellationToken)
Node resolver for Users.
Definition UserGroup.cs:31
Wrapper for accessing UserGroups.
Definition UserGroups.cs:22
async ValueTask< IQueryable< User > > QueryableUsersByGroupId([ID(nameof(UserGroup))]long groupId, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority)
Queries all registered Users in a UserGroup indicated by groupId .
Definition UserGroups.cs:76
async ValueTask< IQueryable< UserGroup > > QueryableGroups([Service] IGraphQLAuthorityInvoker< IUserGroupAuthority > userGroupAuthority)
Queries all registered UserGroups.
Definition UserGroups.cs:58
ValueTask< UserGroup?> Current([Service] IGraphQLAuthorityInvoker< IUserGroupAuthority > userGroupAuthority, CancellationToken cancellationToken)
Gets the current User.
Definition UserGroups.cs:29
ValueTask< UserGroup?> ById([ID(nameof(UserGroup))] long id, [Service] IGraphQLAuthorityInvoker< IUserGroupAuthority > userGroupAuthority, CancellationToken cancellationToken)
Gets a UserGroup by Entity.Id.
A user registered in the server.
Definition User.cs:22
ITransformer<TInput, TOutput> for GraphQL.Types.Users.
ITransformer<TInput, TOutput> for GraphQL.Types.UserGroups.