From a5eb0001e435125545825d2653d68c47bdb3635f Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 26 Sep 2022 22:34:15 -0400 Subject: [PATCH] Various code cleanups --- .../Controllers/InstanceController.cs | 29 +++++++++---------- .../Security/OAuth/TGForumsOAuthValidator.cs | 6 ++-- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/Tgstation.Server.Host/Controllers/InstanceController.cs b/src/Tgstation.Server.Host/Controllers/InstanceController.cs index 22ca5e00ee..f357240410 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceController.cs @@ -261,11 +261,17 @@ namespace Tgstation.Server.Host.Controllers }); } - Logger.LogInformation("{0} {1} instance {2}: {3} ({4})", AuthenticationContext.User.Name, attached ? "attached" : "created", newInstance.Name, newInstance.Id, newInstance.Path); + Logger.LogInformation( + "{userName} {attachedOrCreated} instance {instanceName}: {instanceId} ({instancePath})", + AuthenticationContext.User.Name, + attached ? "attached" : "created", + newInstance.Name, + newInstance.Id, + newInstance.Path); var api = newInstance.ToApi(); api.Accessible = true; // instances are always accessible by their creator - return attached ? (IActionResult)Json(api) : Created(api); + return attached ? Json(api) : Created(api); } /// @@ -337,9 +343,7 @@ namespace Tgstation.Server.Host.Controllers var moveJob = await InstanceQuery() .SelectMany(x => x.Jobs). -#pragma warning disable CA1310 // Specify StringComparison Where(x => !x.StoppedAt.HasValue && x.Description.StartsWith(MoveInstanceJobPrefix)) -#pragma warning restore CA1310 // Specify StringComparison .Select(x => new Job { Id = x.Id, @@ -451,7 +455,7 @@ namespace Tgstation.Server.Host.Controllers } catch (Exception e) { - if (!(e is OperationCanceledException)) + if (e is not OperationCanceledException) Logger.LogError(e, "Error changing instance online state!"); originalModel.Online = originalOnline; originalModel.DreamDaemonSettings.AutoStart = oldAutoStart; @@ -497,7 +501,7 @@ namespace Tgstation.Server.Host.Controllers } await CheckAccessible(api, cancellationToken); - return moving ? (IActionResult)Accepted(api) : Json(api); + return moving ? Accepted(api) : Json(api); } #pragma warning restore CA1502 @@ -540,9 +544,7 @@ namespace Tgstation.Server.Host.Controllers var moveJobs = await GetBaseQuery() .SelectMany(x => x.Jobs) -#pragma warning disable CA1310 // Specify StringComparison .Where(x => !x.StoppedAt.HasValue && x.Description.StartsWith(MoveInstanceJobPrefix)) -#pragma warning restore CA1310 // Specify StringComparison .Include(x => x.StartedBy).ThenInclude(x => x.CreatedBy) .Include(x => x.Instance) .ToListAsync(cancellationToken) @@ -620,9 +622,7 @@ namespace Tgstation.Server.Host.Controllers var moveJob = await QueryForUser() .SelectMany(x => x.Jobs) -#pragma warning disable CA1310 // Specify StringComparison .Where(x => !x.StoppedAt.HasValue && x.Description.StartsWith(MoveInstanceJobPrefix)) -#pragma warning restore CA1310 // Specify StringComparison .Include(x => x.StartedBy).ThenInclude(x => x.CreatedBy) .FirstOrDefaultAsync(cancellationToken) ; @@ -764,11 +764,10 @@ namespace Tgstation.Server.Host.Controllers /// or a new with full rights. InstancePermissionSet InstanceAdminPermissionSet(InstancePermissionSet permissionSetToModify) { - if (permissionSetToModify == null) - permissionSetToModify = new InstancePermissionSet() - { - PermissionSetId = AuthenticationContext.PermissionSet.Id.Value, - }; + permissionSetToModify ??= new InstancePermissionSet() + { + PermissionSetId = AuthenticationContext.PermissionSet.Id.Value, + }; permissionSetToModify.ByondRights = RightsHelper.AllRights(); permissionSetToModify.ChatBotRights = RightsHelper.AllRights(); permissionSetToModify.ConfigurationRights = RightsHelper.AllRights(); diff --git a/src/Tgstation.Server.Host/Security/OAuth/TGForumsOAuthValidator.cs b/src/Tgstation.Server.Host/Security/OAuth/TGForumsOAuthValidator.cs index 1783a03993..3c0f504986 100644 --- a/src/Tgstation.Server.Host/Security/OAuth/TGForumsOAuthValidator.cs +++ b/src/Tgstation.Server.Host/Security/OAuth/TGForumsOAuthValidator.cs @@ -18,10 +18,10 @@ namespace Tgstation.Server.Host.Security.OAuth public override OAuthProvider Provider => OAuthProvider.TGForums; /// - protected override Uri TokenUrl => new Uri("https://tgstation13.org/phpBB/app.php/tgapi/oauth/token"); + protected override Uri TokenUrl => new ("https://tgstation13.org/phpBB/app.php/tgapi/oauth/token"); /// - protected override Uri UserInformationUrl => new Uri("https://tgstation13.org/phpBB/app.php/tgapi/user/me"); + protected override Uri UserInformationUrl => new ("https://tgstation13.org/phpBB/app.php/tgapi/user/me"); /// /// Initializes a new instance of the class. @@ -50,6 +50,6 @@ namespace Tgstation.Server.Host.Security.OAuth protected override string DecodeUserInformationPayload(dynamic responseJson) => responseJson.phpbb_username; /// - protected override OAuthTokenRequest CreateTokenRequest(string code) => new OAuthTokenRequest(OAuthConfiguration, code, "user"); + protected override OAuthTokenRequest CreateTokenRequest(string code) => new (OAuthConfiguration, code, "user"); } }