tgstation-server 6.19.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
UserMutations.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Threading;
5using System.Threading.Tasks;
6
7using HotChocolate;
8using HotChocolate.Types;
9using HotChocolate.Types.Relay;
10
18
20{
24 [ExtendObjectType(typeof(Mutation))]
25 [GraphQLDescription(Mutation.GraphQLDescription)]
26 public sealed class UserMutations
27 {
40 [Error(typeof(ErrorMessageException))]
41 public ValueTask<UpdatedUser> CreateUserByPasswordAndPermissionSet(
42 string name,
43 string password,
44 bool? enabled,
45 IEnumerable<OAuthConnection>? oAuthConnections,
46 IEnumerable<OidcConnection>? oidcConnections,
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.UpdatedUser, UpdatedUser, UpdatedUserGraphQLTransformer>(
56 authority => authority.Create(
58 {
59 Name = name,
60 Password = password,
61 Enabled = enabled,
62 PermissionSet = permissionSet != null
64 {
65 AdministrationRights = permissionSet.AdministrationRights,
66 InstanceManagerRights = permissionSet.InstanceManagerRights,
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 OidcConnections = oidcConnections
77 ?.Select(oidcConnection => new Api.Models.OidcConnection
78 {
79 ExternalUserId = oidcConnection.ExternalUserId,
80 SchemeKey = oidcConnection.SchemeKey,
81 })
82 .ToList(),
83 },
84 false,
85 cancellationToken));
86 }
87
100 [Error(typeof(ErrorMessageException))]
101 public ValueTask<UpdatedUser> CreateUserByPasswordAndGroup(
102 string name,
103 string password,
104 bool? enabled,
105 IEnumerable<OAuthConnection>? oAuthConnections,
106 IEnumerable<OidcConnection>? oidcConnections,
107 [ID(nameof(UserGroup))] long groupId,
108 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
109 CancellationToken cancellationToken)
110 {
111 ArgumentNullException.ThrowIfNull(name);
112 ArgumentNullException.ThrowIfNull(password);
113 ArgumentNullException.ThrowIfNull(userAuthority);
114
115 return userAuthority.InvokeTransformable<Models.UpdatedUser, UpdatedUser, UpdatedUserGraphQLTransformer>(
116 authority => authority.Create(
118 {
119 Name = name,
120 Password = password,
121 Enabled = enabled,
123 {
124 Id = groupId,
125 },
126 OAuthConnections = oAuthConnections
127 ?.Select(oAuthConnection => new Api.Models.OAuthConnection
128 {
129 ExternalUserId = oAuthConnection.ExternalUserId,
130 Provider = oAuthConnection.Provider,
131 })
132 .ToList(),
133 OidcConnections = oidcConnections
134 ?.Select(oidcConnection => new Api.Models.OidcConnection
135 {
136 ExternalUserId = oidcConnection.ExternalUserId,
137 SchemeKey = oidcConnection.SchemeKey,
138 })
139 .ToList(),
140 },
141 false,
142 cancellationToken));
143 }
144
156 [Error(typeof(ErrorMessageException))]
158 string name,
159 IEnumerable<OAuthConnection>? oAuthConnections,
160 IEnumerable<OidcConnection>? oidcConnections,
161 bool? enabled,
162 PermissionSetInput? permissionSet,
163 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
164 CancellationToken cancellationToken)
165 {
166 ArgumentNullException.ThrowIfNull(name);
167 ArgumentNullException.ThrowIfNull(oAuthConnections);
168 ArgumentNullException.ThrowIfNull(userAuthority);
169
170 return userAuthority.InvokeTransformable<Models.UpdatedUser, UpdatedUser, UpdatedUserGraphQLTransformer>(
171 authority => authority.Create(
173 {
174 Name = name,
175 Password = String.Empty,
176 Enabled = enabled,
177 PermissionSet = permissionSet != null
179 {
180 AdministrationRights = permissionSet.AdministrationRights,
181 InstanceManagerRights = permissionSet.InstanceManagerRights,
182 }
183 : null,
184 OAuthConnections = oAuthConnections
185 .Select(oAuthConnection => new Api.Models.OAuthConnection
186 {
187 ExternalUserId = oAuthConnection.ExternalUserId,
188 Provider = oAuthConnection.Provider,
189 })
190 .ToList(),
191 OidcConnections = oidcConnections
192 ?.Select(oidcConnection => new Api.Models.OidcConnection
193 {
194 ExternalUserId = oidcConnection.ExternalUserId,
195 SchemeKey = oidcConnection.SchemeKey,
196 })
197 .ToList(),
198 },
199 true,
200 cancellationToken));
201 }
202
214 [Error(typeof(ErrorMessageException))]
215 public ValueTask<UpdatedUser> CreateUserByServiceConnectionAndGroup(
216 string name,
217 IEnumerable<OAuthConnection> oAuthConnections,
218 IEnumerable<OidcConnection> oidcConnections,
219 [ID(nameof(UserGroup))] long groupId,
220 bool? enabled,
221 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
222 CancellationToken cancellationToken)
223 {
224 ArgumentNullException.ThrowIfNull(name);
225 ArgumentNullException.ThrowIfNull(oAuthConnections);
226 ArgumentNullException.ThrowIfNull(userAuthority);
227
228 return userAuthority.InvokeTransformable<Models.UpdatedUser, UpdatedUser, UpdatedUserGraphQLTransformer>(
229 authority => authority.Create(
231 {
232 Name = name,
233 Password = String.Empty,
234 Enabled = enabled,
236 {
237 Id = groupId,
238 },
239 OAuthConnections = oAuthConnections
240 .Select(oAuthConnection => new Api.Models.OAuthConnection
241 {
242 ExternalUserId = oAuthConnection.ExternalUserId,
243 Provider = oAuthConnection.Provider,
244 })
245 .ToList(),
246 OidcConnections = oidcConnections
247 ?.Select(oidcConnection => new Api.Models.OidcConnection
248 {
249 ExternalUserId = oidcConnection.ExternalUserId,
250 SchemeKey = oidcConnection.SchemeKey,
251 })
252 .ToList(),
253 },
254 true,
255 cancellationToken));
256 }
257
269 [Error(typeof(ErrorMessageException))]
270 public ValueTask<UpdatedUser> CreateUserBySystemIDAndPermissionSet(
271 string systemIdentifier,
272 bool? enabled,
273 IEnumerable<OAuthConnection>? oAuthConnections,
274 IEnumerable<OidcConnection>? oidcConnections,
275 PermissionSetInput permissionSet,
276 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
277 CancellationToken cancellationToken)
278 {
279 ArgumentNullException.ThrowIfNull(systemIdentifier);
280 ArgumentNullException.ThrowIfNull(userAuthority);
281
282 return userAuthority.InvokeTransformable<Models.UpdatedUser, UpdatedUser, UpdatedUserGraphQLTransformer>(
283 authority => authority.Create(
285 {
286 SystemIdentifier = systemIdentifier,
287 Enabled = enabled,
288 PermissionSet = permissionSet != null
290 {
291 AdministrationRights = permissionSet.AdministrationRights,
292 InstanceManagerRights = permissionSet.InstanceManagerRights,
293 }
294 : null,
295 OAuthConnections = oAuthConnections
296 ?.Select(oAuthConnection => new Api.Models.OAuthConnection
297 {
298 ExternalUserId = oAuthConnection.ExternalUserId,
299 Provider = oAuthConnection.Provider,
300 })
301 .ToList(),
302 OidcConnections = oidcConnections
303 ?.Select(oidcConnection => new Api.Models.OidcConnection
304 {
305 ExternalUserId = oidcConnection.ExternalUserId,
306 SchemeKey = oidcConnection.SchemeKey,
307 })
308 .ToList(),
309 },
310 false,
311 cancellationToken));
312 }
313
325 [Error(typeof(ErrorMessageException))]
326 public ValueTask<UpdatedUser> CreateUserBySystemIDAndGroup(
327 string systemIdentifier,
328 bool? enabled,
329 [ID(nameof(UserGroup))] long groupId,
330 IEnumerable<OAuthConnection>? oAuthConnections,
331 IEnumerable<OidcConnection>? oidcConnections,
332 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
333 CancellationToken cancellationToken)
334 {
335 ArgumentNullException.ThrowIfNull(systemIdentifier);
336 ArgumentNullException.ThrowIfNull(userAuthority);
337
338 return userAuthority.InvokeTransformable<Models.UpdatedUser, UpdatedUser, UpdatedUserGraphQLTransformer>(
339 authority => authority.Create(
341 {
342 SystemIdentifier = systemIdentifier,
343 Enabled = enabled,
345 {
346 Id = groupId,
347 },
348 OAuthConnections = oAuthConnections
349 ?.Select(oAuthConnection => new Api.Models.OAuthConnection
350 {
351 ExternalUserId = oAuthConnection.ExternalUserId,
352 Provider = oAuthConnection.Provider,
353 })
354 .ToList(),
355 OidcConnections = oidcConnections
356 ?.Select(oidcConnection => new Api.Models.OidcConnection
357 {
358 ExternalUserId = oidcConnection.ExternalUserId,
359 SchemeKey = oidcConnection.SchemeKey,
360 })
361 .ToList(),
362 },
363 false,
364 cancellationToken));
365 }
366
375 [Error(typeof(ErrorMessageException))]
376 public ValueTask<UpdatedUser> SetCurrentUserPassword(
377 string newPassword,
378 [Service] IAuthenticationContext authenticationContext,
379 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
380 CancellationToken cancellationToken)
381 {
382 ArgumentNullException.ThrowIfNull(newPassword);
383 ArgumentNullException.ThrowIfNull(userAuthority);
384 return userAuthority.InvokeTransformable<Models.UpdatedUser, UpdatedUser, UpdatedUserGraphQLTransformer>(
385 authority => authority.Update(
387 {
388 Id = authenticationContext.User.Id,
389 Password = newPassword,
390 },
391 cancellationToken));
392 }
393
403 [Error(typeof(ErrorMessageException))]
404 public ValueTask<UpdatedUser> SetCurrentServiceConnections(
405 IEnumerable<OAuthConnection>? newOAuthConnections,
406 IEnumerable<OidcConnection>? newOidcConnections,
407 [Service] IAuthenticationContext authenticationContext,
408 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
409 CancellationToken cancellationToken)
410 {
411 ArgumentNullException.ThrowIfNull(newOAuthConnections);
412 ArgumentNullException.ThrowIfNull(userAuthority);
413 return userAuthority.InvokeTransformable<Models.UpdatedUser, UpdatedUser, UpdatedUserGraphQLTransformer>(
414 authority => authority.Update(
416 {
417 Id = authenticationContext.User.Id,
418 OAuthConnections = newOAuthConnections
419 .Select(oAuthConnection => new Api.Models.OAuthConnection
420 {
421 ExternalUserId = oAuthConnection.ExternalUserId,
422 Provider = oAuthConnection.Provider,
423 })
424 .ToList(),
425 OidcConnections = newOidcConnections
426 ?.Select(oidcConnection => new Api.Models.OidcConnection
427 {
428 ExternalUserId = oidcConnection.ExternalUserId,
429 SchemeKey = oidcConnection.SchemeKey,
430 })
431 .ToList(),
432 },
433 cancellationToken));
434 }
435
448 [Error(typeof(ErrorMessageException))]
449 public ValueTask<UpdatedUser> UpdateUser(
450 [ID(nameof(User))] long id,
451 string? casingOnlyNameChange,
452 string? newPassword,
453 bool? enabled,
454 IEnumerable<OAuthConnection>? newOAuthConnections,
455 IEnumerable<OidcConnection>? newOidcConnections,
456 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
457 CancellationToken cancellationToken)
458 {
459 ArgumentNullException.ThrowIfNull(userAuthority);
460 return UpdateUserCore(
461 id,
462 casingOnlyNameChange,
463 newPassword,
464 enabled,
465 null,
466 null,
467 newOAuthConnections,
468 newOidcConnections,
469 userAuthority,
470 cancellationToken);
471 }
472
486 [Error(typeof(ErrorMessageException))]
487 public ValueTask<UpdatedUser> UpdateUserSetOwnedPermissionSet(
488 [ID(nameof(User))] long id,
489 string? casingOnlyNameChange,
490 string? newPassword,
491 bool? enabled,
492 PermissionSetInput newPermissionSet,
493 IEnumerable<OAuthConnection>? newOAuthConnections,
494 IEnumerable<OidcConnection>? newOidcConnections,
495 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
496 CancellationToken cancellationToken)
497 {
498 ArgumentNullException.ThrowIfNull(userAuthority);
499 return UpdateUserCore(
500 id,
501 casingOnlyNameChange,
502 newPassword,
503 enabled,
504 newPermissionSet,
505 null,
506 newOAuthConnections,
507 newOidcConnections,
508 userAuthority,
509 cancellationToken);
510 }
511
525 [Error(typeof(ErrorMessageException))]
526 public ValueTask<UpdatedUser> UpdateUserSetGroup(
527 [ID(nameof(User))] long id,
528 string? casingOnlyNameChange,
529 string? newPassword,
530 bool? enabled,
531 [ID(nameof(UserGroup))] long newGroupId,
532 IEnumerable<OAuthConnection>? newOAuthConnections,
533 IEnumerable<OidcConnection>? newOidcConnections,
534 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
535 CancellationToken cancellationToken)
536 {
537 ArgumentNullException.ThrowIfNull(userAuthority);
538 return UpdateUserCore(
539 id,
540 casingOnlyNameChange,
541 newPassword,
542 enabled,
543 null,
544 newGroupId,
545 newOAuthConnections,
546 newOidcConnections,
547 userAuthority,
548 cancellationToken);
549 }
550
565 ValueTask<UpdatedUser> UpdateUserCore(
566 [ID(nameof(User))] long id,
567 string? casingOnlyNameChange,
568 string? newPassword,
569 bool? enabled,
570 PermissionSetInput? newPermissionSet,
571 long? newGroupId,
572 IEnumerable<OAuthConnection>? newOAuthConnections,
573 IEnumerable<OidcConnection>? newOidcConnections,
575 CancellationToken cancellationToken)
576 => userAuthority.InvokeTransformable<Models.UpdatedUser, UpdatedUser, UpdatedUserGraphQLTransformer>(
577 authority => authority.Update(
579 {
580 Id = id,
581 Name = casingOnlyNameChange,
582 Password = newPassword,
583 Enabled = enabled,
584 PermissionSet = newPermissionSet != null
586 {
587 InstanceManagerRights = newPermissionSet.InstanceManagerRights,
588 AdministrationRights = newPermissionSet.AdministrationRights,
589 }
590 : null,
591 Group = newGroupId.HasValue
593 {
594 Id = newGroupId.Value,
595 }
596 : null,
597 OAuthConnections = newOAuthConnections
598 ?.Select(oAuthConnection => new Api.Models.OAuthConnection
599 {
600 ExternalUserId = oAuthConnection.ExternalUserId,
601 Provider = oAuthConnection.Provider,
602 })
603 .ToList(),
604 OidcConnections = newOidcConnections
605 ?.Select(oidcConnection => new Api.Models.OidcConnection
606 {
607 ExternalUserId = oidcConnection.ExternalUserId,
608 SchemeKey = oidcConnection.SchemeKey,
609 })
610 .ToList(),
611 },
612 cancellationToken));
613 }
614}
virtual ? long Id
The ID of the entity.
Definition EntityId.cs:14
Represents a set of server permissions.
Exception representing ErrorMessageResponses.
Root type for GraphQL mutations.
Definition Mutation.cs:21
const string GraphQLDescription
Description to show on the Mutation type.
Definition Mutation.cs:25
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< UpdatedUser > CreateUserBySystemIDAndGroup(string systemIdentifier, bool? enabled, [ID(nameof(UserGroup))] long groupId, IEnumerable< OAuthConnection >? oAuthConnections, IEnumerable< OidcConnection >? oidcConnections, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Creates a system user specifying the UserGroup they will belong to.
ValueTask< UpdatedUser > UpdateUser([ID(nameof(User))] long id, string? casingOnlyNameChange, string? newPassword, bool? enabled, IEnumerable< OAuthConnection >? newOAuthConnections, IEnumerable< OidcConnection >? newOidcConnections, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Updates a Users properties.
ValueTask< UpdatedUser > CreateUserByServiceConnectionAndGroup(string name, IEnumerable< OAuthConnection > oAuthConnections, IEnumerable< OidcConnection > oidcConnections, [ID(nameof(UserGroup))] long groupId, bool? enabled, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Creates a TGS user using OAuthConnections and/or OidcConnections specifying the UserGroup they will b...
ValueTask< UpdatedUser > CreateUserByServiceConnectionAndPermissionSet(string name, IEnumerable< OAuthConnection >? oAuthConnections, IEnumerable< OidcConnection >? oidcConnections, bool? enabled, PermissionSetInput? permissionSet, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Creates a TGS user authenticated with one or more OAuthConnections or OidcConnections specifying a pe...
ValueTask< UpdatedUser > UpdateUserSetGroup([ID(nameof(User))] long id, string? casingOnlyNameChange, string? newPassword, bool? enabled, [ID(nameof(UserGroup))] long newGroupId, IEnumerable< OAuthConnection >? newOAuthConnections, IEnumerable< OidcConnection >? newOidcConnections, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Updates a User, setting new values for its owned PermissionSet.
ValueTask< UpdatedUser > CreateUserBySystemIDAndPermissionSet(string systemIdentifier, bool? enabled, IEnumerable< OAuthConnection >? oAuthConnections, IEnumerable< OidcConnection >? oidcConnections, PermissionSetInput permissionSet, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Creates a system user specifying a personal PermissionSet.
ValueTask< UpdatedUser > UpdateUserSetOwnedPermissionSet([ID(nameof(User))] long id, string? casingOnlyNameChange, string? newPassword, bool? enabled, PermissionSetInput newPermissionSet, IEnumerable< OAuthConnection >? newOAuthConnections, IEnumerable< OidcConnection >? newOidcConnections, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Updates a User, setting new values for its owned PermissionSet.
ValueTask< UpdatedUser > CreateUserByPasswordAndGroup(string name, string password, bool? enabled, IEnumerable< OAuthConnection >? oAuthConnections, IEnumerable< OidcConnection >? oidcConnections, [ID(nameof(UserGroup))] long groupId, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Creates a TGS user specifying the UserGroup they will belong to.
ValueTask< UpdatedUser > SetCurrentUserPassword(string newPassword, [Service] IAuthenticationContext authenticationContext, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Sets the current user's password.
ValueTask< UpdatedUser > UpdateUserCore([ID(nameof(User))] long id, string? casingOnlyNameChange, string? newPassword, bool? enabled, PermissionSetInput? newPermissionSet, long? newGroupId, IEnumerable< OAuthConnection >? newOAuthConnections, IEnumerable< OidcConnection >? newOidcConnections, IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Updates a user.
ValueTask< UpdatedUser > SetCurrentServiceConnections(IEnumerable< OAuthConnection >? newOAuthConnections, IEnumerable< OidcConnection >? newOidcConnections, [Service] IAuthenticationContext authenticationContext, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Sets the current user's OAuthConnections and OidcConnections.
ValueTask< UpdatedUser > CreateUserByPasswordAndPermissionSet(string name, string password, bool? enabled, IEnumerable< OAuthConnection >? oAuthConnections, IEnumerable< OidcConnection >? oidcConnections, PermissionSetInput? permissionSet, [Service] IGraphQLAuthorityInvoker< IUserAuthority > userAuthority, CancellationToken cancellationToken)
Creates a TGS user specifying a personal PermissionSet.
Represents a set of permissions for the server.
A user registered in the server.
Definition User.cs:22
For creating and accessing authentication contexts.
@ Id
Lookup the Api.Models.EntityId.Id of the Models.PermissionSet.
@ Enabled
The OAuth Gateway is enabled.