diff --git a/src/Tgstation.Server.Host/Authority/IUserGroupAuthority.cs b/src/Tgstation.Server.Host/Authority/IUserGroupAuthority.cs index cd4845a5e5..041e530a7a 100644 --- a/src/Tgstation.Server.Host/Authority/IUserGroupAuthority.cs +++ b/src/Tgstation.Server.Host/Authority/IUserGroupAuthority.cs @@ -24,16 +24,18 @@ namespace Tgstation.Server.Host.Authority /// Gets the with a given . /// /// The of the . + /// If related entities should be loaded. /// The for the operation. /// A resulting in a . [TgsAuthorize(AdministrationRights.ReadUsers)] - public ValueTask> GetId(long id, CancellationToken cancellationToken); + public ValueTask> GetId(long id, bool includeJoins, CancellationToken cancellationToken); /// /// Gets all registered s. /// + /// If related entities should be loaded. /// A of s. [TgsAuthorize(AdministrationRights.ReadUsers)] - IQueryable Queryable(); + IQueryable Queryable(bool includeJoins); } } diff --git a/src/Tgstation.Server.Host/Authority/UserGroupAuthority.cs b/src/Tgstation.Server.Host/Authority/UserGroupAuthority.cs index 12faf9cc40..12005ff370 100644 --- a/src/Tgstation.Server.Host/Authority/UserGroupAuthority.cs +++ b/src/Tgstation.Server.Host/Authority/UserGroupAuthority.cs @@ -68,12 +68,19 @@ namespace Tgstation.Server.Host.Authority } /// - public async ValueTask> GetId(long id, CancellationToken cancellationToken) + public async ValueTask> GetId(long id, bool includeJoins, CancellationToken cancellationToken) { if (id != AuthenticationContext.User.GroupId && !((AdministrationRights)AuthenticationContext.GetRight(RightsType.Administration)).HasFlag(AdministrationRights.ReadUsers)) return Forbid(); - var userGroup = await userGroupsDataLoader.LoadAsync(id, cancellationToken); + UserGroup? userGroup; + if (includeJoins) + userGroup = await Queryable(true) + .Where(x => x.Id == id) + .FirstOrDefaultAsync(cancellationToken); + else + userGroup = await userGroupsDataLoader.LoadAsync(id, cancellationToken); + if (userGroup == null) return NotFound(); @@ -91,9 +98,18 @@ namespace Tgstation.Server.Host.Authority } /// - public IQueryable Queryable() - => DatabaseContext + public IQueryable Queryable(bool includeJoins) + { + var queryable = DatabaseContext .Groups .AsQueryable(); + + if (includeJoins) + queryable = queryable + .Include(x => x.Users) + .Include(x => x.PermissionSet); + + return queryable; + } } } diff --git a/src/Tgstation.Server.Host/Controllers/UserGroupController.cs b/src/Tgstation.Server.Host/Controllers/UserGroupController.cs index ae3dc2b0a8..2dd74490d0 100644 --- a/src/Tgstation.Server.Host/Controllers/UserGroupController.cs +++ b/src/Tgstation.Server.Host/Controllers/UserGroupController.cs @@ -167,20 +167,8 @@ namespace Tgstation.Server.Host.Controllers [TgsRestAuthorize(nameof(IUserGroupAuthority.GetId))] [ProducesResponseType(typeof(UserGroupResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public async ValueTask GetId(long id, CancellationToken cancellationToken) - { - // this functions as userId - var group = await DatabaseContext - .Groups - .AsQueryable() - .Where(x => x.Id == id) - .Include(x => x.Users) - .Include(x => x.PermissionSet) - .FirstOrDefaultAsync(cancellationToken); - if (group == default) - return this.Gone(); - return Json(group.ToApi(true)); - } + public ValueTask GetId(long id, CancellationToken cancellationToken) + => userGroupAuthority.InvokeTransformable(this, authority => authority.GetId(id, true, cancellationToken)); /// /// Lists all s. @@ -197,11 +185,8 @@ namespace Tgstation.Server.Host.Controllers => Paginated( () => ValueTask.FromResult( new PaginatableResult( - DatabaseContext - .Groups - .AsQueryable() - .Include(x => x.Users) - .Include(x => x.PermissionSet) + userGroupAuthority + .InvokeQueryable(authority => authority.Queryable(true)) .OrderBy(x => x.Id))), null, page, diff --git a/src/Tgstation.Server.Host/GraphQL/Types/User.cs b/src/Tgstation.Server.Host/GraphQL/Types/User.cs index 6d9f062898..87bde51eac 100644 --- a/src/Tgstation.Server.Host/GraphQL/Types/User.cs +++ b/src/Tgstation.Server.Host/GraphQL/Types/User.cs @@ -167,7 +167,7 @@ namespace Tgstation.Server.Host.GraphQL.Types return null; return await userGroupAuthority.InvokeTransformable( - authority => authority.GetId(GroupId.Value, cancellationToken)); + authority => authority.GetId(GroupId.Value, false, cancellationToken)); } } } diff --git a/src/Tgstation.Server.Host/GraphQL/Types/UserGroup.cs b/src/Tgstation.Server.Host/GraphQL/Types/UserGroup.cs index 80dec4b65c..325d552b85 100644 --- a/src/Tgstation.Server.Host/GraphQL/Types/UserGroup.cs +++ b/src/Tgstation.Server.Host/GraphQL/Types/UserGroup.cs @@ -34,7 +34,7 @@ namespace Tgstation.Server.Host.GraphQL.Types { ArgumentNullException.ThrowIfNull(userGroupAuthority); return userGroupAuthority.InvokeTransformable( - authority => authority.GetId(id, cancellationToken)); + authority => authority.GetId(id, false, cancellationToken)); } /// diff --git a/src/Tgstation.Server.Host/GraphQL/Types/UserGroups.cs b/src/Tgstation.Server.Host/GraphQL/Types/UserGroups.cs index 779a142339..78978421a8 100644 --- a/src/Tgstation.Server.Host/GraphQL/Types/UserGroups.cs +++ b/src/Tgstation.Server.Host/GraphQL/Types/UserGroups.cs @@ -58,7 +58,7 @@ namespace Tgstation.Server.Host.GraphQL.Types [Service] IGraphQLAuthorityInvoker userGroupAuthority) { ArgumentNullException.ThrowIfNull(userGroupAuthority); - var dtoQueryable = userGroupAuthority.InvokeTransformableQueryable(authority => authority.Queryable()); + var dtoQueryable = userGroupAuthority.InvokeTransformableQueryable(authority => authority.Queryable(false)); return dtoQueryable; }