| | | 1 | | using ArturRios.Heimdall.Domain.Enums; |
| | | 2 | | using ArturRios.Heimdall.Query.Input; |
| | | 3 | | using ArturRios.Heimdall.Query.Output; |
| | | 4 | | using ArturRios.Heimdall.Shared.Messages; |
| | | 5 | | using ArturRios.Heimdall.WebApi.Security; |
| | | 6 | | using ArturRios.Mediator.Query; |
| | | 7 | | using ArturRios.Output; |
| | | 8 | | using ArturRios.Util.WebApi.AspNetCore; |
| | | 9 | | using ArturRios.Util.WebApi.Security.Attributes; |
| | | 10 | | using Microsoft.AspNetCore.Mvc; |
| | | 11 | | |
| | | 12 | | namespace ArturRios.Heimdall.WebApi.Controllers; |
| | | 13 | | |
| | | 14 | | [Route("api/audit-log")] |
| | 20 | 15 | | public class AuditController(QueryMediator queryMediator) : Controller |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Lists the audit trail (UC-48, FR-AT-01/02), newest first. System Admin only. Every filter is |
| | | 19 | | /// optional and they combine: <c>from</c>/<c>to</c> bound when an entry was recorded (UTC, |
| | | 20 | | /// inclusive), <c>actorId</c> and <c>targetId</c> are public ids, <c>action</c> is the exact |
| | | 21 | | /// command type name (e.g. <c>CreateScopeCommand</c>), and <c>succeeded=false</c> lists only |
| | | 22 | | /// refusals. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <remarks> |
| | | 25 | | /// Entries are shown as stored. An actor the retention pass has cleared (NFR-21) is |
| | | 26 | | /// <c>null</c> and is never reconstructed, so filtering by <c>actorId</c> cannot find entries |
| | | 27 | | /// whose attribution has been cleared. A Scope Admin is refused: the trail has no scope |
| | | 28 | | /// column, and an old entry's target may be gone, so it cannot be divided by scope reliably. |
| | | 29 | | /// Reading the trail is not itself audited. |
| | | 30 | | /// </remarks> |
| | | 31 | | [HttpGet] |
| | | 32 | | [RoleRequirement((int)Roles.SystemAdmin)] |
| | | 33 | | public async Task<ActionResult<PaginatedOutput<AuditLogEntryOutput>>> List([FromQuery] ListAuditLogQuery query) |
| | | 34 | | { |
| | 17 | 35 | | HttpContext.ApplyActor(query); |
| | | 36 | | |
| | 17 | 37 | | var result = await queryMediator |
| | 17 | 38 | | .ExecutePaginatedQueryAsync<ListAuditLogQuery, AuditLogEntryOutput>(query); |
| | | 39 | | |
| | 17 | 40 | | return result.ToActionResult(statusMap: AuditMessageMap.StatusCodes); |
| | 17 | 41 | | } |
| | | 42 | | } |