- 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.
158 lines
4.7 KiB
C#
158 lines
4.7 KiB
C#
using PnvPanel.Api.Common;
|
|
using PnvPanel.Application.Admin.Configs;
|
|
using PnvPanel.Application.Admin.Users;
|
|
using PnvPanel.Application.Common.Interfaces;
|
|
using PnvPanel.Application.Common.Messaging;
|
|
using PnvPanel.Application.Common.Models;
|
|
using PnvPanel.Application.Configs;
|
|
using PnvPanel.Domain.Configs;
|
|
using PnvPanel.Domain.Inbounds;
|
|
using PnvPanel.Infrastructure.Identity;
|
|
|
|
namespace PnvPanel.Api.Endpoints;
|
|
|
|
public static class AdminUserEndpoints
|
|
{
|
|
public static IEndpointRouteBuilder MapAdminUserEndpoints(this IEndpointRouteBuilder app)
|
|
{
|
|
var admin = app.MapGroup("/api/admin")
|
|
.WithTags("Admin.Users")
|
|
.RequireAuthorization(policy => policy.RequireRole(RoleNames.Admin));
|
|
|
|
admin.MapGet("/users", ListUsers).Produces<PagedList<UserSummaryDto>>();
|
|
admin
|
|
.MapPatch("/users/{id:guid}/block", BlockUser)
|
|
.Produces(StatusCodes.Status204NoContent);
|
|
admin
|
|
.MapPatch("/users/{id:guid}/unblock", UnblockUser)
|
|
.Produces(StatusCodes.Status204NoContent);
|
|
admin
|
|
.MapPost("/users/{id:guid}/reset-password", ResetPassword)
|
|
.Produces(StatusCodes.Status204NoContent);
|
|
admin.MapDelete("/users/{id:guid}", DeleteUser).Produces(StatusCodes.Status204NoContent);
|
|
admin
|
|
.MapGet("/users/{id:guid}/configs", GetUserConfigs)
|
|
.Produces<IReadOnlyList<VpnConfigDto>>();
|
|
admin.MapGet("/configs", ListAllConfigs).Produces<PagedList<AdminVpnConfigDto>>();
|
|
admin
|
|
.MapDelete("/configs/{id:guid}", ForceRevokeConfig)
|
|
.Produces(StatusCodes.Status204NoContent);
|
|
|
|
return app;
|
|
}
|
|
|
|
private static async Task<IResult> ListUsers(
|
|
int page,
|
|
int pageSize,
|
|
string? search,
|
|
Guid? roleId,
|
|
bool? isActivated,
|
|
bool? isBlocked,
|
|
bool? billingExpired,
|
|
ISender sender,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var query = new ListUsersQuery(
|
|
page <= 0 ? 1 : page,
|
|
pageSize <= 0 ? 20 : pageSize,
|
|
search,
|
|
roleId,
|
|
isActivated,
|
|
isBlocked,
|
|
billingExpired
|
|
);
|
|
var result = await sender.Send(query, cancellationToken);
|
|
return result.ToHttpResult();
|
|
}
|
|
|
|
private static async Task<IResult> BlockUser(
|
|
Guid id,
|
|
ISender sender,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var result = await sender.Send(new BlockUserCommand(id), cancellationToken);
|
|
return result.ToHttpResult();
|
|
}
|
|
|
|
private static async Task<IResult> UnblockUser(
|
|
Guid id,
|
|
ISender sender,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var result = await sender.Send(new UnblockUserCommand(id), cancellationToken);
|
|
return result.ToHttpResult();
|
|
}
|
|
|
|
private static async Task<IResult> ResetPassword(
|
|
Guid id,
|
|
ResetPasswordBody body,
|
|
ISender sender,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var result = await sender.Send(
|
|
new ResetUserPasswordCommand(id, body.NewPassword),
|
|
cancellationToken
|
|
);
|
|
return result.ToHttpResult();
|
|
}
|
|
|
|
private static async Task<IResult> DeleteUser(
|
|
Guid id,
|
|
ISender sender,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var result = await sender.Send(new DeleteUserCommand(id), cancellationToken);
|
|
return result.ToHttpResult();
|
|
}
|
|
|
|
private static async Task<IResult> GetUserConfigs(
|
|
Guid id,
|
|
ISender sender,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var result = await sender.Send(new GetUserConfigsQuery(id), cancellationToken);
|
|
return result.ToHttpResult();
|
|
}
|
|
|
|
private static async Task<IResult> ListAllConfigs(
|
|
int page,
|
|
int pageSize,
|
|
string? search,
|
|
ConfigStatus? status,
|
|
VpnProtocol? protocol,
|
|
Guid? nodeId,
|
|
ISender sender,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var query = new ListAllConfigsQuery(
|
|
page <= 0 ? 1 : page,
|
|
pageSize <= 0 ? 20 : pageSize,
|
|
search,
|
|
status,
|
|
protocol,
|
|
nodeId
|
|
);
|
|
var result = await sender.Send(query, cancellationToken);
|
|
return result.ToHttpResult();
|
|
}
|
|
|
|
private static async Task<IResult> ForceRevokeConfig(
|
|
Guid id,
|
|
ISender sender,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var result = await sender.Send(new ForceRevokeConfigCommand(id), cancellationToken);
|
|
return result.ToHttpResult();
|
|
}
|
|
}
|
|
|
|
public sealed record ResetPasswordBody(string NewPassword);
|