tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
UserGroupController.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
5
8
20
22{
28 {
33
43 IDatabaseContext databaseContext,
44 IAuthenticationContext authenticationContext,
45 IApiHeadersProvider apiHeaders,
48 : base(
49 databaseContext,
50 authenticationContext,
51 apiHeaders,
52 logger,
53 true)
54 {
56 }
57
63 static Models.PermissionSet? TransformApiPermissionSet(Api.Models.PermissionSet? permissionSet)
64 => permissionSet != null
66 {
68 AdministrationRights = permissionSet?.AdministrationRights,
69 }
70 : null;
71
79 [HttpPut]
83 {
84 ArgumentNullException.ThrowIfNull(model);
85
86 if (model.Name == null)
87 return BadRequest(new ErrorMessageResponse(ErrorCode.ModelValidationFailure));
88
89 return await userGroupAuthority.InvokeTransformable<UserGroup, UserGroupResponse>(
90 this,
91 authority => authority.Create(
92 model.Name,
93 TransformApiPermissionSet(model.PermissionSet),
95 }
96
105 [HttpPost]
109 {
110 ArgumentNullException.ThrowIfNull(model);
111
112 return userGroupAuthority.InvokeTransformable<UserGroup, UserGroupResponse>(
113 this,
114 authority => authority.Update(
115 model.Require(x => x.Id),
116 model.Name,
117 TransformApiPermissionSet(model.PermissionSet),
119 }
120
129 [HttpGet("{id}")]
133 public ValueTask<IActionResult> GetId(long id, CancellationToken cancellationToken)
134 => userGroupAuthority.InvokeTransformable<UserGroup, UserGroupResponse>(this, authority => authority.GetId(id, true, cancellationToken));
135
149 () => ValueTask.FromResult(
152 .InvokeQueryable(authority => authority.Queryable(true))
153 .OrderBy(x => x.Id))),
154 null,
155 page,
156 pageSize,
158
168 [HttpDelete("{id}")]
173 public ValueTask<IActionResult> Delete(long id, CancellationToken cancellationToken)
174#pragma warning disable API1001 // The response type is RIGHT THERE ^^^
175 => userGroupAuthority.Invoke(this, authority => authority.DeleteEmpty(id, cancellationToken));
176#pragma warning restore API1001
177 }
178}
InstanceManagerRights? InstanceManagerRights
The Rights.InstanceManagerRights for the user.
Represents an error message returned by the server.
Routes to a server actions.
Definition Routes.cs:9
const string UserGroup
The user group controller.
Definition Routes.cs:43
const string List
The postfix for list operations.
Definition Routes.cs:113
Base Controller for API functions.
ApiController for managing UserGroupResponses.
static Models.? PermissionSet TransformApiPermissionSet(Api.Models.PermissionSet? permissionSet)
Transform a Api.Models.PermissionSet into a PermissionSet.
ValueTask< IActionResult > Delete(long id, CancellationToken cancellationToken)
Delete a UserGroup.
async ValueTask< IActionResult > Create([FromBody] UserGroupCreateRequest model, CancellationToken cancellationToken)
Create a new UserGroup.
ValueTask< IActionResult > GetId(long id, CancellationToken cancellationToken)
Gets a specific UserGroup.
readonly IRestAuthorityInvoker< IUserGroupAuthority > userGroupAuthority
The IUserGroupAuthority for the UserGroupController.
ValueTask< IActionResult > Update([FromBody] UserGroupUpdateRequest model, CancellationToken cancellationToken)
Update a UserGroup.
ValueTask< IActionResult > List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken)
Lists all UserGroups.
UserGroupController(IDatabaseContext databaseContext, IAuthenticationContext authenticationContext, IApiHeadersProvider apiHeaders, ILogger< UserGroupController > logger, IRestAuthorityInvoker< IUserGroupAuthority > userGroupAuthority)
Initializes a new instance of the UserGroupController class.
Represents a group of Users.
Definition UserGroup.cs:16
Invokes TAuthority methods and generates IActionResult responses.
ValueTask< IActionResult > Invoke(ApiController controller, Func< TAuthority, ValueTask< AuthorityResponse > > authorityInvoker)
Invoke a TAuthority method with no success result.
ValueTask< AuthorityResponse< UserGroup > > GetId(long id, bool includeJoins, CancellationToken cancellationToken)
Gets the UserGroup with a given id .
IQueryable< UserGroup > Queryable(bool includeJoins)
Gets all registered UserGroups.
For creating and accessing authentication contexts.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
Definition ErrorCode.cs:12
@ List
User may list files if the Models.Instance allows it.
InstanceManagerRights
Rights for managing Models.Instances.
AdministrationRights
Administration rights for the server.
@ Api
The ApiHeaders.ApiVersionHeader header is missing or invalid.