Make isAdmin async

This commit is contained in:
2025-11-08 02:08:19 +07:00
parent be784a026a
commit ca705d5b76
5 changed files with 10 additions and 10 deletions

View File

@@ -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)

View File

@@ -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)
{

View File

@@ -220,7 +220,7 @@ public class TradingController : BaseController
private async Task<bool> 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;

View File

@@ -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

View File

@@ -7,7 +7,7 @@ namespace Managing.Application.Shared;
public interface IAdminConfigurationService
{
bool IsUserAdmin(string userName);
Task<bool> IsUserAdminAsync(string userName);
List<string> GetAdminUserNames();
}
@@ -27,7 +27,7 @@ public class AdminConfigurationService : IAdminConfigurationService
_serviceScopeFactory = serviceScopeFactory;
}
public bool IsUserAdmin(string userName)
public async Task<bool> 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<IUserRepository>();
var user = userRepository.GetUserByNameAsync(userName).GetAwaiter().GetResult();
var user = await userRepository.GetUserByNameAsync(userName);
if (user != null && user.IsAdmin)
{