Enhance admin maintenance functionality with new endpoints and response types
CI / Backend (build + test) (push) Successful in 1m17s
CI / Frontend (lint + typecheck + build) (push) Successful in 33s

- Added new DELETE endpoints for managing audit logs and disabled apps in the admin maintenance section.
- Updated existing endpoint for closed tickets to use a unified response type, `MaintenanceCleanupResponseDto`.
- Enhanced API documentation to reflect the new operations and their expected request/response formats.
- Improved frontend integration with new functions for deleting old audit logs and disabled apps, including user confirmation prompts.
- Added localization support for new maintenance actions in both Russian and English.
This commit is contained in:
Leonid Pershin
2026-07-14 18:37:22 +03:00
parent 8dfeb05912
commit 94ba514b8e
15 changed files with 449 additions and 15 deletions
@@ -0,0 +1,72 @@
using PnvPanel.Application.Admin.Maintenance;
using PnvPanel.Application.Tests.TestSupport;
using PnvPanel.Domain.Audit;
using Xunit;
namespace PnvPanel.Application.Tests.Admin.Maintenance;
public class DeleteOldAuditLogsCommandHandlerTests
{
[Fact]
public async Task Handle_DeletesOldLogs_KeepsItsOwnCleanupEntry()
{
using var dbContext = InMemoryDbContextFactory.Create();
var oldLog = AuditLog.Create(
Guid.NewGuid(),
"OldAction",
"Test",
"1",
null,
AuditSource.Web
);
dbContext.AuditLogs.Add(oldLog);
await dbContext.SaveChangesAsync(CancellationToken.None);
// Гарантируем, что порог (UtcNow внутри хендлера) окажется позже CreatedAt старой записи.
await Task.Delay(5, CancellationToken.None);
var currentUser = FakeCurrentUser.Authenticated(Guid.NewGuid(), "admin");
var handler = new DeleteOldAuditLogsCommandHandler(dbContext, currentUser);
var result = await handler.Handle(
new DeleteOldAuditLogsCommand(OlderThanDays: 0),
CancellationToken.None
);
// Хендлер не коммитит сам (в проде это делает UnitOfWorkBehavior после диспетчера) — коммитим явно.
await dbContext.SaveChangesAsync(CancellationToken.None);
Assert.True(result.IsSuccess);
Assert.Equal(1, result.Value);
Assert.False(dbContext.AuditLogs.Any(l => l.Id == oldLog.Id));
// Собственная запись об очистке создаётся уже после выборки порога и не попадает под удаление.
Assert.True(dbContext.AuditLogs.Any(l => l.Action == "AuditLogsCleanedUp"));
}
[Fact]
public async Task Handle_WhenNothingOlderThanThreshold_ReturnsZero()
{
using var dbContext = InMemoryDbContextFactory.Create();
var recentLog = AuditLog.Create(
Guid.NewGuid(),
"RecentAction",
"Test",
"1",
null,
AuditSource.Web
);
dbContext.AuditLogs.Add(recentLog);
await dbContext.SaveChangesAsync(CancellationToken.None);
var currentUser = FakeCurrentUser.Authenticated(Guid.NewGuid(), "admin");
var handler = new DeleteOldAuditLogsCommandHandler(dbContext, currentUser);
var result = await handler.Handle(
new DeleteOldAuditLogsCommand(OlderThanDays: 36500),
CancellationToken.None
);
Assert.True(result.IsSuccess);
Assert.Equal(0, result.Value);
Assert.True(dbContext.AuditLogs.Any(l => l.Id == recentLog.Id));
}
}