fix(audit): capture actors for group mutations
Heimdall Gitea / Build and tests (pull_request) Successful in 27m15s
Heimdall Gitea / Publish versioned release (pull_request) Skipped

This commit is contained in:
Arnaud Dartois committed 2026-10-21 14:33:00 +02:00
1 parent 38ab3146e1
commit 4c180827d6
13 files changed
+83 -38

No files matched your search

@@ -3,12 +3,14 @@ using Heimdall.Application.DTOs;
using Heimdall.Domain.Entities;
using MediatR;
using Microsoft.EntityFrameworkCore;
using System.Text.Json;
namespace Heimdall.Application.Groups.Commands.AddCameraToGroup;
public record AddCameraToGroupCommand(
Guid GroupId,
Guid CameraId) : IRequest<ServiceResult<GroupCameraAccessResponse>>;
Guid CameraId,
Guid? ActorId = null) : IRequest<ServiceResult<GroupCameraAccessResponse>>;
public class AddCameraToGroupHandler : IRequestHandler<AddCameraToGroupCommand, ServiceResult<GroupCameraAccessResponse>>
{
@@ -45,8 +47,8 @@ public class AddCameraToGroupHandler : IRequestHandler<AddCameraToGroupCommand,
var access = new GroupCameraAccess(request.GroupId, request.CameraId);
_db.GroupCameraAccesses.Add(access);
_db.AuditLogs.Add(new AuditLog(null, "GroupCameraAccess Granted", "GroupCameraAccess", access.Id.ToString(),
newValue: $"Group {group.Name} granted access to camera {camera.Name}"));
_db.AuditLogs.Add(new AuditLog(request.ActorId, "GroupCameraAccess.Granted", "GroupCameraAccess", access.Id.ToString(),
newValue: JsonSerializer.Serialize(new { access.GroupId, access.CameraId, GroupName = group.Name, CameraName = camera.Name })));
await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false);
@@ -55,4 +57,4 @@ public class AddCameraToGroupHandler : IRequestHandler<AddCameraToGroupCommand,
private static GroupCameraAccessResponse Map(GroupCameraAccess a) => new(
a.Id, a.GroupId, a.CameraId, a.CreatedAt);
}
}