Enhance inbound management by removing MaxClients property
- 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:
+1
-1
@@ -26,7 +26,7 @@ public class ListAllConfigsQueryHandlerTests
|
||||
null
|
||||
);
|
||||
var inbound = Inbound.FromRemote(node.Id, "1", VpnProtocol.Vless, "remark", 443);
|
||||
inbound.Publish("Germany", [], null);
|
||||
inbound.Publish("Germany", []);
|
||||
var config = VpnConfig.Create(userId, inbound.Id, VpnProtocol.Vless, "my-config");
|
||||
|
||||
dbContext.Nodes.Add(node);
|
||||
|
||||
+4
-5
@@ -22,14 +22,13 @@ public class PublishInboundCommandHandlerTests
|
||||
var roleId = Guid.NewGuid();
|
||||
var handler = new PublishInboundCommandHandler(dbContext, _currentUser);
|
||||
|
||||
var command = new PublishInboundCommand(inbound.Id, true, "EU Fast", [roleId], 100);
|
||||
var command = new PublishInboundCommand(inbound.Id, true, "EU Fast", [roleId]);
|
||||
|
||||
var result = await handler.Handle(command, CancellationToken.None);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.True(inbound.IsPublished);
|
||||
Assert.Equal("EU Fast", inbound.DisplayName);
|
||||
Assert.Equal(100, inbound.MaxClients);
|
||||
Assert.Contains(roleId, inbound.AllowedRoleIds);
|
||||
Assert.Equal("EU Fast", result.Value.DisplayName);
|
||||
}
|
||||
@@ -39,13 +38,13 @@ public class PublishInboundCommandHandlerTests
|
||||
{
|
||||
using var dbContext = InMemoryDbContextFactory.Create();
|
||||
var inbound = Inbound.FromRemote(Guid.NewGuid(), "1", VpnProtocol.Vless, "remark", 443);
|
||||
inbound.Publish("EU Fast", [Guid.NewGuid()], 100);
|
||||
inbound.Publish("EU Fast", [Guid.NewGuid()]);
|
||||
dbContext.Inbounds.Add(inbound);
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
var handler = new PublishInboundCommandHandler(dbContext, _currentUser);
|
||||
|
||||
var command = new PublishInboundCommand(inbound.Id, false, null, [], null);
|
||||
var command = new PublishInboundCommand(inbound.Id, false, null, []);
|
||||
|
||||
var result = await handler.Handle(command, CancellationToken.None);
|
||||
|
||||
@@ -60,7 +59,7 @@ public class PublishInboundCommandHandlerTests
|
||||
|
||||
var handler = new PublishInboundCommandHandler(dbContext, _currentUser);
|
||||
|
||||
var command = new PublishInboundCommand(Guid.NewGuid(), true, "EU Fast", [], null);
|
||||
var command = new PublishInboundCommand(Guid.NewGuid(), true, "EU Fast", []);
|
||||
|
||||
var result = await handler.Handle(command, CancellationToken.None);
|
||||
|
||||
|
||||
+12
-4
@@ -1,3 +1,4 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using PnvPanel.Application.Admin.Users;
|
||||
using PnvPanel.Application.Common.Interfaces;
|
||||
@@ -16,6 +17,9 @@ public class DeleteUserCommandHandlerTests
|
||||
private readonly IXuiPanelGateway _gateway = Substitute.For<IXuiPanelGateway>();
|
||||
private readonly ITelegramNotifier _telegramNotifier = Substitute.For<ITelegramNotifier>();
|
||||
private readonly ICurrentUser _currentUser = Substitute.For<ICurrentUser>();
|
||||
private readonly ILogger<DeleteUserCommandHandler> _logger = Substitute.For<
|
||||
ILogger<DeleteUserCommandHandler>
|
||||
>();
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenAdminTargetsSelf_ReturnsCannotDeleteSelfWithoutTouchingConfigs()
|
||||
@@ -29,7 +33,8 @@ public class DeleteUserCommandHandlerTests
|
||||
_identityService,
|
||||
_gateway,
|
||||
_telegramNotifier,
|
||||
_currentUser
|
||||
_currentUser,
|
||||
_logger
|
||||
);
|
||||
|
||||
var result = await handler.Handle(new DeleteUserCommand(adminId), CancellationToken.None);
|
||||
@@ -82,7 +87,8 @@ public class DeleteUserCommandHandlerTests
|
||||
_identityService,
|
||||
_gateway,
|
||||
_telegramNotifier,
|
||||
_currentUser
|
||||
_currentUser,
|
||||
_logger
|
||||
);
|
||||
|
||||
var result = await handler.Handle(new DeleteUserCommand(userId), CancellationToken.None);
|
||||
@@ -125,7 +131,8 @@ public class DeleteUserCommandHandlerTests
|
||||
_identityService,
|
||||
_gateway,
|
||||
_telegramNotifier,
|
||||
_currentUser
|
||||
_currentUser,
|
||||
_logger
|
||||
);
|
||||
|
||||
var result = await handler.Handle(new DeleteUserCommand(userId), CancellationToken.None);
|
||||
@@ -157,7 +164,8 @@ public class DeleteUserCommandHandlerTests
|
||||
_identityService,
|
||||
_gateway,
|
||||
_telegramNotifier,
|
||||
_currentUser
|
||||
_currentUser,
|
||||
_logger
|
||||
);
|
||||
|
||||
var result = await handler.Handle(new DeleteUserCommand(userId), CancellationToken.None);
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ public class GetMyConfigsQueryHandlerTests
|
||||
var otherUserId = Guid.NewGuid();
|
||||
|
||||
var inbound = Inbound.FromRemote(Guid.NewGuid(), "1", VpnProtocol.Vless, "remark", 443);
|
||||
inbound.Publish("My inbound", [], null);
|
||||
inbound.Publish("My inbound", []);
|
||||
|
||||
var activeConfig = VpnConfig.Create(userId, inbound.Id, VpnProtocol.Vless, "Active");
|
||||
var revokedConfig = VpnConfig.Create(userId, inbound.Id, VpnProtocol.Vless, "Revoked");
|
||||
|
||||
+23
-4
@@ -1,5 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using PnvPanel.Application.Common.Interfaces;
|
||||
using PnvPanel.Application.Common.Models;
|
||||
using PnvPanel.Application.Configs;
|
||||
using PnvPanel.Application.Configs.Revoke;
|
||||
using PnvPanel.Application.Tests.TestSupport;
|
||||
@@ -14,6 +16,9 @@ public class RevokeVpnConfigCommandHandlerTests
|
||||
{
|
||||
private readonly IXuiPanelGateway _gateway = Substitute.For<IXuiPanelGateway>();
|
||||
private readonly IRealtimeNotifier _notifier = Substitute.For<IRealtimeNotifier>();
|
||||
private readonly ILogger<RevokeVpnConfigCommandHandler> _logger = Substitute.For<
|
||||
ILogger<RevokeVpnConfigCommandHandler>
|
||||
>();
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenActiveConfigOwnedByUser_RevokesRemovesRemoteClientAndNotifies()
|
||||
@@ -36,11 +41,22 @@ public class RevokeVpnConfigCommandHandlerTests
|
||||
dbContext.VpnConfigs.Add(config);
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
_gateway
|
||||
.RemoveClientAsync(
|
||||
Arg.Any<PnvPanel.Domain.Nodes.Node>(),
|
||||
Arg.Any<string>(),
|
||||
Arg.Any<string>(),
|
||||
Arg.Any<VpnProtocol>(),
|
||||
Arg.Any<CancellationToken>()
|
||||
)
|
||||
.Returns(Result.Success());
|
||||
|
||||
var handler = new RevokeVpnConfigCommandHandler(
|
||||
dbContext,
|
||||
_gateway,
|
||||
_notifier,
|
||||
FakeCurrentUser.Authenticated(userId)
|
||||
FakeCurrentUser.Authenticated(userId),
|
||||
_logger
|
||||
);
|
||||
|
||||
var result = await handler.Handle(
|
||||
@@ -87,7 +103,8 @@ public class RevokeVpnConfigCommandHandlerTests
|
||||
dbContext,
|
||||
_gateway,
|
||||
_notifier,
|
||||
FakeCurrentUser.Authenticated(userId)
|
||||
FakeCurrentUser.Authenticated(userId),
|
||||
_logger
|
||||
);
|
||||
|
||||
var result = await handler.Handle(
|
||||
@@ -117,7 +134,8 @@ public class RevokeVpnConfigCommandHandlerTests
|
||||
dbContext,
|
||||
_gateway,
|
||||
_notifier,
|
||||
FakeCurrentUser.Authenticated(userId)
|
||||
FakeCurrentUser.Authenticated(userId),
|
||||
_logger
|
||||
);
|
||||
|
||||
var result = await handler.Handle(
|
||||
@@ -138,7 +156,8 @@ public class RevokeVpnConfigCommandHandlerTests
|
||||
dbContext,
|
||||
_gateway,
|
||||
_notifier,
|
||||
FakeCurrentUser.Anonymous()
|
||||
FakeCurrentUser.Anonymous(),
|
||||
_logger
|
||||
);
|
||||
|
||||
var result = await handler.Handle(
|
||||
|
||||
Reference in New Issue
Block a user