Add Admin roles

This commit is contained in:
2025-08-16 06:06:02 +07:00
parent 7923b38a26
commit 4ff2ccdae3
7 changed files with 332 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ using Managing.Application.Abstractions;
using Managing.Application.Abstractions.Services;
using Managing.Application.Hubs;
using Managing.Application.ManageBot.Commands;
using Managing.Application.Shared;
using Managing.Common;
using Managing.Core;
using Managing.Domain.Accounts;
@@ -40,6 +41,7 @@ public class BotController : BaseController
private readonly IAccountService _accountService;
private readonly IMoneyManagementService _moneyManagementService;
private readonly IServiceScopeFactory _scopeFactory;
private readonly IAdminConfigurationService _adminService;
/// <summary>
/// Initializes a new instance of the <see cref="BotController"/> class.
@@ -56,7 +58,7 @@ public class BotController : BaseController
public BotController(ILogger<BotController> logger, IMediator mediator, IHubContext<BotHub> hubContext,
IBacktester backtester, IBotService botService, IUserService userService,
IAccountService accountService, IMoneyManagementService moneyManagementService,
IServiceScopeFactory scopeFactory) : base(userService)
IServiceScopeFactory scopeFactory, IAdminConfigurationService adminService) : base(userService)
{
_logger = logger;
_mediator = mediator;
@@ -66,6 +68,7 @@ public class BotController : BaseController
_accountService = accountService;
_moneyManagementService = moneyManagementService;
_scopeFactory = scopeFactory;
_adminService = adminService;
}
/// <summary>
@@ -73,7 +76,7 @@ public class BotController : BaseController
/// </summary>
/// <param name="identifier">The identifier of the bot to check</param>
/// <param name="accountName">Optional account name to check when creating a new bot</param>
/// <returns>True if the user owns the account, False otherwise</returns>
/// <returns>True if the user owns the account or is admin, False otherwise</returns>
private async Task<bool> UserOwnsBotAccount(Guid identifier, string accountName = null)
{
try
@@ -82,6 +85,9 @@ public class BotController : BaseController
if (user == null)
return false;
// Admin users can access all bots
if (_adminService.IsUserAdmin(user.Name))
return true;
if (identifier != default)
{