Add admin configs endpoint and related UI components
CI / Backend (build + test) (push) Successful in 1m17s
CI / Frontend (lint + typecheck + build) (push) Successful in 32s

- Introduced a new endpoint to list all admin configs, enhancing the admin interface for better management.
- Updated API documentation to include the new `/configs` endpoint with pagination and search capabilities.
- Added routing and UI elements for the configs section in the admin panel, improving navigation and accessibility.
- Enhanced localization for the configs feature in both Russian and English, ensuring a user-friendly experience.
This commit is contained in:
Leonid Pershin
2026-07-13 16:08:50 +03:00
parent 7fce5ef181
commit 39a8b30b03
12 changed files with 442 additions and 0 deletions
@@ -0,0 +1,105 @@
using NSubstitute;
using PnvPanel.Application.Admin.Configs;
using PnvPanel.Application.Common.Interfaces;
using PnvPanel.Application.Tests.TestSupport;
using PnvPanel.Domain.Configs;
using PnvPanel.Domain.Inbounds;
using PnvPanel.Domain.Nodes;
using Xunit;
namespace PnvPanel.Application.Tests.Admin.Configs;
public class ListAllConfigsQueryHandlerTests
{
private readonly IIdentityService _identityService = Substitute.For<IIdentityService>();
[Fact]
public async Task Handle_ReturnsConfigsAcrossUsersWithOwnerNodeAndUserName()
{
using var dbContext = InMemoryDbContextFactory.Create();
var userId = Guid.NewGuid();
var node = Node.Register("node-1", new Uri("https://node1.example.com"), new NodeCredentials("admin", "protected"), null);
var inbound = Inbound.FromRemote(node.Id, "1", VpnProtocol.Vless, "remark", 443);
inbound.Publish("Germany", [], null);
var config = VpnConfig.Create(userId, inbound.Id, VpnProtocol.Vless, "my-config");
dbContext.Nodes.Add(node);
dbContext.Inbounds.Add(inbound);
dbContext.VpnConfigs.Add(config);
await dbContext.SaveChangesAsync(CancellationToken.None);
_identityService.GetUserNamesAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
.Returns(new Dictionary<Guid, string> { [userId] = "alice" });
var handler = new ListAllConfigsQueryHandler(dbContext, _identityService);
var result = await handler.Handle(new ListAllConfigsQuery(1, 20, Search: null, Status: null), CancellationToken.None);
Assert.True(result.IsSuccess);
var item = Assert.Single(result.Value.Items);
Assert.Equal(config.Id, item.Id);
Assert.Equal(userId, item.UserId);
Assert.Equal("alice", item.UserName);
Assert.Equal("node-1", item.NodeName);
Assert.Equal("Germany", item.Location);
Assert.Equal(1, result.Value.Total);
}
[Fact]
public async Task Handle_FiltersBySearchAcrossClientEmailAndLabel()
{
using var dbContext = InMemoryDbContextFactory.Create();
var userId = Guid.NewGuid();
var node = Node.Register("node-1", new Uri("https://node1.example.com"), new NodeCredentials("admin", "protected"), null);
var inbound = Inbound.FromRemote(node.Id, "1", VpnProtocol.Vless, "remark", 443);
var matching = VpnConfig.Create(userId, inbound.Id, VpnProtocol.Vless, "phone-config");
var other = VpnConfig.Create(userId, inbound.Id, VpnProtocol.Vless, "laptop-config");
dbContext.Nodes.Add(node);
dbContext.Inbounds.Add(inbound);
dbContext.VpnConfigs.AddRange(matching, other);
await dbContext.SaveChangesAsync(CancellationToken.None);
_identityService.GetUserNamesAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
.Returns(new Dictionary<Guid, string> { [userId] = "alice" });
var handler = new ListAllConfigsQueryHandler(dbContext, _identityService);
var result = await handler.Handle(new ListAllConfigsQuery(1, 20, Search: "phone", Status: null), CancellationToken.None);
Assert.True(result.IsSuccess);
var item = Assert.Single(result.Value.Items);
Assert.Equal(matching.Id, item.Id);
}
[Fact]
public async Task Handle_FiltersByStatus()
{
using var dbContext = InMemoryDbContextFactory.Create();
var userId = Guid.NewGuid();
var node = Node.Register("node-1", new Uri("https://node1.example.com"), new NodeCredentials("admin", "protected"), null);
var inbound = Inbound.FromRemote(node.Id, "1", VpnProtocol.Vless, "remark", 443);
var active = VpnConfig.Create(userId, inbound.Id, VpnProtocol.Vless, "active-config");
var revoked = VpnConfig.Create(userId, inbound.Id, VpnProtocol.Vless, "revoked-config");
revoked.Revoke();
dbContext.Nodes.Add(node);
dbContext.Inbounds.Add(inbound);
dbContext.VpnConfigs.AddRange(active, revoked);
await dbContext.SaveChangesAsync(CancellationToken.None);
_identityService.GetUserNamesAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
.Returns(new Dictionary<Guid, string> { [userId] = "alice" });
var handler = new ListAllConfigsQueryHandler(dbContext, _identityService);
var result = await handler.Handle(new ListAllConfigsQuery(1, 20, Search: null, Status: ConfigStatus.Revoked), CancellationToken.None);
Assert.True(result.IsSuccess);
var item = Assert.Single(result.Value.Items);
Assert.Equal(revoked.Id, item.Id);
}
}