Nullify DreamMakerController

This commit is contained in:
Jordan Dominion
2023-12-20 14:15:45 -05:00
parent 62d5dcb7cc
commit ecf95607e8
2 changed files with 22 additions and 19 deletions
@@ -267,7 +267,7 @@ namespace Tgstation.Server.Host.Controllers
/// </summary>
/// <typeparam name="TModel">The <see cref="Type"/> of model being generated and returned.</typeparam>
/// <param name="queryGenerator">A <see cref="Func{TResult}"/> resulting in a <see cref="Task{TResult}"/> resulting in the generated <see cref="PaginatableResult{TModel}"/>.</param>
/// <param name="resultTransformer">A <see cref="Func{T, TResult}"/> to transform the <typeparamref name="TModel"/>s after being queried.</param>
/// <param name="resultTransformer">Optional <see cref="Func{T, TResult}"/> to transform the <typeparamref name="TModel"/>s after being queried.</param>
/// <param name="pageQuery">The requested page from the query.</param>
/// <param name="pageSizeQuery">The requested page size from the query.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
@@ -297,7 +297,7 @@ namespace Tgstation.Server.Host.Controllers
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="IActionResult"/> for the operation.</returns>
protected ValueTask<IActionResult> Paginated<TModel, TApiModel>(
Func<ValueTask<PaginatableResult<TModel>>> queryGenerator,
Func<TApiModel, ValueTask> resultTransformer,
Func<TApiModel, ValueTask>? resultTransformer,
int? pageQuery,
int? pageSizeQuery,
CancellationToken cancellationToken)
@@ -21,8 +21,6 @@ using Tgstation.Server.Host.Models;
using Tgstation.Server.Host.Security;
using Tgstation.Server.Host.Utils;
#nullable disable
namespace Tgstation.Server.Host.Controllers
{
/// <summary>
@@ -87,6 +85,10 @@ namespace Tgstation.Server.Host.Controllers
.AsQueryable()
.Where(x => x.InstanceId == Instance.Id)
.FirstOrDefaultAsync(cancellationToken);
if (dreamMakerSettings == null)
return this.Gone();
return Json(dreamMakerSettings.ToApi());
}
@@ -189,9 +191,10 @@ namespace Tgstation.Server.Host.Controllers
if (hostModel == null)
return this.Gone();
var dreamMakerRights = InstancePermissionSet.DreamMakerRights!.Value;
if (model.ProjectName != null)
{
if (!AuthenticationContext.InstancePermissionSet.DreamMakerRights.Value.HasFlag(DreamMakerRights.SetDme))
if (!dreamMakerRights.HasFlag(DreamMakerRights.SetDme))
return Forbid();
if (model.ProjectName.Length == 0)
hostModel.ProjectName = null;
@@ -201,10 +204,10 @@ namespace Tgstation.Server.Host.Controllers
if (model.ApiValidationPort.HasValue)
{
if (!AuthenticationContext.InstancePermissionSet.DreamMakerRights.Value.HasFlag(DreamMakerRights.SetApiValidationPort))
if (!dreamMakerRights.HasFlag(DreamMakerRights.SetApiValidationPort))
return Forbid();
if (model.ApiValidationPort.Value != hostModel.ApiValidationPort.Value)
if (model.ApiValidationPort.Value != hostModel.ApiValidationPort!.Value)
{
var verifiedPort = await portAllocator
.GetAvailablePort(
@@ -220,28 +223,28 @@ namespace Tgstation.Server.Host.Controllers
if (model.ApiValidationSecurityLevel.HasValue)
{
if (!AuthenticationContext.InstancePermissionSet.DreamMakerRights.Value.HasFlag(DreamMakerRights.SetSecurityLevel))
if (!dreamMakerRights.HasFlag(DreamMakerRights.SetSecurityLevel))
return Forbid();
hostModel.ApiValidationSecurityLevel = model.ApiValidationSecurityLevel;
}
if (model.RequireDMApiValidation.HasValue)
{
if (!AuthenticationContext.InstancePermissionSet.DreamMakerRights.Value.HasFlag(DreamMakerRights.SetApiValidationRequirement))
if (!dreamMakerRights.HasFlag(DreamMakerRights.SetApiValidationRequirement))
return Forbid();
hostModel.RequireDMApiValidation = model.RequireDMApiValidation;
}
if (model.Timeout.HasValue)
{
if (!AuthenticationContext.InstancePermissionSet.DreamMakerRights.Value.HasFlag(DreamMakerRights.SetTimeout))
if (!dreamMakerRights.HasFlag(DreamMakerRights.SetTimeout))
return Forbid();
hostModel.Timeout = model.Timeout;
}
await DatabaseContext.Save(cancellationToken);
if ((AuthenticationContext.GetRight(RightsType.DreamMaker) & (ulong)DreamMakerRights.Read) == 0)
if (!dreamMakerRights.HasFlag(DreamMakerRights.Read))
return NoContent();
return await Read(cancellationToken);
@@ -254,17 +257,17 @@ namespace Tgstation.Server.Host.Controllers
IQueryable<CompileJob> BaseCompileJobsQuery() => DatabaseContext
.CompileJobs
.AsQueryable()
.Include(x => x.Job)
.Include(x => x.Job!)
.ThenInclude(x => x.StartedBy)
.Include(x => x.Job)
.Include(x => x.Job!)
.ThenInclude(x => x.Instance)
.Include(x => x.RevisionInformation)
.ThenInclude(x => x.PrimaryTestMerge)
.Include(x => x.RevisionInformation!)
.ThenInclude(x => x.PrimaryTestMerge!)
.ThenInclude(x => x.MergedBy)
.Include(x => x.RevisionInformation)
.ThenInclude(x => x.ActiveTestMerges)
.ThenInclude(x => x.TestMerge)
.ThenInclude(x => x.MergedBy)
.Where(x => x.Job.Instance.Id == Instance.Id);
.ThenInclude(x => x.ActiveTestMerges!)
.ThenInclude(x => x!.TestMerge)
.ThenInclude(x => x!.MergedBy)
.Where(x => x.Job.Instance!.Id == Instance.Id);
}
}