From 55c591e36fa08d6a723d0b7b562bcbd64144ebf4 Mon Sep 17 00:00:00 2001 From: snixtho Date: Tue, 10 Oct 2023 20:36:28 +0200 Subject: [PATCH] 141 finish motd (#222) --- .../Models/ThemeOptions/IUIThemeConfig.cs | 4 ++-- src/EvoSC.Common/Database/MigrationManager.cs | 2 +- .../202210100826_AddPlayersTable.cs | 2 +- .../202210270837_AddConfigOptionsTable.cs | 2 +- .../Migrations/202211131231_AddMapsTable.cs | 2 +- .../202211150709_AddUserPermissionTables.cs | 2 +- .../202302081052_AddAuditLogTable.cs | 2 +- .../202306201107_AddPlayerSettingsTable.cs | 2 +- ...2307170829_UpdateAuditLogTableDataTypes.cs | 2 +- .../202309070952_UpdateConfigOptionsTable.cs | 2 +- src/EvoSC/EvoSC.csproj | 1 - .../Controllers/MotdCommandController.cs | 2 +- .../MotdEditManialinkController.cs | 7 ++++-- .../MotdModule/Models/EditMotdEntryModel.cs | 9 ++++++++ src/Modules/MotdModule/MotdPermissions.cs | 5 +++- .../MotdModule/Services/MotdService.cs | 23 ++++++++++++------- src/Modules/MotdModule/Templates/MotdEdit.mt | 8 +++---- .../MotdEditManialinkControllerTests.cs | 3 ++- 18 files changed, 51 insertions(+), 29 deletions(-) create mode 100644 src/Modules/MotdModule/Models/EditMotdEntryModel.cs diff --git a/src/EvoSC.Common/Config/Models/ThemeOptions/IUIThemeConfig.cs b/src/EvoSC.Common/Config/Models/ThemeOptions/IUIThemeConfig.cs index a61159e12..8e2d54b2e 100644 --- a/src/EvoSC.Common/Config/Models/ThemeOptions/IUIThemeConfig.cs +++ b/src/EvoSC.Common/Config/Models/ThemeOptions/IUIThemeConfig.cs @@ -22,11 +22,11 @@ public interface IUIThemeConfig public string PlayerRowBackgroundColor { get; } [Description("Colored logo to be displayed on UI elements like headers.")] - [Option(Alias = "logoUrl", DefaultValue = "https://liquipedia.net/commons/images/thumb/c/cb/XPEvo_allmode.png/600px-XPEvo_allmode.png")] + [Option(Alias = "logoUrl", DefaultValue = "")] public string LogoUrl { get; } [Description("White logo to be displayed on UI elements like headers.")] - [Option(Alias = "logoWhiteUrl", DefaultValue = "https://cdn.discordapp.com/attachments/764035004048080916/1150113831331307540/XPEvoW100px.png")] + [Option(Alias = "logoWhiteUrl", DefaultValue = "")] public string LogoWhiteUrl { get; } public IUIScoreboardThemeConfig Scoreboard { get; } diff --git a/src/EvoSC.Common/Database/MigrationManager.cs b/src/EvoSC.Common/Database/MigrationManager.cs index 7062e44c9..697d5f6fc 100644 --- a/src/EvoSC.Common/Database/MigrationManager.cs +++ b/src/EvoSC.Common/Database/MigrationManager.cs @@ -34,7 +34,7 @@ public void MigrateFromAssembly(Assembly asm) .AddEvoScLogging(_config.Logging) .Configure(opt => { - opt.Tags = new[] { "Production", "XPEvo" }; + opt.Tags = new[] { "Production" }; }) .BuildServiceProvider(false); diff --git a/src/EvoSC.Common/Database/Migrations/202210100826_AddPlayersTable.cs b/src/EvoSC.Common/Database/Migrations/202210100826_AddPlayersTable.cs index 1adf6cc15..24c59ca4c 100644 --- a/src/EvoSC.Common/Database/Migrations/202210100826_AddPlayersTable.cs +++ b/src/EvoSC.Common/Database/Migrations/202210100826_AddPlayersTable.cs @@ -3,7 +3,7 @@ namespace EvoSC.Common.Database.Migrations; -[Tags("XPEvo", "Production")] +[Tags("Production")] [Migration(1665390396)] public class AddPlayersTable : Migration { diff --git a/src/EvoSC.Common/Database/Migrations/202210270837_AddConfigOptionsTable.cs b/src/EvoSC.Common/Database/Migrations/202210270837_AddConfigOptionsTable.cs index a60aee58f..d4a30feef 100644 --- a/src/EvoSC.Common/Database/Migrations/202210270837_AddConfigOptionsTable.cs +++ b/src/EvoSC.Common/Database/Migrations/202210270837_AddConfigOptionsTable.cs @@ -2,7 +2,7 @@ namespace EvoSC.Common.Database.Migrations; -[Tags("XPEvo", "Production")] +[Tags("Production")] [Migration(1666859869)] public class AddConfigOptionsTable : Migration { diff --git a/src/EvoSC.Common/Database/Migrations/202211131231_AddMapsTable.cs b/src/EvoSC.Common/Database/Migrations/202211131231_AddMapsTable.cs index e947c5716..802cea5db 100644 --- a/src/EvoSC.Common/Database/Migrations/202211131231_AddMapsTable.cs +++ b/src/EvoSC.Common/Database/Migrations/202211131231_AddMapsTable.cs @@ -2,7 +2,7 @@ namespace EvoSC.Common.Database.Migrations; -[Tags("XPEvo", "Production")] +[Tags("Production")] [Migration(1668338922)] public class AddMapsTable : Migration { diff --git a/src/EvoSC.Common/Database/Migrations/202211150709_AddUserPermissionTables.cs b/src/EvoSC.Common/Database/Migrations/202211150709_AddUserPermissionTables.cs index 5000d5430..7b4c8a6e3 100644 --- a/src/EvoSC.Common/Database/Migrations/202211150709_AddUserPermissionTables.cs +++ b/src/EvoSC.Common/Database/Migrations/202211150709_AddUserPermissionTables.cs @@ -2,7 +2,7 @@ namespace EvoSC.Common.Database.Migrations; -[Tags("XPEvo", "Production")] +[Tags("Production")] [Migration(1668492589)] public class AddUserPermissionTables : Migration { diff --git a/src/EvoSC.Common/Database/Migrations/202302081052_AddAuditLogTable.cs b/src/EvoSC.Common/Database/Migrations/202302081052_AddAuditLogTable.cs index c628f3020..5c7ae0340 100644 --- a/src/EvoSC.Common/Database/Migrations/202302081052_AddAuditLogTable.cs +++ b/src/EvoSC.Common/Database/Migrations/202302081052_AddAuditLogTable.cs @@ -2,7 +2,7 @@ namespace EvoSC.Common.Database.Migrations; -[Tags("XPEvo", "Production")] +[Tags("Production")] [Migration(1675849925)] public class AddAuditLogTable : Migration { diff --git a/src/EvoSC.Common/Database/Migrations/202306201107_AddPlayerSettingsTable.cs b/src/EvoSC.Common/Database/Migrations/202306201107_AddPlayerSettingsTable.cs index e70b00ff0..fb9a0044e 100644 --- a/src/EvoSC.Common/Database/Migrations/202306201107_AddPlayerSettingsTable.cs +++ b/src/EvoSC.Common/Database/Migrations/202306201107_AddPlayerSettingsTable.cs @@ -2,7 +2,7 @@ namespace EvoSC.Common.Database.Migrations; -[Tags("XPEvo", "Production")] +[Tags("Production")] [Migration(1687252035)] public class AddPlayerSettingsTable : Migration { diff --git a/src/EvoSC.Common/Database/Migrations/202307170829_UpdateAuditLogTableDataTypes.cs b/src/EvoSC.Common/Database/Migrations/202307170829_UpdateAuditLogTableDataTypes.cs index 23e34aa8f..a6f4ae650 100644 --- a/src/EvoSC.Common/Database/Migrations/202307170829_UpdateAuditLogTableDataTypes.cs +++ b/src/EvoSC.Common/Database/Migrations/202307170829_UpdateAuditLogTableDataTypes.cs @@ -2,7 +2,7 @@ namespace EvoSC.Common.Database.Migrations; -[Tags("XPEvo", "Production")] +[Tags("Production")] [Migration(1689575375)] public class UpdateAuditLogTableDataTypes : Migration { diff --git a/src/EvoSC.Common/Database/Migrations/202309070952_UpdateConfigOptionsTable.cs b/src/EvoSC.Common/Database/Migrations/202309070952_UpdateConfigOptionsTable.cs index ec07c9f3b..2b4a2ea4b 100644 --- a/src/EvoSC.Common/Database/Migrations/202309070952_UpdateConfigOptionsTable.cs +++ b/src/EvoSC.Common/Database/Migrations/202309070952_UpdateConfigOptionsTable.cs @@ -2,7 +2,7 @@ namespace EvoSC.Common.Database.Migrations; -[Tags("XPEvo", "Production")] +[Tags("Production")] [Migration(1694073143)] public class UpdateConfigOptionsTable : Migration { diff --git a/src/EvoSC/EvoSC.csproj b/src/EvoSC/EvoSC.csproj index b4db4600a..598d50862 100644 --- a/src/EvoSC/EvoSC.csproj +++ b/src/EvoSC/EvoSC.csproj @@ -66,7 +66,6 @@ - diff --git a/src/Modules/MotdModule/Controllers/MotdCommandController.cs b/src/Modules/MotdModule/Controllers/MotdCommandController.cs index a84f19dd9..dafa07bc5 100644 --- a/src/Modules/MotdModule/Controllers/MotdCommandController.cs +++ b/src/Modules/MotdModule/Controllers/MotdCommandController.cs @@ -30,7 +30,7 @@ public void SetMotdLocal(string local) } } - [ChatCommand("motdedit", "[Command.EditMotd]", MotdPermissions.OpenMotdEdit)] + [ChatCommand("motdedit", "[Command.EditMotd]", MotdPermissions.EditMotd)] public async Task OpenEditMotdAsync() => await _motdService.ShowEditAsync(Context.Player); diff --git a/src/Modules/MotdModule/Controllers/MotdEditManialinkController.cs b/src/Modules/MotdModule/Controllers/MotdEditManialinkController.cs index ebd2d2bc4..e327e85d0 100644 --- a/src/Modules/MotdModule/Controllers/MotdEditManialinkController.cs +++ b/src/Modules/MotdModule/Controllers/MotdEditManialinkController.cs @@ -1,6 +1,8 @@ using EvoSC.Common.Controllers.Attributes; using EvoSC.Manialinks; +using EvoSC.Manialinks.Attributes; using EvoSC.Modules.Official.MotdModule.Interfaces; +using EvoSC.Modules.Official.MotdModule.Models; namespace EvoSC.Modules.Official.MotdModule.Controllers; @@ -14,9 +16,10 @@ public MotdEditManialinkController(IMotdService motdService) _motdService = motdService; } - public async Task SaveAsync(string text) + [ManialinkRoute(Permission = MotdPermissions.EditMotd)] + public async Task SaveAsync(EditMotdEntryModel input) { - _motdService.SetLocalMotd(text, Context.Player); + _motdService.SetLocalMotd(input.Text, Context.Player); await HideAsync(Context.Player, "MotdModule.MotdEdit"); } } diff --git a/src/Modules/MotdModule/Models/EditMotdEntryModel.cs b/src/Modules/MotdModule/Models/EditMotdEntryModel.cs new file mode 100644 index 000000000..561205fd7 --- /dev/null +++ b/src/Modules/MotdModule/Models/EditMotdEntryModel.cs @@ -0,0 +1,9 @@ +using EvoSC.Manialinks.Attributes; + +namespace EvoSC.Modules.Official.MotdModule.Models; + +[FormEntryModel] +public class EditMotdEntryModel +{ + public string Text { get; set; } +} diff --git a/src/Modules/MotdModule/MotdPermissions.cs b/src/Modules/MotdModule/MotdPermissions.cs index 882e0c0e6..9413a6fd3 100644 --- a/src/Modules/MotdModule/MotdPermissions.cs +++ b/src/Modules/MotdModule/MotdPermissions.cs @@ -8,10 +8,13 @@ public enum MotdPermissions { [Description("Set Url to fetch Motd from.")] SetUrl, + [Description("Interval of the timer to fetch Motd.")] SetFetchInterval, + [Description("Changes motd to be fetched from local.")] SetLocal, + [Description("Opens the Motd editor for local motd.")] - OpenMotdEdit + EditMotd } diff --git a/src/Modules/MotdModule/Services/MotdService.cs b/src/Modules/MotdModule/Services/MotdService.cs index 46743fc0f..0733990a9 100644 --- a/src/Modules/MotdModule/Services/MotdService.cs +++ b/src/Modules/MotdModule/Services/MotdService.cs @@ -1,4 +1,5 @@ -using System.Timers; +using System.Security; +using System.Timers; using EvoSC.Common.Interfaces.Controllers; using EvoSC.Common.Interfaces.Models; using EvoSC.Common.Interfaces.Services; @@ -57,7 +58,7 @@ public MotdService(IManialinkManager manialink, IHttpService httpService, }; if (_isMotdLocal) { - MotdText = _settings.MotdLocalText; + MotdText = SecurityElement.Escape(_settings.MotdLocalText); } _motdUpdateTimer.Elapsed += MotdUpdateTimerOnElapsed; @@ -73,7 +74,7 @@ private void MotdUpdateTimerOnElapsed(object? sender, ElapsedEventArgs e) } timer.Interval = _timerInterval; - MotdText = GetMotdAsync().Result; + MotdText = SecurityElement.Escape(GetMotdAsync().Result); _logger.LogDebug($"Fetching Motd"); } @@ -92,7 +93,7 @@ public void SetLocalMotd(string text, IPlayer player) { var old = _settings.MotdLocalText; _settings.MotdLocalText = text; - MotdText = text; + MotdText = SecurityElement.Escape(text); _context.Audit().Success() .WithEventName(AuditEvents.LocalTextSet) @@ -107,7 +108,7 @@ public void SetMotdSource(bool local, IPlayer player) _isMotdLocal = local; if (local) { - MotdText = _settings.MotdLocalText; + MotdText = SecurityElement.Escape(_settings.MotdLocalText); } else { @@ -125,7 +126,7 @@ public void SetUrl(string url, IPlayer player) { var oldUri = _motdUrl; _motdUrl = url; - MotdText = GetMotdAsync().Result; + MotdText = SecurityElement.Escape(GetMotdAsync().Result); if (!_motdUpdateTimer.Enabled) { _motdUpdateTimer.Enabled = true; // re-enable the timer when the url updates. @@ -144,7 +145,7 @@ public async Task ShowEditAsync(IPlayer player) .HavingProperties(new {Player = player}) .Comment("Local Motd editor shown."); - await _manialink.SendManialinkAsync(player, "MotdModule.MotdEdit", new { text = _settings.MotdLocalText }); + await _manialink.SendManialinkAsync(player, "MotdModule.MotdEdit", new { text = MotdText }); } public async Task ShowAsync(string login, bool explicitly) @@ -169,8 +170,14 @@ public async Task ShowAsync(IPlayer? player, bool explicitly) hidden = playerEntry.Hidden; } } + var isCheckboxChecked = hidden ?? false; - await _manialink.SendManialinkAsync(player, "MotdModule.MotdTemplate", new { isChecked = isCheckboxChecked, text = MotdText }); + await _manialink.SendManialinkAsync(player, "MotdModule.MotdTemplate", + new + { + isChecked = isCheckboxChecked, + text = MotdText + }); } public async Task GetMotdAsync() diff --git a/src/Modules/MotdModule/Templates/MotdEdit.mt b/src/Modules/MotdModule/Templates/MotdEdit.mt index ed1fea2e9..56106ea23 100644 --- a/src/Modules/MotdModule/Templates/MotdEdit.mt +++ b/src/Modules/MotdModule/Templates/MotdEdit.mt @@ -22,11 +22,11 @@ @@ -38,7 +38,7 @@ if (Event.Control.ControlId == "button_save") { TriggerPageAction("MotdEditManialinkController/Save/"^(Page.GetFirstChild("textedit_text") as CMlTextEdit).Value); CloseWindow("evosc-window"); - } else if (Event.Control.ControlId == "button_close") { + } else if (Event.Control.ControlId == "btnClose") { CloseWindow("evosc-window"); } *** diff --git a/tests/Modules/MotdModule.Tests/MotdEditManialinkControllerTests.cs b/tests/Modules/MotdModule.Tests/MotdEditManialinkControllerTests.cs index 4b05f04bb..38bb32dcc 100644 --- a/tests/Modules/MotdModule.Tests/MotdEditManialinkControllerTests.cs +++ b/tests/Modules/MotdModule.Tests/MotdEditManialinkControllerTests.cs @@ -2,6 +2,7 @@ using EvoSC.Manialinks.Interfaces.Models; using EvoSC.Modules.Official.MotdModule.Controllers; using EvoSC.Modules.Official.MotdModule.Interfaces; +using EvoSC.Modules.Official.MotdModule.Models; using EvoSC.Testing.Controllers; using Moq; @@ -21,7 +22,7 @@ public MotdEditManialinkControllerTests() [Fact] public async Task SaveAsync_Closes_Manialink_And_Sets_LocalMotd() { - await Controller.SaveAsync("testing stuff"); + await Controller.SaveAsync(new EditMotdEntryModel { Text = "testing stuff" }); ManialinkManager.Verify(m => m.HideManialinkAsync(_actor.Object, "MotdModule.MotdEdit")); _motdService.Verify(r => r.SetLocalMotd("testing stuff", It.IsAny()));