tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
PermissionSetAuthority.cs
Go to the documentation of this file.
1using System;
3using System.Linq;
6
7using GreenDonut;
8
11
17
19{
22 {
27
38 IDatabaseContext databaseContext,
39 CancellationToken cancellationToken)
40 {
41 ArgumentNullException.ThrowIfNull(ids);
42 ArgumentNullException.ThrowIfNull(databaseContext);
43
44 var idLookups = new List<long>(ids.Count);
45 var userIdLookups = new List<long>(ids.Count);
46 var groupIdLookups = new List<long>(ids.Count);
47
48 foreach (var (id, lookupType) in ids)
49 switch (lookupType)
50 {
52 idLookups.Add(id);
53 break;
54 case PermissionSetLookupType.UserId:
55 userIdLookups.Add(id);
56 break;
57 case PermissionSetLookupType.GroupId:
58 groupIdLookups.Add(id);
59 break;
60 default:
61 throw new InvalidOperationException($"Invalid {nameof(PermissionSetLookupType)}: {lookupType}");
62 }
63
64 var selectedPermissionSets = await databaseContext
65 .PermissionSets
66 .Where(dbModel => idLookups.Contains(dbModel.Id!.Value)
67 || (dbModel.UserId.HasValue && userIdLookups.Contains(dbModel.UserId.Value))
68 || (dbModel.GroupId.HasValue && groupIdLookups.Contains(dbModel.GroupId.Value)))
69 .ToListAsync(cancellationToken);
70
72 foreach (var permissionSet in selectedPermissionSets)
73 {
74 results.Add((permissionSet.Id!.Value, PermissionSetLookupType.Id), permissionSet);
75 if (permissionSet.GroupId.HasValue)
76 results.Add((permissionSet.GroupId.Value, PermissionSetLookupType.GroupId), permissionSet);
77 if (permissionSet.UserId.HasValue)
78 results.Add((permissionSet.UserId.Value, PermissionSetLookupType.UserId), permissionSet);
79 }
80
81 return results;
82 }
83
92 IAuthenticationContext authenticationContext,
93 IDatabaseContext databaseContext,
96 : base(
97 authenticationContext,
98 databaseContext,
99 logger)
100 {
102 }
103
106 {
108 return Forbid<PermissionSet>();
109
111 if (permissionSet == null)
113
114 return new AuthorityResponse<PermissionSet>(permissionSet);
115 }
116 }
117}
PermissionSetAuthority(IAuthenticationContext authenticationContext, IDatabaseContext databaseContext, ILogger< AuthorityBase > logger, IPermissionSetsDataLoader permissionSetsDataLoader)
Initializes a new instance of the PermissionSetAuthority class.
static async ValueTask< Dictionary<(long Id, PermissionSetLookupType LookupType), PermissionSet > > GetPermissionSets(IReadOnlyList<(long Id, PermissionSetLookupType LookupType)> ids, IDatabaseContext databaseContext, CancellationToken cancellationToken)
Implements permissionSetsDataLoader.
async ValueTask< AuthorityResponse< PermissionSet > > GetId(long id, PermissionSetLookupType lookupType, CancellationToken cancellationToken)
Gets the User with a given id .A ValueTask<TResult> resulting in a PermissionSet AuthorityResponse<TR...
readonly IPermissionSetsDataLoader permissionSetsDataLoader
The IPermissionSetsDataLoader for the PermissionSetAuthority.
PermissionSet PermissionSet
The User's effective PermissionSet.
ulong GetRight(RightsType rightsType)
Get the value of a given rightsType .The value of rightsType . Note that if InstancePermissionSet is ...
For creating and accessing authentication contexts.
@ 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.
PermissionSetLookupType
Indicates the type of Api.Models.EntityId.Id to lookup on a Models.PermissionSet.
@ Id
Lookup the Api.Models.EntityId.Id of the Models.PermissionSet.