tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
UserMutations.cs
Go to the documentation of this file.
1using System;
3using System.Linq;
6
7using HotChocolate;
10
19
21{
26 [GraphQLDescription(Mutation.GraphQLDescription)]
27 public sealed class UserMutations
28 {
43 string name,
44 string password,
45 bool? enabled,
46 IEnumerable<OAuthConnection>? oAuthConnections,
47 PermissionSetInput? permissionSet,
48 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
49 CancellationToken cancellationToken)
50 {
51 ArgumentNullException.ThrowIfNull(name);
52 ArgumentNullException.ThrowIfNull(password);
53 ArgumentNullException.ThrowIfNull(userAuthority);
54
55 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
56 authority => authority.Create(
58 {
59 Name = name,
60 Password = password,
62 PermissionSet = permissionSet != null
64 {
67 }
68 : null,
69 OAuthConnections = oAuthConnections
70 ?.Select(oAuthConnection => new Api.Models.OAuthConnection
71 {
72 ExternalUserId = oAuthConnection.ExternalUserId,
73 Provider = oAuthConnection.Provider,
74 })
75 .ToList(),
76 },
77 false,
79 }
80
94 public ValueTask<User> CreateUserByPasswordAndGroup(
95 string name,
96 string password,
97 bool? enabled,
98 IEnumerable<OAuthConnection>? oAuthConnections,
99 [ID(nameof(UserGroup))] long groupId,
100 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
101 CancellationToken cancellationToken)
102 {
103 ArgumentNullException.ThrowIfNull(name);
104 ArgumentNullException.ThrowIfNull(password);
105 ArgumentNullException.ThrowIfNull(userAuthority);
106
107 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
108 authority => authority.Create(
110 {
111 Name = name,
112 Password = password,
115 {
116 Id = groupId,
117 },
118 OAuthConnections = oAuthConnections
119 ?.Select(oAuthConnection => new Api.Models.OAuthConnection
120 {
121 ExternalUserId = oAuthConnection.ExternalUserId,
122 Provider = oAuthConnection.Provider,
123 })
124 .ToList(),
125 },
126 false,
128 }
129
142 public ValueTask<User> CreateUserByOAuthAndPermissionSet(
143 string name,
144 IEnumerable<OAuthConnection> oAuthConnections,
145 bool? enabled,
146 PermissionSetInput? permissionSet,
147 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
148 CancellationToken cancellationToken)
149 {
150 ArgumentNullException.ThrowIfNull(name);
151 ArgumentNullException.ThrowIfNull(oAuthConnections);
152 ArgumentNullException.ThrowIfNull(userAuthority);
153
154 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
155 authority => authority.Create(
157 {
158 Name = name,
159 Password = String.Empty,
161 PermissionSet = permissionSet != null
163 {
166 }
167 : null,
168 OAuthConnections = oAuthConnections
169 .Select(oAuthConnection => new Api.Models.OAuthConnection
170 {
171 ExternalUserId = oAuthConnection.ExternalUserId,
172 Provider = oAuthConnection.Provider,
173 })
174 .ToList(),
175 },
176 true,
178 }
179
192 public ValueTask<User> CreateUserByOAuthAndGroup(
193 string name,
194 IEnumerable<OAuthConnection> oAuthConnections,
195 [ID(nameof(UserGroup))] long groupId,
196 bool? enabled,
197 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
198 CancellationToken cancellationToken)
199 {
200 ArgumentNullException.ThrowIfNull(name);
201 ArgumentNullException.ThrowIfNull(oAuthConnections);
202 ArgumentNullException.ThrowIfNull(userAuthority);
203
204 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
205 authority => authority.Create(
207 {
208 Name = name,
209 Password = String.Empty,
212 {
213 Id = groupId,
214 },
215 OAuthConnections = oAuthConnections
216 .Select(oAuthConnection => new Api.Models.OAuthConnection
217 {
218 ExternalUserId = oAuthConnection.ExternalUserId,
219 Provider = oAuthConnection.Provider,
220 })
221 .ToList(),
222 },
223 true,
225 }
226
240 string systemIdentifier,
241 bool? enabled,
242 IEnumerable<OAuthConnection>? oAuthConnections,
243 PermissionSetInput permissionSet,
244 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
245 CancellationToken cancellationToken)
246 {
248 ArgumentNullException.ThrowIfNull(userAuthority);
249
250 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
251 authority => authority.Create(
253 {
254 SystemIdentifier = systemIdentifier,
256 PermissionSet = permissionSet != null
258 {
261 }
262 : null,
263 OAuthConnections = oAuthConnections
264 ?.Select(oAuthConnection => new Api.Models.OAuthConnection
265 {
266 ExternalUserId = oAuthConnection.ExternalUserId,
267 Provider = oAuthConnection.Provider,
268 })
269 .ToList(),
270 },
271 false,
273 }
274
287 public ValueTask<User> CreateUserBySystemIDAndGroup(
288 string systemIdentifier,
289 bool? enabled,
290 [ID(nameof(UserGroup))] long groupId,
291 IEnumerable<OAuthConnection>? oAuthConnections,
292 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
293 CancellationToken cancellationToken)
294 {
296 ArgumentNullException.ThrowIfNull(userAuthority);
297
298 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
299 authority => authority.Create(
301 {
302 SystemIdentifier = systemIdentifier,
305 {
306 Id = groupId,
307 },
308 OAuthConnections = oAuthConnections
309 ?.Select(oAuthConnection => new Api.Models.OAuthConnection
310 {
311 ExternalUserId = oAuthConnection.ExternalUserId,
312 Provider = oAuthConnection.Provider,
313 })
314 .ToList(),
315 },
316 false,
318 }
319
330 public ValueTask<User> SetCurrentUserPassword(
331 string newPassword,
332 [Service] IAuthenticationContext authenticationContext,
333 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
334 CancellationToken cancellationToken)
335 {
337 ArgumentNullException.ThrowIfNull(userAuthority);
338 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
339 async authority => await authority.Update(
341 {
342 Id = authenticationContext.User.Id,
343 Password = newPassword,
344 },
346 }
347
356 [TgsGraphQLAuthorize(AdministrationRights.WriteUsers | AdministrationRights.EditOwnOAuthConnections)]
358 public ValueTask<User> SetCurrentOAuthConnections(
360 [Service] IAuthenticationContext authenticationContext,
361 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
362 CancellationToken cancellationToken)
363 {
365 ArgumentNullException.ThrowIfNull(userAuthority);
366 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
367 async authority => await authority.Update(
369 {
370 Id = authenticationContext.User.Id,
371 OAuthConnections = newOAuthConnections
372 .Select(oAuthConnection => new Api.Models.OAuthConnection
373 {
374 ExternalUserId = oAuthConnection.ExternalUserId,
375 Provider = oAuthConnection.Provider,
376 })
377 .ToList(),
378 },
380 }
381
395 public ValueTask<User> UpdateUser(
396 [ID(nameof(User))] long id,
397 string? casingOnlyNameChange,
398 string? newPassword,
399 bool? enabled,
401 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
402 CancellationToken cancellationToken)
403 {
404 ArgumentNullException.ThrowIfNull(userAuthority);
405 return UpdateUserCore(
406 id,
409 enabled,
410 null,
411 null,
413 userAuthority,
415 }
416
431 public ValueTask<User> UpdateUserSetOwnedPermissionSet(
432 [ID(nameof(User))] long id,
433 string? casingOnlyNameChange,
434 string? newPassword,
435 bool? enabled,
438 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
439 CancellationToken cancellationToken)
440 {
441 ArgumentNullException.ThrowIfNull(userAuthority);
442 return UpdateUserCore(
443 id,
446 enabled,
448 null,
450 userAuthority,
452 }
453
468 public ValueTask<User> UpdateUserSetGroup(
469 [ID(nameof(User))] long id,
470 string? casingOnlyNameChange,
471 string? newPassword,
472 bool? enabled,
473 [ID(nameof(UserGroup))] long newGroupId,
475 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
476 CancellationToken cancellationToken)
477 {
478 ArgumentNullException.ThrowIfNull(userAuthority);
479 return UpdateUserCore(
480 id,
483 enabled,
484 null,
487 userAuthority,
489 }
490
504 ValueTask<User> UpdateUserCore(
505 [ID(nameof(User))] long id,
506 string? casingOnlyNameChange,
507 string? newPassword,
508 bool? enabled,
510 long? newGroupId,
513 CancellationToken cancellationToken)
514 => userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
515 async authority => await authority.Update(
517 {
518 Id = id,
520 Password = newPassword,
524 {
526 AdministrationRights = newPermissionSet.AdministrationRights,
527 }
528 : null,
529 Group = newGroupId.HasValue
531 {
532 Id = newGroupId.Value,
533 }
534 : null,
535 OAuthConnections = newOAuthConnections
536 ?.Select(oAuthConnection => new Api.Models.OAuthConnection
537 {
538 ExternalUserId = oAuthConnection.ExternalUserId,
539 Provider = oAuthConnection.Provider,
540 })
541 .ToList(),
542 },
544 }
545}
virtual ? long Id
The ID of the entity.
Definition EntityId.cs:13
Represents a set of server permissions.
InstanceManagerRights? InstanceManagerRights
The Rights.InstanceManagerRights for the user.
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.
required? InstanceManagerRights InstanceManagerRights
The Api.Rights.InstanceManagerRights for the Types.PermissionSet.
required? AdministrationRights AdministrationRights
The Api.Rights.AdministrationRights for the Types.PermissionSet.
ValueTask< User > CreateUserByPasswordAndGroup(string name, string password, bool? enabled, IEnumerable< OAuthConnection >? oAuthConnections, [ID(nameof(UserGroup))] long groupId, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Creates a TGS user specifying the UserGroup they will belong to.
ValueTask< User > UpdateUser([ID(nameof(User))] long id, string? casingOnlyNameChange, string? newPassword, bool? enabled, IEnumerable< OAuthConnection >? newOAuthConnections, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Updates a Users properties.
ValueTask< User > CreateUserBySystemIDAndPermissionSet(string systemIdentifier, bool? enabled, IEnumerable< OAuthConnection >? oAuthConnections, PermissionSetInput permissionSet, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Creates a system user specifying a personal PermissionSet.
ValueTask< User > UpdateUserSetOwnedPermissionSet([ID(nameof(User))] long id, string? casingOnlyNameChange, string? newPassword, bool? enabled, PermissionSetInput newPermissionSet, IEnumerable< OAuthConnection >? newOAuthConnections, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Updates a User, setting new values for its owned PermissionSet.
ValueTask< User > UpdateUserCore([ID(nameof(User))] long id, string? casingOnlyNameChange, string? newPassword, bool? enabled, PermissionSetInput? newPermissionSet, long? newGroupId, IEnumerable< OAuthConnection >? newOAuthConnections, IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Updates a user.
ValueTask< User > CreateUserByOAuthAndGroup(string name, IEnumerable< OAuthConnection > oAuthConnections, [ID(nameof(UserGroup))] long groupId, bool? enabled, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Creates a TGS user specifying the UserGroup they will belong to.
ValueTask< User > CreateUserBySystemIDAndGroup(string systemIdentifier, bool? enabled, [ID(nameof(UserGroup))] long groupId, IEnumerable< OAuthConnection >? oAuthConnections, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Creates a system user specifying the UserGroup they will belong to.
ValueTask< User > CreateUserByPasswordAndPermissionSet(string name, string password, bool? enabled, IEnumerable< OAuthConnection >? oAuthConnections, PermissionSetInput? permissionSet, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Creates a TGS user specifying a personal PermissionSet.
ValueTask< User > SetCurrentOAuthConnections(IEnumerable< OAuthConnection > newOAuthConnections, [Service] IAuthenticationContext authenticationContext, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Sets the current user's OAuthConnections.
ValueTask< User > UpdateUserSetGroup([ID(nameof(User))] long id, string? casingOnlyNameChange, string? newPassword, bool? enabled, [ID(nameof(UserGroup))] long newGroupId, IEnumerable< OAuthConnection >? newOAuthConnections, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Updates a User, setting new values for its owned PermissionSet.
ValueTask< User > CreateUserByOAuthAndPermissionSet(string name, IEnumerable< OAuthConnection > oAuthConnections, bool? enabled, PermissionSetInput? permissionSet, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Creates a TGS user authenticated with one or mor OAuthConnections specifying a personal PermissionSet...
ValueTask< User > SetCurrentUserPassword(string newPassword, [Service] IAuthenticationContext authenticationContext, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Sets the current user's password.
Represents a set of permissions for the server.
A user registered in the server.
Definition User.cs:21
ITransformer<TInput, TOutput> for GraphQL.Types.Users.
ValueTask< AuthorityResponse< User > > Create(UserCreateRequest createRequest, bool? needZeroLengthPasswordWithOAuthConnections, CancellationToken cancellationToken)
Creates a User.
For creating and accessing authentication contexts.
@ List
User may list files if the Models.Instance allows it.
InstanceManagerRights
Rights for managing Models.Instances.
AdministrationRights
Administration rights for the server.
@ Id
Lookup the Api.Models.EntityId.Id of the Models.PermissionSet.
@ Enabled
The OAuth Gateway is enabled.