Enhance admin endpoints and queries for improved filtering and management
- Updated `ListPaymentRequestsQuery` to include `Kind` and `Search` parameters for better filtering of payment requests. - Enhanced `ListAuditLogsQuery` to support additional filters: `Source`, `TargetType`, and `Action`, improving audit log retrieval. - Modified `ListUsersQuery` to accept new filters: `RoleId`, `IsActivated`, `IsBlocked`, and `BillingExpired`, allowing for more granular user management. - Introduced `DeleteInbound` endpoint to allow deletion of inbounds that are not currently available, enhancing inbound management capabilities. - Updated frontend API calls to reflect new query parameters and support for additional filtering options in the admin interface. - Revised API documentation to include new parameters and endpoint functionalities for better clarity and usage guidance.
This commit is contained in:
+84
-3
@@ -41,7 +41,7 @@ public class ListAllConfigsQueryHandlerTests
|
||||
var handler = new ListAllConfigsQueryHandler(dbContext, _identityService);
|
||||
|
||||
var result = await handler.Handle(
|
||||
new ListAllConfigsQuery(1, 20, Search: null, Status: null),
|
||||
new ListAllConfigsQuery(1, 20, Search: null, Status: null, Protocol: null, NodeId: null),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
@@ -83,7 +83,7 @@ public class ListAllConfigsQueryHandlerTests
|
||||
var handler = new ListAllConfigsQueryHandler(dbContext, _identityService);
|
||||
|
||||
var result = await handler.Handle(
|
||||
new ListAllConfigsQuery(1, 20, Search: "phone", Status: null),
|
||||
new ListAllConfigsQuery(1, 20, Search: "phone", Status: null, Protocol: null, NodeId: null),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
@@ -121,7 +121,7 @@ public class ListAllConfigsQueryHandlerTests
|
||||
var handler = new ListAllConfigsQueryHandler(dbContext, _identityService);
|
||||
|
||||
var result = await handler.Handle(
|
||||
new ListAllConfigsQuery(1, 20, Search: null, Status: ConfigStatus.Revoked),
|
||||
new ListAllConfigsQuery(1, 20, Search: null, Status: ConfigStatus.Revoked, Protocol: null, NodeId: null),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
@@ -129,4 +129,85 @@ public class ListAllConfigsQueryHandlerTests
|
||||
var item = Assert.Single(result.Value.Items);
|
||||
Assert.Equal(revoked.Id, item.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_FiltersByProtocol()
|
||||
{
|
||||
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 vless = VpnConfig.Create(userId, inbound.Id, VpnProtocol.Vless, "vless-config");
|
||||
var trojan = VpnConfig.Create(userId, inbound.Id, VpnProtocol.Trojan, "trojan-config");
|
||||
|
||||
dbContext.Nodes.Add(node);
|
||||
dbContext.Inbounds.Add(inbound);
|
||||
dbContext.VpnConfigs.AddRange(vless, trojan);
|
||||
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, Protocol: VpnProtocol.Trojan, NodeId: null),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
var item = Assert.Single(result.Value.Items);
|
||||
Assert.Equal(trojan.Id, item.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_FiltersByNodeId()
|
||||
{
|
||||
using var dbContext = InMemoryDbContextFactory.Create();
|
||||
var userId = Guid.NewGuid();
|
||||
|
||||
var nodeA = Node.Register(
|
||||
"node-a",
|
||||
new Uri("https://node-a.example.com"),
|
||||
new NodeCredentials("admin", "protected"),
|
||||
null
|
||||
);
|
||||
var nodeB = Node.Register(
|
||||
"node-b",
|
||||
new Uri("https://node-b.example.com"),
|
||||
new NodeCredentials("admin", "protected"),
|
||||
null
|
||||
);
|
||||
var inboundA = Inbound.FromRemote(nodeA.Id, "1", VpnProtocol.Vless, "remark", 443);
|
||||
var inboundB = Inbound.FromRemote(nodeB.Id, "1", VpnProtocol.Vless, "remark", 443);
|
||||
var configA = VpnConfig.Create(userId, inboundA.Id, VpnProtocol.Vless, "config-a");
|
||||
var configB = VpnConfig.Create(userId, inboundB.Id, VpnProtocol.Vless, "config-b");
|
||||
|
||||
dbContext.Nodes.AddRange(nodeA, nodeB);
|
||||
dbContext.Inbounds.AddRange(inboundA, inboundB);
|
||||
dbContext.VpnConfigs.AddRange(configA, configB);
|
||||
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, Protocol: null, NodeId: nodeB.Id),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
var item = Assert.Single(result.Value.Items);
|
||||
Assert.Equal(configB.Id, item.Id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user