tgstation-server 6.16.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 {
44 string name,
45 string password,
46 bool? enabled,
47 IEnumerable<OAuthConnection>? oAuthConnections,
48 IEnumerable<OidcConnection>? oidcConnections,
49 PermissionSetInput? permissionSet,
50 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
51 CancellationToken cancellationToken)
52 {
53 ArgumentNullException.ThrowIfNull(name);
54 ArgumentNullException.ThrowIfNull(password);
55 ArgumentNullException.ThrowIfNull(userAuthority);
56
57 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
58 authority => authority.Create(
60 {
61 Name = name,
62 Password = password,
64 PermissionSet = permissionSet != null
66 {
69 }
70 : null,
71 OAuthConnections = oAuthConnections
72 ?.Select(oAuthConnection => new Api.Models.OAuthConnection
73 {
74 ExternalUserId = oAuthConnection.ExternalUserId,
75 Provider = oAuthConnection.Provider,
76 })
77 .ToList(),
78 OidcConnections = oidcConnections
79 ?.Select(oidcConnection => new Api.Models.OidcConnection
80 {
81 ExternalUserId = oidcConnection.ExternalUserId,
82 SchemeKey = oidcConnection.SchemeKey,
83 })
84 .ToList(),
85 },
86 false,
88 }
89
104 public ValueTask<User> CreateUserByPasswordAndGroup(
105 string name,
106 string password,
107 bool? enabled,
108 IEnumerable<OAuthConnection>? oAuthConnections,
109 IEnumerable<OidcConnection>? oidcConnections,
110 [ID(nameof(UserGroup))] long groupId,
111 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
112 CancellationToken cancellationToken)
113 {
114 ArgumentNullException.ThrowIfNull(name);
115 ArgumentNullException.ThrowIfNull(password);
116 ArgumentNullException.ThrowIfNull(userAuthority);
117
118 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
119 authority => authority.Create(
121 {
122 Name = name,
123 Password = password,
126 {
127 Id = groupId,
128 },
129 OAuthConnections = oAuthConnections
130 ?.Select(oAuthConnection => new Api.Models.OAuthConnection
131 {
132 ExternalUserId = oAuthConnection.ExternalUserId,
133 Provider = oAuthConnection.Provider,
134 })
135 .ToList(),
136 OidcConnections = oidcConnections
137 ?.Select(oidcConnection => new Api.Models.OidcConnection
138 {
139 ExternalUserId = oidcConnection.ExternalUserId,
140 SchemeKey = oidcConnection.SchemeKey,
141 })
142 .ToList(),
143 },
144 false,
146 }
147
162 string name,
163 IEnumerable<OAuthConnection>? oAuthConnections,
164 IEnumerable<OidcConnection>? oidcConnections,
165 bool? enabled,
166 PermissionSetInput? permissionSet,
167 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
168 CancellationToken cancellationToken)
169 {
170 ArgumentNullException.ThrowIfNull(name);
171 ArgumentNullException.ThrowIfNull(oAuthConnections);
172 ArgumentNullException.ThrowIfNull(userAuthority);
173
174 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
175 authority => authority.Create(
177 {
178 Name = name,
179 Password = String.Empty,
181 PermissionSet = permissionSet != null
183 {
186 }
187 : null,
188 OAuthConnections = oAuthConnections
189 .Select(oAuthConnection => new Api.Models.OAuthConnection
190 {
191 ExternalUserId = oAuthConnection.ExternalUserId,
192 Provider = oAuthConnection.Provider,
193 })
194 .ToList(),
195 OidcConnections = oidcConnections
196 ?.Select(oidcConnection => new Api.Models.OidcConnection
197 {
198 ExternalUserId = oidcConnection.ExternalUserId,
199 SchemeKey = oidcConnection.SchemeKey,
200 })
201 .ToList(),
202 },
203 true,
205 }
206
221 string name,
222 IEnumerable<OAuthConnection> oAuthConnections,
223 IEnumerable<OidcConnection> oidcConnections,
224 [ID(nameof(UserGroup))] long groupId,
225 bool? enabled,
226 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
227 CancellationToken cancellationToken)
228 {
229 ArgumentNullException.ThrowIfNull(name);
230 ArgumentNullException.ThrowIfNull(oAuthConnections);
231 ArgumentNullException.ThrowIfNull(userAuthority);
232
233 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
234 authority => authority.Create(
236 {
237 Name = name,
238 Password = String.Empty,
241 {
242 Id = groupId,
243 },
244 OAuthConnections = oAuthConnections
245 .Select(oAuthConnection => new Api.Models.OAuthConnection
246 {
247 ExternalUserId = oAuthConnection.ExternalUserId,
248 Provider = oAuthConnection.Provider,
249 })
250 .ToList(),
251 OidcConnections = oidcConnections
252 ?.Select(oidcConnection => new Api.Models.OidcConnection
253 {
254 ExternalUserId = oidcConnection.ExternalUserId,
255 SchemeKey = oidcConnection.SchemeKey,
256 })
257 .ToList(),
258 },
259 true,
261 }
262
277 string systemIdentifier,
278 bool? enabled,
279 IEnumerable<OAuthConnection>? oAuthConnections,
280 IEnumerable<OidcConnection>? oidcConnections,
281 PermissionSetInput permissionSet,
282 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
283 CancellationToken cancellationToken)
284 {
286 ArgumentNullException.ThrowIfNull(userAuthority);
287
288 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
289 authority => authority.Create(
291 {
292 SystemIdentifier = systemIdentifier,
294 PermissionSet = permissionSet != null
296 {
299 }
300 : null,
301 OAuthConnections = oAuthConnections
302 ?.Select(oAuthConnection => new Api.Models.OAuthConnection
303 {
304 ExternalUserId = oAuthConnection.ExternalUserId,
305 Provider = oAuthConnection.Provider,
306 })
307 .ToList(),
308 OidcConnections = oidcConnections
309 ?.Select(oidcConnection => new Api.Models.OidcConnection
310 {
311 ExternalUserId = oidcConnection.ExternalUserId,
312 SchemeKey = oidcConnection.SchemeKey,
313 })
314 .ToList(),
315 },
316 false,
318 }
319
333 public ValueTask<User> CreateUserBySystemIDAndGroup(
334 string systemIdentifier,
335 bool? enabled,
336 [ID(nameof(UserGroup))] long groupId,
337 IEnumerable<OAuthConnection>? oAuthConnections,
338 IEnumerable<OidcConnection>? oidcConnections,
339 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
340 CancellationToken cancellationToken)
341 {
343 ArgumentNullException.ThrowIfNull(userAuthority);
344
345 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
346 authority => authority.Create(
348 {
349 SystemIdentifier = systemIdentifier,
352 {
353 Id = groupId,
354 },
355 OAuthConnections = oAuthConnections
356 ?.Select(oAuthConnection => new Api.Models.OAuthConnection
357 {
358 ExternalUserId = oAuthConnection.ExternalUserId,
359 Provider = oAuthConnection.Provider,
360 })
361 .ToList(),
362 OidcConnections = oidcConnections
363 ?.Select(oidcConnection => new Api.Models.OidcConnection
364 {
365 ExternalUserId = oidcConnection.ExternalUserId,
366 SchemeKey = oidcConnection.SchemeKey,
367 })
368 .ToList(),
369 },
370 false,
372 }
373
384 public ValueTask<User> SetCurrentUserPassword(
385 string newPassword,
386 [Service] IAuthenticationContext authenticationContext,
387 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
388 CancellationToken cancellationToken)
389 {
391 ArgumentNullException.ThrowIfNull(userAuthority);
392 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
393 async authority => await authority.Update(
395 {
396 Id = authenticationContext.User.Id,
397 Password = newPassword,
398 },
400 }
401
411 [TgsGraphQLAuthorize(AdministrationRights.WriteUsers | AdministrationRights.EditOwnServiceConnections)]
413 public ValueTask<User> SetCurrentServiceConnections(
416 [Service] IAuthenticationContext authenticationContext,
417 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
418 CancellationToken cancellationToken)
419 {
421 ArgumentNullException.ThrowIfNull(userAuthority);
422 return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
423 async authority => await authority.Update(
425 {
426 Id = authenticationContext.User.Id,
427 OAuthConnections = newOAuthConnections
428 .Select(oAuthConnection => new Api.Models.OAuthConnection
429 {
430 ExternalUserId = oAuthConnection.ExternalUserId,
431 Provider = oAuthConnection.Provider,
432 })
433 .ToList(),
434 OidcConnections = newOidcConnections
435 ?.Select(oidcConnection => new Api.Models.OidcConnection
436 {
437 ExternalUserId = oidcConnection.ExternalUserId,
438 SchemeKey = oidcConnection.SchemeKey,
439 })
440 .ToList(),
441 },
443 }
444
459 public ValueTask<User> UpdateUser(
460 [ID(nameof(User))] long id,
461 string? casingOnlyNameChange,
462 string? newPassword,
463 bool? enabled,
466 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
467 CancellationToken cancellationToken)
468 {
469 ArgumentNullException.ThrowIfNull(userAuthority);
470 return UpdateUserCore(
471 id,
474 enabled,
475 null,
476 null,
479 userAuthority,
481 }
482
498 public ValueTask<User> UpdateUserSetOwnedPermissionSet(
499 [ID(nameof(User))] long id,
500 string? casingOnlyNameChange,
501 string? newPassword,
502 bool? enabled,
506 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
507 CancellationToken cancellationToken)
508 {
509 ArgumentNullException.ThrowIfNull(userAuthority);
510 return UpdateUserCore(
511 id,
514 enabled,
516 null,
519 userAuthority,
521 }
522
538 public ValueTask<User> UpdateUserSetGroup(
539 [ID(nameof(User))] long id,
540 string? casingOnlyNameChange,
541 string? newPassword,
542 bool? enabled,
543 [ID(nameof(UserGroup))] long newGroupId,
546 [Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
547 CancellationToken cancellationToken)
548 {
549 ArgumentNullException.ThrowIfNull(userAuthority);
550 return UpdateUserCore(
551 id,
554 enabled,
555 null,
559 userAuthority,
561 }
562
577 ValueTask<User> UpdateUserCore(
578 [ID(nameof(User))] long id,
579 string? casingOnlyNameChange,
580 string? newPassword,
581 bool? enabled,
583 long? newGroupId,
587 CancellationToken cancellationToken)
588 => userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
589 async authority => await authority.Update(
591 {
592 Id = id,
594 Password = newPassword,
598 {
600 AdministrationRights = newPermissionSet.AdministrationRights,
601 }
602 : null,
603 Group = newGroupId.HasValue
605 {
606 Id = newGroupId.Value,
607 }
608 : null,
609 OAuthConnections = newOAuthConnections
610 ?.Select(oAuthConnection => new Api.Models.OAuthConnection
611 {
612 ExternalUserId = oAuthConnection.ExternalUserId,
613 Provider = oAuthConnection.Provider,
614 })
615 .ToList(),
616 OidcConnections = newOidcConnections
617 ?.Select(oidcConnection => new Api.Models.OidcConnection
618 {
619 ExternalUserId = oidcConnection.ExternalUserId,
620 SchemeKey = oidcConnection.SchemeKey,
621 })
622 .ToList(),
623 },
625 }
626}
virtual ? long Id
The ID of the entity.
Definition EntityId.cs:14
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 > 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< User > 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< User > 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< User > 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< User > 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< User > 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< User > 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.
ValueTask< User > 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< User > 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< User > 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< User > 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< 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.