tgstation-server 6.12.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
8
20
22{
27 public sealed class UserController : ApiController
28 {
33
43 IDatabaseContext databaseContext,
44 IAuthenticationContext authenticationContext,
47 IApiHeadersProvider apiHeaders)
48 : base(
49 databaseContext,
50 authenticationContext,
51 apiHeaders,
52 logger,
53 true)
54 {
56 }
57
66 [HttpPut]
70 => userAuthority.InvokeTransformable<User, UserResponse>(this, authority => authority.Create(model, null, cancellationToken));
71
82 [HttpPost]
89 => userAuthority.InvokeTransformable<User, UserResponse>(this, authority => authority.Update(model, cancellationToken));
90
97 [HttpGet]
101 => userAuthority.InvokeTransformable<User, UserResponse>(this, authority => authority.Read(cancellationToken));
102
116 () => ValueTask.FromResult(
118 userAuthority.InvokeQueryable(
119 authority => authority.Queryable(true))
120 .OrderBy(x => x.Id))),
121 null,
122 page,
123 pageSize,
125
134 [HttpGet("{id}")]
138 public async ValueTask<IActionResult> GetId(long id, CancellationToken cancellationToken)
139 {
140 if (id == AuthenticationContext.User.Id)
142
143 if (!((AdministrationRights)AuthenticationContext.GetRight(RightsType.Administration)).HasFlag(AdministrationRights.ReadUsers))
144 return Forbid();
145
146 return await userAuthority.InvokeTransformable<User, UserResponse>(
147 this,
148 authority => authority.GetId(id, true, false, cancellationToken));
149 }
150 }
151}
virtual ? long Id
The ID of the entity.
Definition EntityId.cs:13
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.
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.
IQueryable< User > Queryable(bool includeJoins)
Gets all registered Users.
ValueTask< AuthorityResponse< User > > Update(UserUpdateRequest updateRequest, CancellationToken cancellationToken)
Updates a User.
ValueTask< AuthorityResponse< User > > Read(CancellationToken cancellationToken)
Gets the currently authenticated user.
ValueTask< AuthorityResponse< User > > Create(UserCreateRequest createRequest, bool? needZeroLengthPasswordWithOAuthConnections, CancellationToken cancellationToken)
Creates a User.
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.