From 22f9e581ed7b863f3ba555fa037453a5fab83e78 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Thu, 6 Aug 2020 08:48:14 -0500 Subject: [PATCH] fix dependency injection of comands in webfront preventing ui actions from working --- Tests/ApplicationTests/ControllerTests.cs | 14 ++++++++++++++ WebfrontCore/Controllers/ActionController.cs | 6 +++++- WebfrontCore/Startup.cs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Tests/ApplicationTests/ControllerTests.cs b/Tests/ApplicationTests/ControllerTests.cs index 28a103800..5d661779b 100644 --- a/Tests/ApplicationTests/ControllerTests.cs +++ b/Tests/ApplicationTests/ControllerTests.cs @@ -38,6 +38,7 @@ namespace ApplicationTests .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .BuildServiceProvider() .SetupTestHooks(); @@ -141,6 +142,19 @@ namespace ApplicationTests Assert.AreEqual(expectedEndpoint, result.RouteValues["serverId"]); Assert.AreEqual(expectedCommandText, result.RouteValues["command"]); } + + [Test] + public async Task Test_SetLevel_Redirects_WithCommandText() + { + var controller = serviceProvider.GetRequiredService(); + var expectedCommandText = "!setlevel @1 Moderator"; + var expectedEndpoint = server.EndPoint; + + var result = await controller.EditAsync(1, "Moderator") as RedirectToActionResult; + + Assert.AreEqual(expectedEndpoint, result.RouteValues["serverId"]); + Assert.AreEqual(expectedCommandText, result.RouteValues["command"]); + } #endregion } } diff --git a/WebfrontCore/Controllers/ActionController.cs b/WebfrontCore/Controllers/ActionController.cs index e6b846944..0c79e3c1d 100644 --- a/WebfrontCore/Controllers/ActionController.cs +++ b/WebfrontCore/Controllers/ActionController.cs @@ -23,6 +23,7 @@ namespace WebfrontCore.Controllers private readonly string _kickCommandName; private readonly string _flagCommandName; private readonly string _unflagCommandName; + private readonly string _setLevelCommandName; public ActionController(IManager manager, IEnumerable registeredCommands) : base(manager) { @@ -55,6 +56,9 @@ namespace WebfrontCore.Controllers case nameof(UnflagClientCommand): _unflagCommandName = cmd.Name; break; + case nameof(SetLevelCommand): + _setLevelCommandName = cmd.Name; + break; } } } @@ -230,7 +234,7 @@ namespace WebfrontCore.Controllers return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new { serverId = server.EndPoint, - command = $"{_appConfig.CommandPrefix}setlevel @{targetId} {level}" + command = $"{_appConfig.CommandPrefix}{_setLevelCommandName} @{targetId} {level}" })); } diff --git a/WebfrontCore/Startup.cs b/WebfrontCore/Startup.cs index d39321e21..b961579b9 100644 --- a/WebfrontCore/Startup.cs +++ b/WebfrontCore/Startup.cs @@ -124,6 +124,7 @@ namespace WebfrontCore services.AddSingleton(Program.ApplicationServiceProvider.GetService()); services.AddSingleton(Program.ApplicationServiceProvider.GetService()); services.AddSingleton(Program.ApplicationServiceProvider.GetService()); + services.AddSingleton(Program.ApplicationServiceProvider.GetService>()); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.