Enhance inbound management by removing MaxClients property
CI / Backend (build + test) (push) Successful in 1m23s
CI / Frontend (lint + typecheck + build) (push) Successful in 34s

- Removed the MaxClients property from Inbound-related data models, including InboundDto and PublishInboundCommand.
- Updated related methods and handlers to reflect the removal of MaxClients, ensuring consistent behavior across the application.
- Adjusted API documentation and frontend components to remove references to MaxClients, streamlining the inbound publishing process.
- Enhanced logging in command handlers to handle node unavailability scenarios during user actions.
- Improved database schema and migrations to align with the updated data model.
This commit is contained in:
Leonid Pershin
2026-07-14 23:11:50 +03:00
parent bef3880593
commit 8f6807a456
34 changed files with 1150 additions and 77 deletions
@@ -25,4 +25,9 @@ public static class ConfigErrors
);
public static readonly Error NotFound = Error.NotFound("Configs.NotFound", "Конфиг не найден.");
public static readonly Error NodeUnavailable = Error.Failure(
"Configs.NodeUnavailable",
"Сервер временно недоступен. Попробуйте повторить операцию позже."
);
}
@@ -4,6 +4,7 @@ using PnvPanel.Application.Common.Interfaces;
using PnvPanel.Application.Common.Messaging;
using PnvPanel.Application.Common.Models;
using PnvPanel.Domain.Configs;
using PnvPanel.Domain.Nodes;
namespace PnvPanel.Application.Configs.Create;
@@ -39,7 +40,7 @@ public sealed class CreateVpnConfigCommandHandler(
var node = await dbContext
.Nodes.AsNoTracking()
.FirstOrDefaultAsync(n => n.Id == inbound.NodeId, cancellationToken);
if (node is null || !node.IsEnabled)
if (node is null || !node.IsEnabled || node.Status == NodeStatus.Offline)
return Result.Failure<VpnConfigDto>(ConfigErrors.NodeDisabled);
var config = VpnConfig.Create(userId, inbound.Id, inbound.Protocol, command.Label);
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using PnvPanel.Application.Auth;
using PnvPanel.Application.Common.Interfaces;
using PnvPanel.Application.Common.Messaging;
@@ -9,7 +10,8 @@ namespace PnvPanel.Application.Configs.Edit;
public sealed class EditVpnConfigCommandHandler(
IAppDbContext dbContext,
IXuiPanelGateway gateway,
ICurrentUser currentUser
ICurrentUser currentUser,
ILogger<EditVpnConfigCommandHandler> logger
) : ICommandHandler<EditVpnConfigCommand, Result<VpnConfigDto>>
{
public async Task<Result<VpnConfigDto>> Handle(
@@ -35,23 +37,36 @@ public sealed class EditVpnConfigCommandHandler(
if (command.Label is not null)
{
config.Rename(command.Label);
var node = await dbContext
.Nodes.AsNoTracking()
.FirstOrDefaultAsync(n => n.Id == inbound.NodeId, cancellationToken);
if (node is not null)
{
await gateway.UpdateClientAsync(
var updateResult = await gateway.UpdateClientAsync(
node,
inbound.RemoteInboundId,
config.ClientExternalId,
config.Protocol,
config.Label ?? config.ClientEmail,
command.Label,
enable: true,
cancellationToken
);
if (!updateResult.IsSuccess)
{
// Нода недоступна — не переименовываем локально, иначе метка разойдётся
// с тем, что реально хранится в 3x-ui. Пользователь может повторить.
logger.LogWarning(
"Failed to rename client for config {ConfigId} on node {NodeId}: {Error}",
config.Id,
node.Id,
updateResult.Error
);
return Result.Failure<VpnConfigDto>(ConfigErrors.NodeUnavailable);
}
}
config.Rename(command.Label);
}
return Result.Success(VpnConfigDto.FromDomain(config, inbound));
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using PnvPanel.Application.Auth;
using PnvPanel.Application.Common.Interfaces;
using PnvPanel.Application.Common.Messaging;
@@ -11,7 +12,8 @@ public sealed class RevokeVpnConfigCommandHandler(
IAppDbContext dbContext,
IXuiPanelGateway gateway,
IRealtimeNotifier notifier,
ICurrentUser currentUser
ICurrentUser currentUser,
ILogger<RevokeVpnConfigCommandHandler> logger
) : ICommandHandler<RevokeVpnConfigCommand, Result>
{
public async Task<Result> Handle(
@@ -42,7 +44,8 @@ public sealed class RevokeVpnConfigCommandHandler(
.FirstOrDefaultAsync(n => n.Id == inbound.NodeId, cancellationToken);
if (inbound is not null && node is not null)
await gateway.RemoveClientAsync(
{
var removeResult = await gateway.RemoveClientAsync(
node,
inbound.RemoteInboundId,
config.ClientExternalId,
@@ -50,6 +53,20 @@ public sealed class RevokeVpnConfigCommandHandler(
cancellationToken
);
if (!removeResult.IsSuccess)
{
// Нода недоступна/сбой панели — не помечаем конфиг Revoked локально, иначе БД
// разойдётся с реальным состоянием клиента в 3x-ui. Пользователь может повторить.
logger.LogWarning(
"Failed to remove client for config {ConfigId} on node {NodeId}: {Error}",
config.Id,
node.Id,
removeResult.Error
);
return Result.Failure(ConfigErrors.NodeUnavailable);
}
}
config.Revoke();
await notifier.NotifyConfigStatusChangedAsync(
userId,