feat(security): enforcement — filtrage caméra dans les endpoints sensibles (#175)
This commit is contained in:
1 parent
0f47236c08
commit
b97d3bec11
24 files changed
+313
-25
No files matched your search
@@ -27,6 +27,7 @@ public class AppDbContext : IdentityDbContext<AppUser, AppRole, Guid>, IApplicat
|
||||
public DbSet<Camera> Cameras => Set<Camera>();
|
||||
public DbSet<CameraCredentials> CameraCredentials => Set<CameraCredentials>();
|
||||
public DbSet<CameraDetectionProfile> CameraDetectionProfiles => Set<CameraDetectionProfile>();
|
||||
public DbSet<UserCamera> UserCameras => Set<UserCamera>();
|
||||
public DbSet<UserSite> UserSites => Set<UserSite>();
|
||||
public DbSet<ApiKey> ApiKeys => Set<ApiKey>();
|
||||
public DbSet<AuditLog> AuditLogs => Set<AuditLog>();
|
||||
@@ -93,6 +94,7 @@ public class AppDbContext : IdentityDbContext<AppUser, AppRole, Guid>, IApplicat
|
||||
builder.Entity<CameraCredentials>().HasQueryFilter(e => e.Camera == null || !e.Camera.IsDeleted);
|
||||
builder.Entity<CameraDetectionProfile>().HasQueryFilter(e => e.Camera == null || !e.Camera.IsDeleted);
|
||||
builder.Entity<UserSite>().HasQueryFilter(e => e.Site == null || !e.Site.IsDeleted);
|
||||
builder.Entity<UserCamera>().HasQueryFilter(e => e.Camera == null || !e.Camera.IsDeleted);
|
||||
|
||||
// Matching query filters for dependent entities sharing required
|
||||
// navigations to soft-deletable entities. These prevent EF Core
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class UserCameraConfiguration : IEntityTypeConfiguration<UserCamera>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<UserCamera> builder)
|
||||
{
|
||||
builder.ToTable("user_cameras");
|
||||
|
||||
builder.HasKey(uc => new { uc.UserId, uc.CameraId });
|
||||
|
||||
builder.HasOne(uc => uc.User)
|
||||
.WithMany()
|
||||
.HasForeignKey(uc => uc.UserId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasOne(uc => uc.Camera)
|
||||
.WithMany()
|
||||
.HasForeignKey(uc => uc.CameraId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
// Index for "find all cameras for a user" queries
|
||||
builder.HasIndex(uc => uc.UserId);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user