From 1829e5c9404024e7be4f0c8b7c7884a45556a2fa Mon Sep 17 00:00:00 2001 From: sysadmin Date: Wed, 27 Aug 2025 22:41:18 +0100 Subject: [PATCH] "Fix-security-and-config-from-TestAgent" --- .../Areas/Admin/Controllers/BotsController.cs | 2 +- LittleShop/Program.cs | 4 +++- LittleShop/Services/TelegramBotManagerService.cs | 13 +++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/LittleShop/Areas/Admin/Controllers/BotsController.cs b/LittleShop/Areas/Admin/Controllers/BotsController.cs index e67e5c3..ec65184 100644 --- a/LittleShop/Areas/Admin/Controllers/BotsController.cs +++ b/LittleShop/Areas/Admin/Controllers/BotsController.cs @@ -289,7 +289,7 @@ public class BotsController : Controller } // GET: Admin/Bots/RegenerateKey/5 - public async Task RegenerateKey(Guid id) + public IActionResult RegenerateKey(Guid id) { // This would require updating the bot model to support key regeneration TempData["Error"] = "Key regeneration not yet implemented"; diff --git a/LittleShop/Program.cs b/LittleShop/Program.cs index a1a6029..180e9f5 100644 --- a/LittleShop/Program.cs +++ b/LittleShop/Program.cs @@ -53,7 +53,9 @@ builder.Services.AddAuthentication("Cookies") builder.Services.AddAuthorization(options => { - options.AddPolicy("AdminOnly", policy => policy.RequireAuthenticatedUser()); + options.AddPolicy("AdminOnly", policy => + policy.RequireAuthenticatedUser() + .RequireRole("Admin")); options.AddPolicy("ApiAccess", policy => policy.RequireAuthenticatedUser()); }); diff --git a/LittleShop/Services/TelegramBotManagerService.cs b/LittleShop/Services/TelegramBotManagerService.cs index 6e1daa8..fb9e2a5 100644 --- a/LittleShop/Services/TelegramBotManagerService.cs +++ b/LittleShop/Services/TelegramBotManagerService.cs @@ -49,13 +49,13 @@ public class TelegramBotManagerService : BackgroundService, ITelegramBotManagerS } } - public async Task StartAsync(CancellationToken cancellationToken) + public override async Task StartAsync(CancellationToken cancellationToken) { _logger.LogInformation("Telegram Bot Manager Service started"); await base.StartAsync(cancellationToken); } - public async Task StopAsync(CancellationToken cancellationToken) + public override async Task StopAsync(CancellationToken cancellationToken) { _logger.LogInformation("Stopping all Telegram bots..."); @@ -122,15 +122,15 @@ public class TelegramBotManagerService : BackgroundService, ITelegramBotManagerS return false; } - public async Task UpdateBotSettingsAsync(Guid botId) + public Task UpdateBotSettingsAsync(Guid botId) { if (_activeBots.TryGetValue(botId, out var botInstance)) { // Reload settings from database _logger.LogInformation("Updating settings for bot {BotId}", botId); - return true; + return Task.FromResult(true); } - return false; + return Task.FromResult(false); } public Task GetActiveBotCount() @@ -174,7 +174,7 @@ public class TelegramBotManagerService : BackgroundService, ITelegramBotManagerS } } - private async Task PerformHealthChecksAsync() + private Task PerformHealthChecksAsync() { foreach (var kvp in _activeBots) { @@ -189,6 +189,7 @@ public class TelegramBotManagerService : BackgroundService, ITelegramBotManagerS _logger.LogWarning(ex, "Health check failed for bot {BotId}", kvp.Key); } } + return Task.CompletedTask; } }