Project effective permission set

This commit is contained in:
Jordan Dominion
2025-08-16 13:08:26 -04:00
parent a3c5022d52
commit f0fbcbae36
2 changed files with 12 additions and 38 deletions
@@ -60,17 +60,16 @@ namespace Tgstation.Server.Host.GraphQL.Types
/// </summary>
public required UserGroup? Group { get; set; }
/// <summary>
/// The <see cref="PermissionSet"/> associated with the <see cref="User"/>.
/// </summary>
public required PermissionSet EffectivePermissionSet { get; set; }
/// <summary>
/// The <see cref="PermissionSet"/> for the user if the user does not belong to a <see cref="Group"/>.
/// </summary>
public required PermissionSet? OwnedPermissionSet { get; set; }
/// <summary>
/// The <see cref="Entity.Id"/> of the <see cref="CreatedBy"/> <see cref="User"/>.
/// </summary>
[IsProjected(true)]
public required long? GroupId { get; init; }
/// <summary>
/// The <see cref="Entity.Id"/> of the <see cref="CreatedBy"/> <see cref="User"/>.
/// </summary>
@@ -169,34 +168,5 @@ namespace Tgstation.Server.Host.GraphQL.Types
return userAuthority.Invoke<OidcConnection[], OidcConnection[]>(
authority => authority.OidcConnections(Id, cancellationToken));
}
/// <summary>
/// The <see cref="PermissionSet"/> associated with the <see cref="User"/>.
/// </summary>
/// <param name="permissionSetAuthority">The <see cref="IGraphQLAuthorityInvoker{TAuthority}"/> for the <see cref="IPermissionSetAuthority"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="PermissionSet"/> associated with the <see cref="User"/>.</returns>
public ValueTask<PermissionSet> EffectivePermissionSet(
[Service] IGraphQLAuthorityInvoker<IPermissionSetAuthority> permissionSetAuthority,
CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(permissionSetAuthority);
long lookupId;
PermissionSetLookupType lookupType;
if (GroupId.HasValue)
{
lookupId = GroupId.Value;
lookupType = PermissionSetLookupType.GroupId;
}
else
{
lookupId = Id;
lookupType = PermissionSetLookupType.UserId;
}
return permissionSetAuthority.InvokeTransformable<Models.PermissionSet, PermissionSet, PermissionSetGraphQLTransformer>(
authority => authority.GetId(lookupId, lookupType, cancellationToken));
}
}
}
@@ -19,17 +19,21 @@ namespace Tgstation.Server.Host.Models.Transformers
GraphQL.Types.PermissionSet,
UserGroupGraphQLTransformer,
PermissionSetGraphQLTransformer>(
(model, group, permissionSet) => new GraphQL.Types.User
(model, group, ownedPermissionSet) => new GraphQL.Types.User
{
CreatedAt = model.CreatedAt ?? NotNullFallback<DateTimeOffset>(),
CanonicalName = model.CanonicalName ?? NotNullFallback<string>(),
CreatedById = model.CreatedById,
Enabled = model.Enabled ?? NotNullFallback<bool>(),
GroupId = model.GroupId,
Id = model.Id!.Value,
Name = model.Name ?? NotNullFallback<string>(),
SystemIdentifier = model.SystemIdentifier,
OwnedPermissionSet = permissionSet,
OwnedPermissionSet = ownedPermissionSet,
EffectivePermissionSet = ownedPermissionSet != null
? ownedPermissionSet
: group != null
? group.PermissionSet
: NotNullFallback<GraphQL.Types.PermissionSet>(),
Group = group,
},
model => model.Group,