tgstation-server 6.19.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
UserController.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
5
9
21
23{
28 [Authorize]
29 public sealed class UserController : ApiController
30 {
35
45 IDatabaseContext databaseContext,
46 IAuthenticationContext authenticationContext,
49 IApiHeadersProvider apiHeaders)
50 : base(
51 databaseContext,
52 authenticationContext,
53 apiHeaders,
54 logger,
55 true)
56 {
58 }
59
68 [HttpPut]
71 => userAuthority.InvokeTransformable<UpdatedUser, UserResponse>(this, authority => authority.Create(model, null, cancellationToken));
72
83 [HttpPost]
90
97 [HttpGet]
98 [Authorize]
101 => userAuthority.InvokeTransformable<User, UserResponse>(this, authority => authority.Read(cancellationToken));
102
115 async () =>
116 {
117 var queryable = await userAuthority.InvokeQueryable(
118 authority => authority.Queryable(true));
119 if (queryable == null)
120 return null;
121
122 return new PaginatableResult<User>(queryable.OrderBy(x => x.Id));
123 },
124 null,
125 page,
126 pageSize,
128
137 [HttpGet("{id}")]
140 public async ValueTask<IActionResult> GetId(long id, CancellationToken cancellationToken)
141 {
142 if (id == AuthenticationContext.User.Id)
144
145 if (!((AdministrationRights)AuthenticationContext.GetRight(RightsType.Administration)).HasFlag(AdministrationRights.ReadUsers))
146 return Forbid();
147
148 return await userAuthority.InvokeTransformable<User, UserResponse>(
149 this,
150 authority => authority.GetId(id, true, false, cancellationToken));
151 }
152 }
153}
virtual ? long Id
The ID of the entity.
Definition EntityId.cs:14
Represents an error message returned by the server.
Routes to a server actions.
Definition Routes.cs:9
const string User
The user controller.
Definition Routes.cs:38
const string List
The postfix for list operations.
Definition Routes.cs:113
Base Controller for API functions.
async ValueTask< IActionResult > GetId(long id, CancellationToken cancellationToken)
Get a specific User.
ValueTask< IActionResult > Update([FromBody] UserUpdateRequest model, CancellationToken cancellationToken)
Update a User.
ValueTask< IActionResult > List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken)
List all Users in the server.
UserController(IDatabaseContext databaseContext, IAuthenticationContext authenticationContext, IRestAuthorityInvoker< IUserAuthority > userAuthority, ILogger< UserController > logger, IApiHeadersProvider apiHeaders)
Initializes a new instance of the UserController class.
readonly IRestAuthorityInvoker< IUserAuthority > userAuthority
The IRestAuthorityInvoker<TAuthority> for the IUserAuthority.
ValueTask< IActionResult > Read(CancellationToken cancellationToken)
Get information about the current User.
ValueTask< IActionResult > Create([FromBody] UserCreateRequest model, CancellationToken cancellationToken)
Create a new User.
Represents a User that has been updated.
ulong GetRight(RightsType rightsType)
Get the value of a given rightsType .The value of rightsType . Note that if InstancePermissionSet is ...
Invokes TAuthority methods and generates IActionResult responses.
For creating and accessing authentication contexts.
@ Read
User can read all chat bot properties except Models.Internal.ChatBotSettings.ConnectionString.
@ List
User may list files if the Models.Instance allows it.
RightsType
The type of rights a model uses.
Definition RightsType.cs:7
AdministrationRights
Administration rights for the server.