diff --git a/src/Managing.Api/Controllers/BotController.cs b/src/Managing.Api/Controllers/BotController.cs index c08628ab..181d7a23 100644 --- a/src/Managing.Api/Controllers/BotController.cs +++ b/src/Managing.Api/Controllers/BotController.cs @@ -87,7 +87,7 @@ public class BotController : BaseController return false; // Admin users can access all bots - if (_adminService.IsUserAdmin(user.Name)) + if (await _adminService.IsUserAdminAsync(user.Name)) return true; if (identifier != default) diff --git a/src/Managing.Api/Controllers/SqlMonitoringController.cs b/src/Managing.Api/Controllers/SqlMonitoringController.cs index d5756e3d..193599c8 100644 --- a/src/Managing.Api/Controllers/SqlMonitoringController.cs +++ b/src/Managing.Api/Controllers/SqlMonitoringController.cs @@ -46,7 +46,7 @@ public class SqlMonitoringController : BaseController if (user == null) return false; - return _adminService.IsUserAdmin(user.Name); + return await _adminService.IsUserAdminAsync(user.Name); } catch (Exception ex) { diff --git a/src/Managing.Api/Controllers/TradingController.cs b/src/Managing.Api/Controllers/TradingController.cs index 95a3ee17..c7512330 100644 --- a/src/Managing.Api/Controllers/TradingController.cs +++ b/src/Managing.Api/Controllers/TradingController.cs @@ -220,7 +220,7 @@ public class TradingController : BaseController private async Task CanUserInitializeAddress(string userName, string publicAddress) { // Admin users can initialize any address - if (_adminService.IsUserAdmin(userName)) + if (await _adminService.IsUserAdminAsync(userName)) { _logger.LogInformation("Admin user {UserName} initializing address {Address}", userName, publicAddress); return true; diff --git a/src/Managing.Api/Controllers/WhitelistController.cs b/src/Managing.Api/Controllers/WhitelistController.cs index ad4b23e1..3631993c 100644 --- a/src/Managing.Api/Controllers/WhitelistController.cs +++ b/src/Managing.Api/Controllers/WhitelistController.cs @@ -49,10 +49,10 @@ public class WhitelistController : BaseController { var user = await GetUser(); - if (!_adminService.IsUserAdmin(user.Name)) + if (!await _adminService.IsUserAdminAsync(user.Name)) { _logger.LogWarning("User {UserName} attempted to list whitelist accounts without admin privileges", user.Name); - return Forbid("Only admin users can list whitelist accounts"); + return StatusCode(403, new { error = "Only admin users can list whitelist accounts" }); } try @@ -89,10 +89,10 @@ public class WhitelistController : BaseController { var user = await GetUser(); - if (!_adminService.IsUserAdmin(user.Name)) + if (!await _adminService.IsUserAdminAsync(user.Name)) { _logger.LogWarning("User {UserName} attempted to set whitelisted status without admin privileges", user.Name); - return Forbid("Only admin users can set whitelisted status"); + return StatusCode(403, new { error = "Only admin users can set whitelisted status" }); } try diff --git a/src/Managing.Application/Shared/AdminConfigurationService.cs b/src/Managing.Application/Shared/AdminConfigurationService.cs index b850ec14..8e678634 100644 --- a/src/Managing.Application/Shared/AdminConfigurationService.cs +++ b/src/Managing.Application/Shared/AdminConfigurationService.cs @@ -7,7 +7,7 @@ namespace Managing.Application.Shared; public interface IAdminConfigurationService { - bool IsUserAdmin(string userName); + Task IsUserAdminAsync(string userName); List GetAdminUserNames(); } @@ -27,7 +27,7 @@ public class AdminConfigurationService : IAdminConfigurationService _serviceScopeFactory = serviceScopeFactory; } - public bool IsUserAdmin(string userName) + public async Task IsUserAdminAsync(string userName) { if (string.IsNullOrEmpty(userName)) { @@ -50,7 +50,7 @@ public class AdminConfigurationService : IAdminConfigurationService using var scope = _serviceScopeFactory.CreateScope(); var userRepository = scope.ServiceProvider.GetRequiredService(); - var user = userRepository.GetUserByNameAsync(userName).GetAwaiter().GetResult(); + var user = await userRepository.GetUserByNameAsync(userName); if (user != null && user.IsAdmin) {