diff --git a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs index 7c874e536a..f83ec8410f 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs @@ -25,8 +25,6 @@ using Tgstation.Server.Host.Utils; #pragma warning disable API1001 // Action method returns a success result without a corresponding ProducesResponseType. Somehow this happens ONLY IN THIS CONTROLLER??? -#nullable disable - namespace Tgstation.Server.Host.Controllers { /// @@ -174,7 +172,7 @@ namespace Tgstation.Server.Host.Controllers if (current == default) return this.Gone(); - if (model.Port.HasValue && model.Port.Value != current.Port.Value) + if (model.Port.HasValue && model.Port.Value != current.Port!.Value) { var verifiedPort = await portAllocator .GetAvailablePort( @@ -203,14 +201,15 @@ namespace Tgstation.Server.Host.Controllers return false; } + var ddRights = InstancePermissionSet.DreamDaemonRights!.Value; if (CheckModified(x => x.AllowWebClient, DreamDaemonRights.SetWebClient) || CheckModified(x => x.AutoStart, DreamDaemonRights.SetAutoStart) || CheckModified(x => x.Port, DreamDaemonRights.SetPort) || CheckModified(x => x.SecurityLevel, DreamDaemonRights.SetSecurity) || CheckModified(x => x.Visibility, DreamDaemonRights.SetVisibility) - || (model.SoftRestart.HasValue && !AuthenticationContext.InstancePermissionSet.DreamDaemonRights.Value.HasFlag(DreamDaemonRights.SoftRestart)) - || (model.SoftShutdown.HasValue && !AuthenticationContext.InstancePermissionSet.DreamDaemonRights.Value.HasFlag(DreamDaemonRights.SoftShutdown)) - || (!String.IsNullOrWhiteSpace(model.BroadcastMessage) && !AuthenticationContext.InstancePermissionSet.DreamDaemonRights.Value.HasFlag(DreamDaemonRights.BroadcastMessage)) + || (model.SoftRestart.HasValue && !ddRights.HasFlag(DreamDaemonRights.SoftRestart)) + || (model.SoftShutdown.HasValue && !ddRights.HasFlag(DreamDaemonRights.SoftShutdown)) + || (!String.IsNullOrWhiteSpace(model.BroadcastMessage) && !ddRights.HasFlag(DreamDaemonRights.BroadcastMessage)) || CheckModified(x => x.StartupTimeout, DreamDaemonRights.SetStartupTimeout) || CheckModified(x => x.HealthCheckSeconds, DreamDaemonRights.SetHealthCheckInterval) || CheckModified(x => x.DumpOnHealthCheckRestart, DreamDaemonRights.CreateDump) @@ -310,7 +309,7 @@ namespace Tgstation.Server.Host.Controllers /// If there was a settings change made that forced a switch to . /// The for the operation. /// A resulting in the of the operation. - ValueTask ReadImpl(DreamDaemonSettings settings, bool knownForcedReboot, CancellationToken cancellationToken) + ValueTask ReadImpl(DreamDaemonSettings? settings, bool knownForcedReboot, CancellationToken cancellationToken) => WithComponentInstance(async instance => { var dd = instance.Watchdog; @@ -324,7 +323,7 @@ namespace Tgstation.Server.Host.Controllers .Instances .AsQueryable() .Where(x => x.Id == Instance.Id) - .Select(x => x.DreamDaemonSettings) + .Select(x => x.DreamDaemonSettings!) .FirstOrDefaultAsync(cancellationToken); if (settings == default) return this.Gone(); @@ -336,13 +335,13 @@ namespace Tgstation.Server.Host.Controllers var alphaActive = dd.AlphaIsActive; var llp = dd.LastLaunchParameters; var rstate = dd.RebootState; - result.AutoStart = settings.AutoStart.Value; - result.CurrentPort = llp?.Port.Value; - result.CurrentSecurity = llp?.SecurityLevel.Value; - result.CurrentVisibility = llp?.Visibility.Value; - result.CurrentAllowWebclient = llp?.AllowWebClient.Value; - result.Port = settings.Port.Value; - result.AllowWebClient = settings.AllowWebClient.Value; + result.AutoStart = settings.AutoStart!.Value; + result.CurrentPort = llp?.Port!.Value; + result.CurrentSecurity = llp?.SecurityLevel!.Value; + result.CurrentVisibility = llp?.Visibility!.Value; + result.CurrentAllowWebclient = llp?.AllowWebClient!.Value; + result.Port = settings.Port!.Value; + result.AllowWebClient = settings.AllowWebClient!.Value; var firstIteration = true; do @@ -359,18 +358,18 @@ namespace Tgstation.Server.Host.Controllers } while (result.Status == WatchdogStatus.Online && !result.SessionId.HasValue); // this is the one invalid combo, it's not that racy - result.SecurityLevel = settings.SecurityLevel.Value; - result.Visibility = settings.Visibility.Value; + result.SecurityLevel = settings.SecurityLevel!.Value; + result.Visibility = settings.Visibility!.Value; result.SoftRestart = rstate == RebootState.Restart; result.SoftShutdown = rstate == RebootState.Shutdown; if (rstate == RebootState.Normal && knownForcedReboot) result.SoftRestart = true; - result.StartupTimeout = settings.StartupTimeout.Value; - result.HealthCheckSeconds = settings.HealthCheckSeconds.Value; - result.DumpOnHealthCheckRestart = settings.DumpOnHealthCheckRestart.Value; - result.TopicRequestTimeout = settings.TopicRequestTimeout.Value; + result.StartupTimeout = settings.StartupTimeout!.Value; + result.HealthCheckSeconds = settings.HealthCheckSeconds!.Value; + result.DumpOnHealthCheckRestart = settings.DumpOnHealthCheckRestart!.Value; + result.TopicRequestTimeout = settings.TopicRequestTimeout!.Value; result.AdditionalParameters = settings.AdditionalParameters; result.StartProfiler = settings.StartProfiler; result.LogOutput = settings.LogOutput; diff --git a/src/Tgstation.Server.Host/Controllers/InstanceRequiredController.cs b/src/Tgstation.Server.Host/Controllers/InstanceRequiredController.cs index 68dec10504..1e36f544b4 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceRequiredController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceRequiredController.cs @@ -19,6 +19,11 @@ namespace Tgstation.Server.Host.Controllers /// protected new Models.Instance Instance => base.Instance!; + /// + /// The for the request. + /// + protected Models.InstancePermissionSet InstancePermissionSet => AuthenticationContext.InstancePermissionSet!; + /// /// Initializes a new instance of the class. ///