From dc8a24918d78fcbb4604e935bde2541f97852fa0 Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Wed, 12 Aug 2026 12:18:52 +0200 Subject: [PATCH] feat(settings): topic ntfy par site, SMTP/ntfy/S3 globaux, DSN GlitchTip fixe + toggle (Fixes #105 #106 #107 #108) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #105 — Topic ntfy cible par site : - Site.NtfyTopic (migration AddSiteNtfyTopic), UI création/édition SitesPage - NotificationService.ResolveNtfyTopicAsync : topic du site sinon heimdall_{userId} #106 — Paramètres SMTP/ntfy/S3 GLOBAUX : - Seed + sections UI : agentScoped=false pour ntfy.*/email.*/storage.*/sentry.* - Migration douce au démarrage : UPDATE des clés existantes en base #107 — GlitchTip : DSN fixes (central projet 6, agent projet 7) dans appsettings, - plus de champ DSN éditable en UI → switch sentry.enabled (nécessite redémarrage) - Init Sentry déplacé après AddInfrastructure, lit sentry.enabled en base (fallback true) #108 — Composants typés : MudNumericField borné (port SMTP, rétention, heartbeat), - switch pour booléens, select pour log.level — pas de saisie libre --- src/Heimdall.Agent/appsettings.json | 2 +- src/Heimdall.Application/DTOs/SiteDto.cs | 1 + .../Commands/CreateSite/CreateSiteCommand.cs | 2 +- .../Commands/CreateSite/CreateSiteHandler.cs | 2 +- .../Commands/UpdateSite/UpdateSiteCommand.cs | 2 +- .../Commands/UpdateSite/UpdateSiteHandler.cs | 4 +- .../Sites/Queries/GetSite/GetSiteHandler.cs | 2 +- .../Sites/Queries/GetSites/GetSitesHandler.cs | 2 +- src/Heimdall.Domain/Entities/Site.cs | 9 +- ...0260812101327_AddSiteNtfyTopic.Designer.cs | 2217 +++++++++++++++++ .../20260812101327_AddSiteNtfyTopic.cs | 28 + .../Migrations/AppDbContextModelSnapshot.cs | 3 + .../Services/NotificationService.cs | 22 +- .../Components/Pages/SitesPage.razor | 12 +- .../Settings/AgentDefaultsSection.razor | 44 +- .../NotificationSettingsSection.razor | 11 +- .../Settings/StorageSettingsSection.razor | 2 +- src/Heimdall.Web/Program.cs | 216 +- src/Heimdall.Web/Services/AuthState.cs | 1 + .../Services/HeimdallApiClient.cs | 8 +- src/Heimdall.Web/appsettings.json | 2 +- .../Components/Pages/DashboardTests.cs | 2 +- .../Components/Pages/SiteDetailTests.cs | 16 +- .../Components/Pages/SitesPageTests.cs | 2 +- .../Settings/AgentDefaultsSectionTests.cs | 26 +- 25 files changed, 2485 insertions(+), 153 deletions(-) create mode 100644 src/Heimdall.Infrastructure/Migrations/20260812101327_AddSiteNtfyTopic.Designer.cs create mode 100644 src/Heimdall.Infrastructure/Migrations/20260812101327_AddSiteNtfyTopic.cs diff --git a/src/Heimdall.Agent/appsettings.json b/src/Heimdall.Agent/appsettings.json index dd48445..eec813e 100644 --- a/src/Heimdall.Agent/appsettings.json +++ b/src/Heimdall.Agent/appsettings.json @@ -15,6 +15,6 @@ // Sentry/GlitchTip — DSN is read from Sentry:Dsn (or env Sentry__Dsn / legacy SENTRY_DSN) // When null/empty, Sentry SDK is not initialized (graceful no-op). "Sentry": { - "Dsn": "" + "Dsn": "https://5ff158606c674ba8bb59c1b11d2aa04a@glitchtip.tordais.cc/7" } } diff --git a/src/Heimdall.Application/DTOs/SiteDto.cs b/src/Heimdall.Application/DTOs/SiteDto.cs index a5c4e33..fa24ef6 100644 --- a/src/Heimdall.Application/DTOs/SiteDto.cs +++ b/src/Heimdall.Application/DTOs/SiteDto.cs @@ -9,6 +9,7 @@ public record SiteResponse( string Name, string? Address, string Timezone, + string? NtfyTopic, bool Enabled, DateTime CreatedAt); diff --git a/src/Heimdall.Application/Sites/Commands/CreateSite/CreateSiteCommand.cs b/src/Heimdall.Application/Sites/Commands/CreateSite/CreateSiteCommand.cs index 140e1cc..963b727 100644 --- a/src/Heimdall.Application/Sites/Commands/CreateSite/CreateSiteCommand.cs +++ b/src/Heimdall.Application/Sites/Commands/CreateSite/CreateSiteCommand.cs @@ -4,4 +4,4 @@ using MediatR; namespace Heimdall.Application.Sites.Commands.CreateSite; -public record CreateSiteCommand(string Name, string? Address, string? Timezone) : IRequest>; +public record CreateSiteCommand(string Name, string? Address, string? Timezone, string? NtfyTopic = null) : IRequest>; diff --git a/src/Heimdall.Application/Sites/Commands/CreateSite/CreateSiteHandler.cs b/src/Heimdall.Application/Sites/Commands/CreateSite/CreateSiteHandler.cs index 7a7e49b..b9e738e 100644 --- a/src/Heimdall.Application/Sites/Commands/CreateSite/CreateSiteHandler.cs +++ b/src/Heimdall.Application/Sites/Commands/CreateSite/CreateSiteHandler.cs @@ -19,7 +19,7 @@ public class CreateSiteHandler : IRequestHandler.Conflict("A site with this name already exists"); - var site = new Site(request.Name, request.Address, request.Timezone); + var site = new Site(request.Name, request.Address, request.Timezone, request.NtfyTopic); // Generate a registration token at creation so the UI can show it // immediately (POST /api/sites returns SiteWithTokenResponse). diff --git a/src/Heimdall.Application/Sites/Commands/UpdateSite/UpdateSiteCommand.cs b/src/Heimdall.Application/Sites/Commands/UpdateSite/UpdateSiteCommand.cs index 06450aa..874fe50 100644 --- a/src/Heimdall.Application/Sites/Commands/UpdateSite/UpdateSiteCommand.cs +++ b/src/Heimdall.Application/Sites/Commands/UpdateSite/UpdateSiteCommand.cs @@ -4,4 +4,4 @@ using MediatR; namespace Heimdall.Application.Sites.Commands.UpdateSite; -public record UpdateSiteCommand(Guid Id, string Name, string? Address, string? Timezone) : IRequest>; +public record UpdateSiteCommand(Guid Id, string Name, string? Address, string? Timezone, string? NtfyTopic = null) : IRequest>; diff --git a/src/Heimdall.Application/Sites/Commands/UpdateSite/UpdateSiteHandler.cs b/src/Heimdall.Application/Sites/Commands/UpdateSite/UpdateSiteHandler.cs index f5b1610..e5d7a50 100644 --- a/src/Heimdall.Application/Sites/Commands/UpdateSite/UpdateSiteHandler.cs +++ b/src/Heimdall.Application/Sites/Commands/UpdateSite/UpdateSiteHandler.cs @@ -16,10 +16,10 @@ public class UpdateSiteHandler : IRequestHandler.NotFound("Site not found"); - site.Update(request.Name, request.Address, request.Timezone); + site.Update(request.Name, request.Address, request.Timezone, request.NtfyTopic); await _context.SaveChangesWithRetryAsync(ct: cancellationToken).ConfigureAwait(false); return ServiceResult.Success(new SiteResponse( - site.Id, site.Name, site.Address, site.Timezone, site.Enabled, site.CreatedAt)); + site.Id, site.Name, site.Address, site.Timezone, site.NtfyTopic, site.Enabled, site.CreatedAt)); } } diff --git a/src/Heimdall.Application/Sites/Queries/GetSite/GetSiteHandler.cs b/src/Heimdall.Application/Sites/Queries/GetSite/GetSiteHandler.cs index aa59d2a..481ecf2 100644 --- a/src/Heimdall.Application/Sites/Queries/GetSite/GetSiteHandler.cs +++ b/src/Heimdall.Application/Sites/Queries/GetSite/GetSiteHandler.cs @@ -17,6 +17,6 @@ public class GetSiteHandler : IRequestHandler.NotFound("Site not found"); return ServiceResult.Success(new SiteResponse( - site.Id, site.Name, site.Address, site.Timezone, site.Enabled, site.CreatedAt)); + site.Id, site.Name, site.Address, site.Timezone, site.NtfyTopic, site.Enabled, site.CreatedAt)); } } diff --git a/src/Heimdall.Application/Sites/Queries/GetSites/GetSitesHandler.cs b/src/Heimdall.Application/Sites/Queries/GetSites/GetSitesHandler.cs index 8a2bfe9..9c63a7e 100644 --- a/src/Heimdall.Application/Sites/Queries/GetSites/GetSitesHandler.cs +++ b/src/Heimdall.Application/Sites/Queries/GetSites/GetSitesHandler.cs @@ -20,7 +20,7 @@ public class GetSitesHandler : IRequestHandler new SiteResponse( - s.Id, s.Name, s.Address, s.Timezone, s.Enabled, s.CreatedAt)) + s.Id, s.Name, s.Address, s.Timezone, s.NtfyTopic, s.Enabled, s.CreatedAt)) .ToListAsync(cancellationToken); return ServiceResult>.Success( diff --git a/src/Heimdall.Domain/Entities/Site.cs b/src/Heimdall.Domain/Entities/Site.cs index 8fa8f8c..e18fa15 100644 --- a/src/Heimdall.Domain/Entities/Site.cs +++ b/src/Heimdall.Domain/Entities/Site.cs @@ -9,6 +9,9 @@ public class Site : Entity, IAuditableEntity, ISoftDeletable public string Timezone { get; private set; } = "UTC"; public bool Enabled { get; private set; } = true; + /// Topic ntfy dédié pour les notifications de ce site (null → topic personnel utilisateur). + public string? NtfyTopic { get; private set; } + /// Hashed registration token (SHA256) for agent enrollment. public string? RegistrationTokenHash { get; private set; } @@ -36,19 +39,21 @@ public class Site : Entity, IAuditableEntity, ISoftDeletable private Site() { } // EF Core - public Site(string name, string? address = null, string? timezone = null) + public Site(string name, string? address = null, string? timezone = null, string? ntfyTopic = null) : base(Guid.NewGuid()) { Name = name; Address = address; Timezone = timezone ?? "UTC"; + NtfyTopic = ntfyTopic; } - public void Update(string name, string? address, string? timezone) + public void Update(string name, string? address, string? timezone, string? ntfyTopic = null) { Name = name; Address = address; Timezone = timezone ?? Timezone; + NtfyTopic = ntfyTopic; } public void GenerateRegistrationToken(string tokenHash, DateTime expiresAt) diff --git a/src/Heimdall.Infrastructure/Migrations/20260812101327_AddSiteNtfyTopic.Designer.cs b/src/Heimdall.Infrastructure/Migrations/20260812101327_AddSiteNtfyTopic.Designer.cs new file mode 100644 index 0000000..84ff87f --- /dev/null +++ b/src/Heimdall.Infrastructure/Migrations/20260812101327_AddSiteNtfyTopic.Designer.cs @@ -0,0 +1,2217 @@ +// +using System; +using Heimdall.Infrastructure.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Heimdall.Infrastructure.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20260812101327_AddSiteNtfyTopic")] + partial class AddSiteNtfyTopic + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ApiKeyHash") + .HasMaxLength(128) + .IsUnicode(false) + .HasColumnType("character varying(128)"); + + b.Property("ApiKeyPrefix") + .HasMaxLength(8) + .IsUnicode(false) + .HasColumnType("character varying(8)"); + + b.Property("CpuCores") + .HasColumnType("integer"); + + b.Property("CpuUsagePercent") + .HasColumnType("double precision"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DiskUsagePercent") + .HasColumnType("double precision"); + + b.Property("GpuType") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("HasGpu") + .HasColumnType("boolean"); + + b.Property("Hostname") + .IsRequired() + .HasMaxLength(255) + .IsUnicode(false) + .HasColumnType("character varying(255)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastHeartbeat") + .HasColumnType("timestamp with time zone"); + + b.Property("MemoryMb") + .HasColumnType("bigint"); + + b.Property("MemoryUsageBytes") + .HasColumnType("bigint"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("PublicIp") + .HasMaxLength(45) + .IsUnicode(false) + .HasColumnType("character varying(45)"); + + b.Property("SiteId") + .HasColumnType("uuid"); + + b.Property("Status") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("UptimeSeconds") + .HasColumnType("bigint"); + + b.Property("Version") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("LastHeartbeat") + .HasFilter("\"Status\" = 'Online'"); + + b.HasIndex("SiteId"); + + b.ToTable("agents", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AgentLogEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AgentId") + .HasColumnType("uuid"); + + b.Property("Exception") + .HasMaxLength(4000) + .HasColumnType("character varying(4000)"); + + b.Property("Level") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Message") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.Property("Source") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("TimestampUtc") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("AgentId", "TimestampUtc"); + + b.ToTable("agent_log_entries", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AgentId") + .HasColumnType("uuid") + .HasColumnName("agent_id"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone") + .HasColumnName("created_at"); + + b.Property("Key") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)") + .HasColumnName("key"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_at"); + + b.Property("Value") + .IsRequired() + .HasColumnType("text") + .HasColumnName("value"); + + b.HasKey("Id"); + + b.HasIndex("AgentId", "Key") + .IsUnique(); + + b.ToTable("agent_settings", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("CreatedByUserId") + .HasColumnType("uuid"); + + b.Property("Enabled") + .HasColumnType("boolean"); + + b.Property("ExpiresAt") + .HasColumnType("timestamp with time zone"); + + b.Property("KeyHash") + .IsRequired() + .HasMaxLength(128) + .IsUnicode(false) + .HasColumnType("character varying(128)"); + + b.Property("KeyPrefix") + .IsRequired() + .HasMaxLength(8) + .IsUnicode(false) + .HasColumnType("character varying(8)"); + + b.Property("LastUsedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("SiteId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("KeyHash"); + + b.HasIndex("KeyPrefix"); + + b.HasIndex("SiteId"); + + b.ToTable("api_keys", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AppRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("roles", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AppSetting", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AgentScoped") + .HasColumnType("boolean"); + + b.Property("AllowedValues") + .HasMaxLength(2000) + .HasColumnType("character varying(2000)") + .HasColumnName("allowed_values"); + + b.Property("Category") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasColumnName("category"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone") + .HasColumnName("created_at"); + + b.Property("Description") + .HasMaxLength(500) + .HasColumnType("character varying(500)") + .HasColumnName("description"); + + b.Property("Key") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)") + .HasColumnName("key"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_at"); + + b.Property("Value") + .IsRequired() + .HasColumnType("text") + .HasColumnName("value"); + + b.Property("ValueType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasColumnName("value_type"); + + b.HasKey("Id"); + + b.HasIndex("Key") + .IsUnique(); + + b.ToTable("app_settings", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("Language") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(10) + .IsUnicode(false) + .HasColumnType("character varying(10)") + .HasDefaultValue("fr"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("MustChangePassword") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(false); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("Theme") + .ValueGeneratedOnAdd() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)") + .HasDefaultValue("Auto"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("users", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Action") + .IsRequired() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("IpAddress") + .HasMaxLength(45) + .IsUnicode(false) + .HasColumnType("character varying(45)"); + + b.Property("NewValue") + .HasColumnType("text"); + + b.Property("OldValue") + .HasColumnType("text"); + + b.Property("ResourceId") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("ResourceType") + .IsRequired() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("Timestamp") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("Timestamp") + .IsDescending(); + + b.HasIndex("UserId"); + + b.HasIndex("ResourceType", "ResourceId", "Timestamp") + .IsDescending(false, false, true); + + b.ToTable("audit_logs", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AgentId") + .HasColumnType("uuid"); + + b.Property("Capabilities") + .IsRequired() + .HasMaxLength(64) + .IsUnicode(false) + .HasColumnType("character varying(64)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DetectedType") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("DiscoveryMethod") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("HasAudio") + .HasColumnType("boolean"); + + b.Property("HasMotionDetection") + .HasColumnType("boolean"); + + b.Property("HasPtz") + .HasColumnType("boolean"); + + b.Property("HttpPort") + .HasColumnType("integer"); + + b.Property("IpAddress") + .HasMaxLength(45) + .HasColumnType("character varying(45)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastDiscoveredAt") + .HasColumnType("timestamp with time zone"); + + b.Property("LastStreamTestAt") + .HasColumnType("timestamp with time zone"); + + b.Property("LastTestedCodecs") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("LastTestedHeight") + .HasColumnType("integer"); + + b.Property("LastTestedLatencyMs") + .HasColumnType("bigint"); + + b.Property("LastTestedWidth") + .HasColumnType("integer"); + + b.Property("MacAddress") + .HasMaxLength(17) + .HasColumnType("character varying(17)"); + + b.Property("Manufacturer") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Model") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("OnvifPort") + .HasColumnType("integer"); + + b.Property("RtspPort") + .HasColumnType("integer"); + + b.Property("RtspUrl") + .HasMaxLength(1000) + .IsUnicode(false) + .HasColumnType("character varying(1000)"); + + b.Property("SiteId") + .HasColumnType("uuid"); + + b.Property("Status") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("StoragePolicyId") + .HasColumnType("uuid"); + + b.Property("SubRtspUrl") + .HasMaxLength(1000) + .IsUnicode(false) + .HasColumnType("character varying(1000)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("AgentId"); + + b.HasIndex("IpAddress"); + + b.HasIndex("MacAddress"); + + b.HasIndex("SiteId"); + + b.HasIndex("StoragePolicyId"); + + b.ToTable("cameras", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraAssignment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AgentId") + .HasColumnType("uuid"); + + b.Property("AssignedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CameraId") + .HasColumnType("uuid"); + + b.Property("Reason") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("ReleasedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("AssignedAt"); + + b.HasIndex("AgentId", "ReleasedAt") + .HasFilter("\"ReleasedAt\" IS NULL"); + + b.HasIndex("CameraId", "ReleasedAt") + .IsUnique() + .HasFilter("\"ReleasedAt\" IS NULL"); + + b.ToTable("camera_assignments", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => + { + b.Property("CameraId") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("OnvifPassword") + .IsRequired() + .HasMaxLength(500) + .IsUnicode(false) + .HasColumnType("character varying(500)"); + + b.Property("OnvifUsername") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)") + .HasDefaultValue("admin"); + + b.Property("RtspPassword") + .IsRequired() + .HasMaxLength(500) + .IsUnicode(false) + .HasColumnType("character varying(500)"); + + b.Property("RtspUsername") + .IsRequired() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("CameraId"); + + b.ToTable("camera_credentials", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => + { + b.Property("CameraId") + .HasColumnType("uuid"); + + b.Property("ActiveIntervalMs") + .HasColumnType("integer"); + + b.Property("AnimalCooldownSec") + .HasColumnType("integer"); + + b.Property("DetectAnimal") + .HasColumnType("boolean"); + + b.Property("DetectMotion") + .HasColumnType("boolean"); + + b.Property("DetectPackage") + .HasColumnType("boolean"); + + b.Property("DetectPerson") + .HasColumnType("boolean"); + + b.Property("DetectVehicle") + .HasColumnType("boolean"); + + b.Property("FaceRecognition") + .HasColumnType("boolean"); + + b.Property("IdleIntervalMs") + .HasColumnType("integer"); + + b.Property("IoUThreshold") + .HasColumnType("double precision"); + + b.Property("LicensePlateRecognition") + .HasColumnType("boolean"); + + b.Property("MaxEventsPerMinute") + .HasColumnType("integer"); + + b.Property("MinConfidence") + .ValueGeneratedOnAdd() + .HasColumnType("double precision") + .HasDefaultValue(0.40000000000000002); + + b.Property("MotionIntervalMs") + .HasColumnType("integer"); + + b.Property("MotionThreshold") + .HasColumnType("double precision"); + + b.Property("PersonCooldownSec") + .HasColumnType("integer"); + + b.Property("RequireMotionForAI") + .HasColumnType("boolean"); + + b.Property("VehicleCooldownSec") + .HasColumnType("integer"); + + b.Property("YoloModel") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)") + .HasDefaultValue("yolov8n"); + + b.HasKey("CameraId"); + + b.ToTable("camera_detection_profiles", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DetectedType") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("DiscoveryMethod") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("HomeKitDeviceId") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("HomeKitModel") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("HomeKitName") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("Hostname") + .HasMaxLength(255) + .IsUnicode(false) + .HasColumnType("character varying(255)"); + + b.Property("HttpPort") + .HasColumnType("integer"); + + b.Property("HttpServerHeader") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("HttpStatusCode") + .HasColumnType("integer"); + + b.Property("IpAddress") + .IsRequired() + .HasMaxLength(45) + .IsUnicode(false) + .HasColumnType("character varying(45)"); + + b.Property("IsHomeKitCamera") + .HasColumnType("boolean"); + + b.Property("IsProcessed") + .HasColumnType("boolean"); + + b.Property("IsReachable") + .HasColumnType("boolean"); + + b.Property("MacAddress") + .HasMaxLength(17) + .IsUnicode(false) + .HasColumnType("character varying(17)"); + + b.Property("OnvifDeviceServiceUrl") + .HasMaxLength(500) + .IsUnicode(false) + .HasColumnType("character varying(500)"); + + b.Property("OnvifHardware") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("OnvifName") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("OnvifPort") + .HasColumnType("integer"); + + b.PrimitiveCollection("OpenPorts") + .IsRequired() + .IsUnicode(false) + .HasColumnType("integer[]"); + + b.Property("ProbedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("SiteId") + .HasColumnType("uuid"); + + b.Property("Vendor") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.HasKey("Id"); + + b.HasIndex("IpAddress"); + + b.HasIndex("IsProcessed"); + + b.HasIndex("SiteId"); + + b.ToTable("camera_discovery_results", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraEvent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AgentId") + .HasColumnType("uuid"); + + b.Property("CameraId") + .HasColumnType("uuid"); + + b.Property("Confidence") + .ValueGeneratedOnAdd() + .HasColumnType("double precision") + .HasDefaultValue(0.0); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("DetectionHash") + .HasMaxLength(128) + .IsUnicode(false) + .HasColumnType("character varying(128)"); + + b.Property("IsSuppressed") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(false); + + b.Property("Label") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.Property("MetadataJson") + .HasColumnType("jsonb"); + + b.Property("OccurredAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ParentEventId") + .HasColumnType("uuid"); + + b.Property("RecordingId") + .HasColumnType("uuid"); + + b.Property("SnapshotThumbUrl") + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("SnapshotUrl") + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("TrackId") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("Type") + .HasColumnType("integer"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("VehicleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("DetectionHash"); + + b.HasIndex("OccurredAt"); + + b.HasIndex("ParentEventId"); + + b.HasIndex("RecordingId"); + + b.HasIndex("TrackId"); + + b.HasIndex("VehicleId"); + + b.HasIndex("CameraId", "OccurredAt") + .IsDescending(false, true); + + b.HasIndex("CameraId", "Type"); + + b.ToTable("camera_events", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.PrimitiveCollection("Codecs") + .IsRequired() + .IsUnicode(false) + .HasColumnType("text[]"); + + b.Property("DiscoveryResultId") + .HasColumnType("uuid"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("IsAlive") + .HasColumnType("boolean"); + + b.Property("IsMainStream") + .HasColumnType("boolean"); + + b.Property("LatencyMs") + .HasColumnType("bigint"); + + b.Property("Protocol") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Url") + .IsRequired() + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DiscoveryResultId"); + + b.HasIndex("IsAlive"); + + b.HasIndex("IsMainStream"); + + b.ToTable("discovered_streams", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Group", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .HasMaxLength(1000) + .HasColumnType("character varying(1000)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted") + .HasFilter("\"IsDeleted\" = false"); + + b.HasIndex("Name"); + + b.ToTable("groups", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.KnownFace", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Embedding") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("PersonId") + .HasColumnType("uuid"); + + b.Property("SourceEventId") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("ThumbnailUrl") + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.HasKey("Id"); + + b.HasIndex("PersonId"); + + b.ToTable("known_faces", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.LicensePlate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Confidence") + .ValueGeneratedOnAdd() + .HasColumnType("double precision") + .HasDefaultValue(0.0); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("PersonId") + .HasColumnType("uuid"); + + b.Property("PlateText") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("VehicleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("PersonId"); + + b.HasIndex("PlateText"); + + NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("PlateText"), "gin"); + NpgsqlIndexBuilderExtensions.HasOperators(b.HasIndex("PlateText"), new[] { "gin_trgm_ops" }); + + b.HasIndex("VehicleId"); + + b.ToTable("license_plates", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Notification", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CameraId") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("EventType") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("IsRead") + .HasColumnType("boolean"); + + b.Property("Link") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Message") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.Property("ReadAt") + .HasColumnType("timestamp with time zone"); + + b.Property("SiteId") + .HasColumnType("uuid"); + + b.Property("SnapshotUrl") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("CreatedAt"); + + b.HasIndex("UserId"); + + b.HasIndex("UserId", "IsRead"); + + b.ToTable("notifications", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.NotificationTemplate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("BodyMarkdown") + .IsRequired() + .HasColumnType("text"); + + b.Property("Channel") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("EventType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("IsDefault") + .HasColumnType("boolean"); + + b.Property("Language") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(10) + .HasColumnType("character varying(10)") + .HasDefaultValue("fr"); + + b.Property("Subject") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("EventType", "Channel", "Language") + .IsUnique(); + + b.ToTable("notification_templates", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Category") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("IsWatchlisted") + .HasColumnType("boolean"); + + b.Property("Notes") + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.Property("PhotoUrl") + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Category"); + + b.HasIndex("DisplayName"); + + b.HasIndex("IsWatchlisted"); + + b.ToTable("persons", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Recording", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CameraId") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("DurationSeconds") + .ValueGeneratedOnAdd() + .HasColumnType("double precision") + .HasDefaultValue(0.0); + + b.Property("SizeBytes") + .HasColumnType("bigint"); + + b.Property("StoragePath") + .IsRequired() + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("StoragePolicyId") + .HasColumnType("uuid"); + + b.Property("StorageProvider") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Timestamp") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("StoragePath") + .IsUnique(); + + b.HasIndex("StoragePolicyId"); + + b.HasIndex("CameraId", "Timestamp"); + + b.ToTable("recordings", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.RevokedRefreshToken", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ExpiresAt") + .HasColumnType("timestamp with time zone"); + + b.Property("RevokedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("TokenHash") + .IsRequired() + .HasMaxLength(128) + .IsUnicode(false) + .HasColumnType("character varying(128)"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ExpiresAt"); + + b.HasIndex("TokenHash") + .IsUnique(); + + b.ToTable("revoked_refresh_tokens", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Address") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Enabled") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("NtfyTopic") + .HasColumnType("text"); + + b.Property("RegistrationTokenHash") + .HasMaxLength(128) + .IsUnicode(false) + .HasColumnType("character varying(128)"); + + b.Property("Timezone") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)") + .HasDefaultValue("UTC"); + + b.Property("TokenExpiresAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted") + .HasFilter("\"IsDeleted\" = false"); + + b.HasIndex("Name"); + + b.ToTable("sites", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.SiteCredential", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("Label") + .IsRequired() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("LastUsedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(2000) + .IsUnicode(false) + .HasColumnType("character varying(2000)"); + + b.Property("SiteId") + .HasColumnType("uuid"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("character varying(200)"); + + b.HasKey("Id"); + + b.HasIndex("SiteId"); + + b.ToTable("site_credentials", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.StoragePolicy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("RetentionDays") + .HasColumnType("integer"); + + b.Property("StorageProvider") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.ToTable("storage_policies", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("GroupId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "GroupId"); + + b.HasIndex("GroupId"); + + b.ToTable("user_groups", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.UserNotificationConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("DailyDigest") + .HasColumnType("boolean"); + + b.Property("EmailAddress") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("EmailEnabled") + .HasColumnType("boolean"); + + b.Property("Language") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(10) + .HasColumnType("character varying(10)") + .HasDefaultValue("fr"); + + b.Property("NtfyEnabled") + .HasColumnType("boolean"); + + b.Property("NtfyUrl") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("SubscribedEventsJson") + .HasColumnType("jsonb") + .HasColumnName("subscribed_events"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("WeeklyDigest") + .HasColumnType("boolean"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("user_notification_configs", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.UserRecoveryCode", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CodeHash") + .IsRequired() + .HasMaxLength(64) + .IsUnicode(false) + .HasColumnType("character varying(64)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("UsedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.HasIndex("UserId", "CodeHash") + .IsUnique(); + + b.ToTable("user_recovery_codes", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("SiteId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "SiteId"); + + b.HasIndex("SiteId"); + + b.ToTable("user_sites", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Vehicle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Color") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.Property("LicensePlate") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Make") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("Model") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("character varying(100)"); + + b.Property("PersonId") + .HasColumnType("uuid"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("NOW()"); + + b.HasKey("Id"); + + b.HasIndex("LicensePlate"); + + b.HasIndex("PersonId"); + + b.ToTable("vehicles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("role_claims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_claims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("user_logins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("user_roles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("user_tokens", (string)null); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => + { + b.HasOne("Heimdall.Domain.Entities.Site", "Site") + .WithMany("Agents") + .HasForeignKey("SiteId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Site"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AgentLogEntry", b => + { + b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") + .WithMany() + .HasForeignKey("AgentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Agent"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b => + { + b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") + .WithMany() + .HasForeignKey("AgentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Agent"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => + { + b.HasOne("Heimdall.Domain.Entities.Site", "Site") + .WithMany() + .HasForeignKey("SiteId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("Site"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => + { + b.HasOne("Heimdall.Domain.Entities.AppUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => + { + b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") + .WithMany("Cameras") + .HasForeignKey("AgentId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Heimdall.Domain.Entities.Site", "Site") + .WithMany("Cameras") + .HasForeignKey("SiteId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Heimdall.Domain.Entities.StoragePolicy", "StoragePolicy") + .WithMany() + .HasForeignKey("StoragePolicyId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("Agent"); + + b.Navigation("Site"); + + b.Navigation("StoragePolicy"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraAssignment", b => + { + b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") + .WithMany() + .HasForeignKey("AgentId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") + .WithMany() + .HasForeignKey("CameraId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Agent"); + + b.Navigation("Camera"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => + { + b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") + .WithOne("Credentials") + .HasForeignKey("Heimdall.Domain.Entities.CameraCredentials", "CameraId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Camera"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => + { + b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") + .WithOne("DetectionProfile") + .HasForeignKey("Heimdall.Domain.Entities.CameraDetectionProfile", "CameraId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Camera"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => + { + b.HasOne("Heimdall.Domain.Entities.Site", "Site") + .WithMany() + .HasForeignKey("SiteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Site"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraEvent", b => + { + b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") + .WithMany() + .HasForeignKey("CameraId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Heimdall.Domain.Entities.CameraEvent", "ParentEvent") + .WithMany() + .HasForeignKey("ParentEventId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Heimdall.Domain.Entities.Recording", "Recording") + .WithMany() + .HasForeignKey("RecordingId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Heimdall.Domain.Entities.Vehicle", "Vehicle") + .WithMany() + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("Camera"); + + b.Navigation("ParentEvent"); + + b.Navigation("Recording"); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b => + { + b.HasOne("Heimdall.Domain.Entities.CameraDiscoveryResult", "DiscoveryResult") + .WithMany("DiscoveredStreams") + .HasForeignKey("DiscoveryResultId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DiscoveryResult"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.KnownFace", b => + { + b.HasOne("Heimdall.Domain.Entities.Person", "Person") + .WithMany("Faces") + .HasForeignKey("PersonId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Person"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.LicensePlate", b => + { + b.HasOne("Heimdall.Domain.Entities.Person", "Person") + .WithMany() + .HasForeignKey("PersonId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Heimdall.Domain.Entities.Vehicle", "Vehicle") + .WithMany() + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("Person"); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Recording", b => + { + b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") + .WithMany() + .HasForeignKey("CameraId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Heimdall.Domain.Entities.StoragePolicy", "StoragePolicy") + .WithMany() + .HasForeignKey("StoragePolicyId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("Camera"); + + b.Navigation("StoragePolicy"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.SiteCredential", b => + { + b.HasOne("Heimdall.Domain.Entities.Site", "Site") + .WithMany("Credentials") + .HasForeignKey("SiteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Site"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b => + { + b.HasOne("Heimdall.Domain.Entities.Group", "Group") + .WithMany("UserGroups") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Heimdall.Domain.Entities.AppUser", "User") + .WithMany("UserGroups") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => + { + b.HasOne("Heimdall.Domain.Entities.Site", "Site") + .WithMany() + .HasForeignKey("SiteId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Heimdall.Domain.Entities.AppUser", "User") + .WithMany("UserSites") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Site"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Vehicle", b => + { + b.HasOne("Heimdall.Domain.Entities.Person", "Person") + .WithMany() + .HasForeignKey("PersonId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("Person"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Heimdall.Domain.Entities.AppRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Heimdall.Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Heimdall.Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Heimdall.Domain.Entities.AppRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Heimdall.Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Heimdall.Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => + { + b.Navigation("Cameras"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => + { + b.Navigation("UserGroups"); + + b.Navigation("UserSites"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => + { + b.Navigation("Credentials"); + + b.Navigation("DetectionProfile"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => + { + b.Navigation("DiscoveredStreams"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Group", b => + { + b.Navigation("UserGroups"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Person", b => + { + b.Navigation("Faces"); + }); + + modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => + { + b.Navigation("Agents"); + + b.Navigation("Cameras"); + + b.Navigation("Credentials"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Heimdall.Infrastructure/Migrations/20260812101327_AddSiteNtfyTopic.cs b/src/Heimdall.Infrastructure/Migrations/20260812101327_AddSiteNtfyTopic.cs new file mode 100644 index 0000000..fe7705e --- /dev/null +++ b/src/Heimdall.Infrastructure/Migrations/20260812101327_AddSiteNtfyTopic.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Heimdall.Infrastructure.Migrations +{ + /// + public partial class AddSiteNtfyTopic : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "NtfyTopic", + table: "sites", + type: "text", + nullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "NtfyTopic", + table: "sites"); + } + } +} diff --git a/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs b/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs index fe066c1..24d0a4a 100644 --- a/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs +++ b/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs @@ -1453,6 +1453,9 @@ namespace Heimdall.Infrastructure.Migrations .HasMaxLength(200) .HasColumnType("character varying(200)"); + b.Property("NtfyTopic") + .HasColumnType("text"); + b.Property("RegistrationTokenHash") .HasMaxLength(128) .IsUnicode(false) diff --git a/src/Heimdall.Infrastructure/Services/NotificationService.cs b/src/Heimdall.Infrastructure/Services/NotificationService.cs index 22a3359..0cd804e 100644 --- a/src/Heimdall.Infrastructure/Services/NotificationService.cs +++ b/src/Heimdall.Infrastructure/Services/NotificationService.cs @@ -111,7 +111,7 @@ public class NotificationService : INotificationService if (config.NtfyEnabled) { - var topic = $"heimdall_{userId}"; + var topic = await ResolveNtfyTopicAsync(notification, userId, ct); await _ntfyService.SendNotificationAsync( topic, notification.Title, @@ -125,6 +125,26 @@ public class NotificationService : INotificationService } } + /// + /// Résout le topic ntfy cible d'une notification (ticket #105) : + /// topic du site si défini, sinon topic personnel heimdall_{userId}. + /// + private async Task ResolveNtfyTopicAsync(Notification notification, Guid userId, CancellationToken ct) + { + if (notification.SiteId is { } siteId) + { + var siteTopic = await _context.Sites + .AsNoTracking() + .Where(s => s.Id == siteId) + .Select(s => s.NtfyTopic) + .FirstOrDefaultAsync(ct); + if (!string.IsNullOrWhiteSpace(siteTopic)) + return siteTopic; + } + + return $"heimdall_{userId}"; + } + public async Task GetUnreadCountAsync(Guid userId, CancellationToken ct = default) { return await _context.Notifications diff --git a/src/Heimdall.Web/Components/Pages/SitesPage.razor b/src/Heimdall.Web/Components/Pages/SitesPage.razor index ba7f036..0f53b79 100644 --- a/src/Heimdall.Web/Components/Pages/SitesPage.razor +++ b/src/Heimdall.Web/Components/Pages/SitesPage.razor @@ -80,6 +80,8 @@ else + @if (!string.IsNullOrEmpty(_creationError)) { @_creationError @@ -130,6 +132,8 @@ else + @if (!string.IsNullOrEmpty(_editError)) { @_editError @@ -227,6 +231,7 @@ else private string _newName = ""; private string? _newAddress; private string? _newTimezone; + private string? _newNtfyTopic; private string _creationError = ""; private string _createdToken = ""; private bool IsCreateDisabled => _saving || !string.IsNullOrEmpty(_createdToken); @@ -247,6 +252,7 @@ else private string _editName = ""; private string? _editAddress; private string? _editTimezone; + private string? _editNtfyTopic; private string _editError = ""; /// URL publique du serveur Heimdall (utilisée dans le compose généré). @@ -305,6 +311,7 @@ else _newName = ""; _newAddress = null; _newTimezone = null; + _newNtfyTopic = null; } private async Task ConfirmCreate() @@ -314,7 +321,7 @@ else _creationError = ""; try { - var result = await Api.CreateSiteAsync(_newName, _newAddress, _newTimezone); + var result = await Api.CreateSiteAsync(_newName, _newAddress, _newTimezone, _newNtfyTopic); if (result is null) { _creationError = "Erreur lors de la création"; return; } _createdToken = result.RegistrationToken ?? "Token non disponible"; Snackbar.Add("Site créé avec succès", Severity.Success); @@ -362,6 +369,7 @@ else _editName = site.Name; _editAddress = site.Address; _editTimezone = site.Timezone; + _editNtfyTopic = site.NtfyTopic; _editError = ""; _showEdit = true; } @@ -373,7 +381,7 @@ else _editError = ""; try { - var ok = await Api.UpdateSiteAsync(_editId, _editName, _editAddress, _editTimezone); + var ok = await Api.UpdateSiteAsync(_editId, _editName, _editAddress, _editTimezone, _editNtfyTopic); if (!ok) { _editError = "Erreur lors de la mise à jour"; return; } Snackbar.Add("Site modifié avec succès", Severity.Success); _showEdit = false; diff --git a/src/Heimdall.Web/Components/Settings/AgentDefaultsSection.razor b/src/Heimdall.Web/Components/Settings/AgentDefaultsSection.razor index 4441c34..4bda8f7 100644 --- a/src/Heimdall.Web/Components/Settings/AgentDefaultsSection.razor +++ b/src/Heimdall.Web/Components/Settings/AgentDefaultsSection.razor @@ -31,11 +31,10 @@ - + @@ -44,11 +43,10 @@ - + @@ -56,13 +54,13 @@ Diagnostic - - + + @@ -85,16 +83,10 @@ private string? GetValue(string key) => _settings.FirstOrDefault(s => s.Key == key)?.Value; - private string SecretValue(string key) - { - var v = GetValue(key); - return v is null or "" or "***REDACTED***" ? string.Empty : v; - } - private Task OnLogLevelChanged(string v) => SaveValueAsync("log.level", v); - private Task OnRetentionChanged(string v) => SaveValueAsync("log.retentiondays", v); - private Task OnHeartbeatChanged(string v) => SaveValueAsync("heartbeat.interval.seconds", v); - private Task OnSentryDsnChanged(string v) => SaveValueAsync("sentry.dsn", v); + private Task OnRetentionChanged(int? v) => SaveValueAsync("log.retentiondays", v?.ToString() ?? ""); + private Task OnHeartbeatChanged(int? v) => SaveValueAsync("heartbeat.interval.seconds", v?.ToString() ?? ""); + private Task OnSentryEnabledChanged(bool v) => SaveValueAsync("sentry.enabled", v ? "true" : "false"); private async Task SaveValueAsync(string key, string? value) { diff --git a/src/Heimdall.Web/Components/Settings/NotificationSettingsSection.razor b/src/Heimdall.Web/Components/Settings/NotificationSettingsSection.razor index aec8b9c..7b9fc44 100644 --- a/src/Heimdall.Web/Components/Settings/NotificationSettingsSection.razor +++ b/src/Heimdall.Web/Components/Settings/NotificationSettingsSection.razor @@ -56,10 +56,9 @@ HelperText="Ex : smtp.gmail.com" /> - + SaveValueAsync("email.fromaddress", v); private Task OnFromNameChanged(string v) => SaveValueAsync("email.fromname", v); private Task OnSmtpHostChanged(string v) => SaveValueAsync("email.smtphost", v); - private Task OnSmtpPortChanged(string v) => SaveValueAsync("email.smtpport", v); + private Task OnSmtpPortChanged(int? v) => SaveValueAsync("email.smtpport", v?.ToString() ?? ""); private Task OnUsernameChanged(string v) => SaveValueAsync("email.username", v); private Task OnPasswordChanged(string v) => SaveValueAsync("email.password", v); private Task OnUseSslChanged(bool v) => SaveValueAsync("email.usessl", v ? "true" : "false"); @@ -187,7 +186,7 @@ await Api.CreateSettingAsync(new CreateAppSettingRequest( Key: key, Value: value, Category: "integrations", - Description: key, ValueType: "string", AllowedValues: null, AgentScoped: true)); + Description: key, ValueType: "string", AllowedValues: null, AgentScoped: false)); } else { diff --git a/src/Heimdall.Web/Components/Settings/StorageSettingsSection.razor b/src/Heimdall.Web/Components/Settings/StorageSettingsSection.razor index e15ec40..04717ff 100644 --- a/src/Heimdall.Web/Components/Settings/StorageSettingsSection.razor +++ b/src/Heimdall.Web/Components/Settings/StorageSettingsSection.razor @@ -125,7 +125,7 @@ Key: key, Value: value, Category: "storage", Description: key.StartsWith("storage.s3.secretKey", StringComparison.Ordinal) ? "Clé secrète S3" : key, - ValueType: "string", AllowedValues: null, AgentScoped: true)); + ValueType: "string", AllowedValues: null, AgentScoped: false)); } else { diff --git a/src/Heimdall.Web/Program.cs b/src/Heimdall.Web/Program.cs index f575528..7655764 100644 --- a/src/Heimdall.Web/Program.cs +++ b/src/Heimdall.Web/Program.cs @@ -242,7 +242,8 @@ public partial class Program { "storage.s3.secretKey" => "Clé secrète S3", "storage.s3.region" => "Région S3", _ => key - })); + }, + agentScoped: false)); } await groupDb.SaveChangesWithRetryAsync(); @@ -265,12 +266,17 @@ public partial class Program { ["log.level"] = Environment.GetEnvironmentVariable("LOG__LEVEL") ?? "info", ["log.retentionDays"] = Environment.GetEnvironmentVariable("LOG__RETENTION_DAYS") ?? "7", ["heartbeat.interval.seconds"] = Environment.GetEnvironmentVariable("HEARTBEAT__INTERVAL_SECONDS") ?? "30", - ["sentry.dsn"] = Environment.GetEnvironmentVariable("SENTRY_DSN"), + ["sentry.enabled"] = "true", }; foreach (var (key, value) in integrationDefaults) { if (existingAppSettingKeys.Contains(key)) continue; + // SMTP/ntfy/Sentry = paramètres GLOBAUX (jamais poussés aux agents) ; + // ai.*, log.*, heartbeat.* restent des défauts applicables aux agents. + var agentScoped = !(key.StartsWith("ntfy.", StringComparison.Ordinal) + || key.StartsWith("email.", StringComparison.Ordinal) + || key.StartsWith("sentry.", StringComparison.Ordinal)); groupDb.AppSettings.Add(new Heimdall.Domain.Entities.AppSetting( key, value ?? string.Empty, key.StartsWith("ntfy.", StringComparison.Ordinal) || key.StartsWith("email.", StringComparison.Ordinal) @@ -292,12 +298,27 @@ public partial class Program { "log.level" => "Niveau de log global (agents + central)", "log.retentionDays" => "Rétention des logs agents (jours)", "heartbeat.interval.seconds" => "Intervalle de heartbeat des agents (secondes)", - "sentry.dsn" => "DSN Sentry/GlitchTip (diagnostic)", + "sentry.enabled" => "Autoriser l'envoi des erreurs vers GlitchTip (nécessite un redémarrage)", _ => key - })); + }, + agentScoped)); } await groupDb.SaveChangesWithRetryAsync(); + // Migration douce (#106) : les clés d'intégration déjà présentes en base + // (créées avant ce changement avec agentScoped=true) doivent passer en + // GLOBAL — jamais exposées aux agents. sentry.dsn n'a plus de rôle + // (DSN fixes en appsettings) → suppression. + await groupDb.AppSettings + .Where(s => s.Key.StartsWith("ntfy.") || s.Key.StartsWith("email.") + || s.Key.StartsWith("storage.") || s.Key.StartsWith("sentry.")) + .ExecuteUpdateAsync(s => s.SetProperty(x => x.AgentScoped, false)); + var legacySentryDsn = await groupDb.AppSettings + .FirstOrDefaultAsync(s => s.Key == "sentry.dsn"); + if (legacySentryDsn is not null) + groupDb.AppSettings.Remove(legacySentryDsn); + await groupDb.SaveChangesWithRetryAsync(); + // Seed demo admin + demo site when explicitly enabled (dev & E2E hosts) if (configuration.GetValue("Seed:DemoOnStartup", false)) { @@ -334,92 +355,6 @@ public partial class Program { internal static void ConfigureServices(WebApplicationBuilder builder) { - // ── Sentry (GlitchTip) — error tracking, performance & structured logs ── - // Primary: Sentry:Dsn from appsettings.json or env var Sentry__Dsn - // Fallback: legacy SENTRY_DSN env var (Docker backward compat) - // Neither set → DSN is null → Sentry SDK no-ops gracefully - var sentryDsn = builder.Configuration["Sentry:Dsn"] - ?? Environment.GetEnvironmentVariable("SENTRY_DSN"); - if (!string.IsNullOrEmpty(sentryDsn)) - { - builder.WebHost.UseSentry((SentryAspNetCoreOptions options) => - { - options.Dsn = sentryDsn; - - // ── Env & Release ──────────────────────────────────────── - // Environment is auto-read from IHostingEnvironment - // Release should be explicitly set (e.g. "heimdall@1.2.3") - options.Release = builder.Configuration["Sentry:Release"] - ?? Environment.GetEnvironmentVariable("SENTRY_RELEASE"); - - // ── Error sampling ────────────────────────────────────── - options.SampleRate = 1.0f; // 100% errors (adjust if volume too high) - options.AttachStacktrace = true; // Stack traces even on CaptureMessage - options.MaxBreadcrumbs = 100; // Breadcrumb buffer size - options.MinimumBreadcrumbLevel = LogLevel.Debug; - options.MinimumEventLevel = LogLevel.Error; - - // ── Tracing (Performance) ─────────────────────────────── - // GlitchTip counts every transaction as an event. - // 0.05 = 5% sample = good signal-to-noise in production. - options.TracesSampleRate = double.Parse( - builder.Configuration["Sentry:TracesSampleRate"] ?? "0.05", - System.Globalization.CultureInfo.InvariantCulture); - - // ── Request body capture ──────────────────────────────── - options.MaxRequestBodySize = Sentry.Extensibility.RequestSize.Small; - - // ── Structured logs (v5.14+) ──────────────────────────── - // Enables SentrySdk.Logger.LogInfo() etc. - options.EnableLogs = true; - - // ── GlitchTip-specific: disable unsupported features ──── - // Release Health / Sessions are NOT supported by GlitchTip - options.AutoSessionTracking = false; - - // ── PII & GDPR ────────────────────────────────────────── - options.SendDefaultPii = false; // Explicit RGPD-safe default - options.ServerName = null; // Never send hostname - - // ── Enhanced diagnostics ──────────────────────────────── - options.CaptureBlockingCalls = true; // Detect .Result / .Wait() - options.CaptureFailedRequests = true; // Capture HttpClient 4xx/5xx - options.IncludeActivityData = true; // DiagnosticSource Activity - - // ── Stack traces ──────────────────────────────────────── - options.StackTraceMode = Sentry.StackTraceMode.Enhanced; - - // ── BeforeSend — scrub PII before it leaves the SDK ──── - options.SetBeforeSend((sentryEvent, hint) => - { - // Never send server name (already null above, belt-and-suspenders) - sentryEvent.ServerName = null; - - // Remove sensitive extras - if (sentryEvent.Extra?.ContainsKey("password") == true) - (sentryEvent.Extra as IDictionary)?.Remove("password"); - if (sentryEvent.Extra?.ContainsKey("token") == true) - (sentryEvent.Extra as IDictionary)?.Remove("token"); - if (sentryEvent.Extra?.ContainsKey("secret") == true) - (sentryEvent.Extra as IDictionary)?.Remove("secret"); - - return sentryEvent; - }); - - // ── BeforeBreadcrumb — filter noisy breadcrumbs ──────── - options.SetBeforeBreadcrumb(breadcrumb - => breadcrumb.Category == "Microsoft.AspNetCore.RateLimiting" - ? null - : breadcrumb); - }); - } - - - // ── Startup diagnostics ──────────────────────────────────────── - var sentryStatus = string.IsNullOrEmpty(sentryDsn) - ? "NOT CONFIGURED — errors will NOT be reported to GlitchTip" - : "configured (" + sentryDsn[..sentryDsn.IndexOf('@')] + "@...)"; - Console.WriteLine($"[DIAG] Sentry/GlitchTip DSN: {sentryStatus}"); Console.WriteLine($"[DIAG] Environment: {builder.Environment.EnvironmentName}"); Console.WriteLine($"[DIAG] Data Protection keys dir: /var/lib/heimdall/dp-keys"); Console.WriteLine($"[DIAG] Demo seeding: {(builder.Configuration.GetValue("Seed:DemoOnStartup", false) ? "enabled" : "disabled (set Seed:DemoOnStartup=true to enable)")}"); @@ -575,6 +510,86 @@ public partial class Program { builder.Services.AddApplication(); builder.Services.AddInfrastructure(builder.Configuration); + // ── Sentry (GlitchTip) — DSN fixe (appsettings), toggle global ── + // Le toggle sentry.enabled est lu en base (après AddInfrastructure) : + // false -> SDK non initialisé (redémarrage requis pour changer). + // Table absente au 1er boot / DB indisponible -> défaut activé. + var sentryDsn = builder.Configuration["Sentry:Dsn"] + ?? Environment.GetEnvironmentVariable("SENTRY_DSN"); + var sentryEnabled = IsSentryEnabledFromDb(builder.Services); + if (sentryEnabled && !string.IsNullOrEmpty(sentryDsn)) + { + builder.WebHost.UseSentry((SentryAspNetCoreOptions options) => + { + options.Dsn = sentryDsn; + + // ── Env & Release ──────────────────────────────────────── + options.Release = builder.Configuration["Sentry:Release"] + ?? Environment.GetEnvironmentVariable("SENTRY_RELEASE"); + + // ── Error sampling ────────────────────────────────────── + options.SampleRate = 1.0f; + options.AttachStacktrace = true; + options.MaxBreadcrumbs = 100; + options.MinimumBreadcrumbLevel = LogLevel.Debug; + options.MinimumEventLevel = LogLevel.Error; + + // ── Tracing (Performance) ─────────────────────────────── + options.TracesSampleRate = double.Parse( + builder.Configuration["Sentry:TracesSampleRate"] ?? "0.05", + System.Globalization.CultureInfo.InvariantCulture); + + // ── Request body capture ──────────────────────────────── + options.MaxRequestBodySize = Sentry.Extensibility.RequestSize.Small; + + // ── Structured logs (v5.14+) ──────────────────────────── + options.EnableLogs = true; + + // ── GlitchTip-specific: disable unsupported features ──── + options.AutoSessionTracking = false; + + // ── PII & GDPR ────────────────────────────────────────── + options.SendDefaultPii = false; + options.ServerName = null; + + // ── Enhanced diagnostics ──────────────────────────────── + options.CaptureBlockingCalls = true; + options.CaptureFailedRequests = true; + options.IncludeActivityData = true; + + // ── Stack traces ──────────────────────────────────────── + options.StackTraceMode = Sentry.StackTraceMode.Enhanced; + + // ── BeforeSend — scrub PII before it leaves the SDK ──── + options.SetBeforeSend((sentryEvent, hint) => + { + sentryEvent.ServerName = null; + if (sentryEvent.Extra?.ContainsKey("password") == true) + (sentryEvent.Extra as IDictionary)?.Remove("password"); + if (sentryEvent.Extra?.ContainsKey("token") == true) + (sentryEvent.Extra as IDictionary)?.Remove("token"); + if (sentryEvent.Extra?.ContainsKey("secret") == true) + (sentryEvent.Extra as IDictionary)?.Remove("secret"); + + return sentryEvent; + }); + + // ── BeforeBreadcrumb — filter noisy breadcrumbs ──────── + options.SetBeforeBreadcrumb(breadcrumb + => breadcrumb.Category == "Microsoft.AspNetCore.RateLimiting" + ? null + : breadcrumb); + }); + } + + var sentryStatus = !sentryEnabled + ? "DISABLED (toggle sentry.enabled=false — redémarrage requis)" + : string.IsNullOrEmpty(sentryDsn) + ? "NOT CONFIGURED — errors will NOT be reported to GlitchTip" + : "configured (" + sentryDsn[..sentryDsn.IndexOf('@')] + "@...)"; + Console.WriteLine($"[DIAG] Sentry/GlitchTip DSN: {sentryStatus}"); + + // AddIdentity (inside AddInfrastructure) sets Identity.Application as the // default authenticate/challenge scheme. But /_auth/signin signs the // ".Heimdall.Auth" cookie with the "Cookies" scheme. If the default stays @@ -783,4 +798,25 @@ public partial class Program { var accept = request.Headers.Accept.ToString(); return accept.Contains("application/json", StringComparison.OrdinalIgnoreCase); } + + /// + /// Lit le toggle global sentry.enabled en base (défaut true). Table absente + /// au premier démarrage ou DB indisponible -> activé (comportement sûr). + /// + private static bool IsSentryEnabledFromDb(IServiceCollection services) + { + try + { + using var sp = services.BuildServiceProvider(); + using var scope = sp.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + return db.AppSettings.AsNoTracking() + .FirstOrDefault(s => s.Key == "sentry.enabled")?.Value != "false"; + } + catch + { + return true; + } + } + } diff --git a/src/Heimdall.Web/Services/AuthState.cs b/src/Heimdall.Web/Services/AuthState.cs index b39d0f7..f03b244 100644 --- a/src/Heimdall.Web/Services/AuthState.cs +++ b/src/Heimdall.Web/Services/AuthState.cs @@ -96,6 +96,7 @@ public record SiteItem( [property: JsonPropertyName("name")] string Name, [property: JsonPropertyName("address")] string? Address, [property: JsonPropertyName("timezone")] string Timezone, + [property: JsonPropertyName("ntfyTopic")] string? NtfyTopic, [property: JsonPropertyName("enabled")] bool Enabled, [property: JsonPropertyName("createdAt")] DateTime CreatedAt); diff --git a/src/Heimdall.Web/Services/HeimdallApiClient.cs b/src/Heimdall.Web/Services/HeimdallApiClient.cs index 94b4d97..f4747a0 100644 --- a/src/Heimdall.Web/Services/HeimdallApiClient.cs +++ b/src/Heimdall.Web/Services/HeimdallApiClient.cs @@ -265,20 +265,20 @@ public class HeimdallApiClient return await client.GetFromJsonAsync($"api/sites/{id}", Json); } - public async Task CreateSiteAsync(string name, string? address, string? timezone) + public async Task CreateSiteAsync(string name, string? address, string? timezone, string? ntfyTopic = null) { var client = CreateClient(); var response = await client.PostAsJsonAsync("api/sites", - new { name, address, timezone }, Json); + new { name, address, timezone, ntfyTopic }, Json); if (!response.IsSuccessStatusCode) return null; return await response.Content.ReadFromJsonAsync(Json); } - public async Task UpdateSiteAsync(Guid id, string name, string? address, string? timezone) + public async Task UpdateSiteAsync(Guid id, string name, string? address, string? timezone, string? ntfyTopic = null) { var client = CreateClient(); var response = await client.PutAsJsonAsync($"api/sites/{id}", - new { name, address, timezone }, Json); + new { name, address, timezone, ntfyTopic }, Json); return response.IsSuccessStatusCode; } diff --git a/src/Heimdall.Web/appsettings.json b/src/Heimdall.Web/appsettings.json index b260b45..b2df244 100644 --- a/src/Heimdall.Web/appsettings.json +++ b/src/Heimdall.Web/appsettings.json @@ -9,6 +9,6 @@ }, "AllowedHosts": "*", "Sentry": { - "Dsn": "" + "Dsn": "https://db94b9fc2f36425f9eb4b9f6f347dc73@glitchtip.tordais.cc/6" } } diff --git a/tests/Heimdall.Web.Tests/Components/Pages/DashboardTests.cs b/tests/Heimdall.Web.Tests/Components/Pages/DashboardTests.cs index c44ee9e..3676827 100644 --- a/tests/Heimdall.Web.Tests/Components/Pages/DashboardTests.cs +++ b/tests/Heimdall.Web.Tests/Components/Pages/DashboardTests.cs @@ -29,7 +29,7 @@ public class DashboardTests : PageTestBase DateTime.UtcNow)); Handler.OnGet("api/sites", new PagedData( - [new SiteItem(SiteId, "Site Principal", "12 rue des Caméras", "Europe/Paris", true, DateTime.UtcNow.AddDays(-10))], + [new SiteItem(SiteId, "Site Principal", "12 rue des Caméras", "Europe/Paris", null, true, DateTime.UtcNow.AddDays(-10))], 1, 1, 5)); Handler.OnGet("api/agents", new PagedData( diff --git a/tests/Heimdall.Web.Tests/Components/Pages/SiteDetailTests.cs b/tests/Heimdall.Web.Tests/Components/Pages/SiteDetailTests.cs index c9c6c92..95b3a60 100644 --- a/tests/Heimdall.Web.Tests/Components/Pages/SiteDetailTests.cs +++ b/tests/Heimdall.Web.Tests/Components/Pages/SiteDetailTests.cs @@ -16,7 +16,7 @@ public class SiteDetailTests : PageTestBase public void SiteDetail_AfficheInformations() { Handler.OnGet("api/sites/", new SiteItem( - SiteId, "Site Principal", "12 rue des Caméras", "Europe/Paris", true, DateTime.UtcNow.AddDays(-10))); + SiteId, "Site Principal", "12 rue des Caméras", "Europe/Paris", null, true, DateTime.UtcNow.AddDays(-10))); LoginAs(); var cut = RenderPage(p => p.Add(x => x.Id, SiteId)); @@ -45,7 +45,7 @@ public class SiteDetailTests : PageTestBase public void SiteDetail_GenererToken_AfficheDockerCompose() { Handler.OnGet("api/sites/", new SiteItem( - SiteId, "Site Principal", null, "UTC", true, DateTime.UtcNow.AddDays(-10))); + SiteId, "Site Principal", null, "UTC", null, true, DateTime.UtcNow.AddDays(-10))); Handler.On(HttpMethod.Post, "api/sites/", new TokenResult("tok-detail-42", DateTime.UtcNow.AddHours(24))); LoginAs(); @@ -67,7 +67,7 @@ public class SiteDetailTests : PageTestBase public void SiteDetail_CopierDockerCompose_AppellePressePapier() { Handler.OnGet("api/sites/", new SiteItem( - SiteId, "Site Principal", null, "UTC", true, DateTime.UtcNow.AddDays(-10))); + SiteId, "Site Principal", null, "UTC", null, true, DateTime.UtcNow.AddDays(-10))); Handler.On(HttpMethod.Post, "api/sites/", new TokenResult("tok-detail-42", DateTime.UtcNow.AddHours(24))); JSInterop.SetupVoid("navigator.clipboard.writeText", _ => true).SetVoidResult(); LoginAs(); @@ -91,7 +91,7 @@ public class SiteDetailTests : PageTestBase public void SiteDetail_NavigationCameras_Redirige() { Handler.OnGet("api/sites/", new SiteItem( - SiteId, "Site Principal", null, "UTC", true, DateTime.UtcNow.AddDays(-10))); + SiteId, "Site Principal", null, "UTC", null, true, DateTime.UtcNow.AddDays(-10))); LoginAs(); var nav = Services.GetRequiredService(); @@ -123,7 +123,7 @@ public class SiteDetailTests : PageTestBase // Routes spécifiques AVANT la route générique (le handler matche par substring). Handler.OnGet($"api/sites/{SiteId}/credentials", Array.Empty()); Handler.OnGet("api/sites/", new SiteItem( - SiteId, "Site Principal", null, "UTC", true, DateTime.UtcNow.AddDays(-10))); + SiteId, "Site Principal", null, "UTC", null, true, DateTime.UtcNow.AddDays(-10))); LoginAs(); var cut = RenderPage(p => p.Add(x => x.Id, SiteId)); @@ -141,7 +141,7 @@ public class SiteDetailTests : PageTestBase Credential("compte NVR", "nvr", DateTime.UtcNow.AddHours(-1)), }); Handler.OnGet("api/sites/", new SiteItem( - SiteId, "Site Principal", null, "UTC", true, DateTime.UtcNow.AddDays(-10))); + SiteId, "Site Principal", null, "UTC", null, true, DateTime.UtcNow.AddDays(-10))); LoginAs(); var cut = RenderPage(p => p.Add(x => x.Id, SiteId)); @@ -161,7 +161,7 @@ public class SiteDetailTests : PageTestBase { Handler.OnGet($"api/sites/{SiteId}/credentials", new List()); Handler.OnGet("api/sites/", new SiteItem( - SiteId, "Site Principal", null, "UTC", true, DateTime.UtcNow.AddDays(-10))); + SiteId, "Site Principal", null, "UTC", null, true, DateTime.UtcNow.AddDays(-10))); Handler.On(HttpMethod.Post, $"api/sites/{SiteId}/credentials", Credential("admin principal", "admin")); LoginAs(); @@ -203,7 +203,7 @@ public class SiteDetailTests : PageTestBase var cred = Credential("admin principal", "admin"); Handler.OnGet($"api/sites/{SiteId}/credentials", new List { cred }); Handler.OnGet("api/sites/", new SiteItem( - SiteId, "Site Principal", null, "UTC", true, DateTime.UtcNow.AddDays(-10))); + SiteId, "Site Principal", null, "UTC", null, true, DateTime.UtcNow.AddDays(-10))); Handler.On(HttpMethod.Delete, $"api/sites/{SiteId}/credentials/{cred.Id}", System.Net.HttpStatusCode.NoContent); LoginAs(); diff --git a/tests/Heimdall.Web.Tests/Components/Pages/SitesPageTests.cs b/tests/Heimdall.Web.Tests/Components/Pages/SitesPageTests.cs index 28ff865..5bbf194 100644 --- a/tests/Heimdall.Web.Tests/Components/Pages/SitesPageTests.cs +++ b/tests/Heimdall.Web.Tests/Components/Pages/SitesPageTests.cs @@ -12,7 +12,7 @@ public class SitesPageTests : PageTestBase private static readonly Guid SiteId = Guid.NewGuid(); private static SiteItem Site(string name = "Site Alpha") => - new(SiteId, name, "1 rue de la Surveillance", "Europe/Paris", true, DateTime.UtcNow.AddDays(-5)); + new(SiteId, name, "1 rue de la Surveillance", "Europe/Paris", null, true, DateTime.UtcNow.AddDays(-5)); [Fact] public void SitesPage_AfficheListeDesSites() diff --git a/tests/Heimdall.Web.Tests/Components/Settings/AgentDefaultsSectionTests.cs b/tests/Heimdall.Web.Tests/Components/Settings/AgentDefaultsSectionTests.cs index c275678..758d7f1 100644 --- a/tests/Heimdall.Web.Tests/Components/Settings/AgentDefaultsSectionTests.cs +++ b/tests/Heimdall.Web.Tests/Components/Settings/AgentDefaultsSectionTests.cs @@ -21,7 +21,7 @@ public class AgentDefaultsSectionTests : PageTestBase Setting("log.level", "info"), Setting("log.retentiondays", "7"), Setting("heartbeat.interval.seconds", "30"), - Setting("sentry.dsn", "***REDACTED***"), + Setting("sentry.enabled", "true"), }); LoginAs(); @@ -32,7 +32,7 @@ public class AgentDefaultsSectionTests : PageTestBase cut.Markup.ShouldContain("Niveau de log global"); cut.Markup.ShouldContain("Rétention des logs agents"); cut.Markup.ShouldContain("Intervalle de heartbeat"); - cut.Markup.ShouldContain("DSN Sentry / GlitchTip"); + cut.Markup.ShouldContain("Envoyer les erreurs vers GlitchTip"); }); } @@ -76,4 +76,26 @@ public class AgentDefaultsSectionTests : PageTestBase r.RequestUri!.AbsolutePath.Contains("heartbeat.interval.seconds", StringComparison.OrdinalIgnoreCase)); }); } + + [Fact] + public void AgentDefaults_ToggleSentry_AppellePutAvecBonneCle() + { + Handler.OnGet("api/settings", new List { Setting("sentry.enabled", "false") }); + Handler.On(HttpMethod.Put, "api/settings/sentry.enabled", System.Net.HttpStatusCode.OK); + LoginAs(); + + var cut = Render(); + cut.WaitForAssertion(() => cut.Markup.ShouldContain("Envoyer les erreurs vers GlitchTip")); + + // Le switch sentry.enabled est le seul input[type=checkbox] de la section + // (MudSwitch déclenche onchange, pas onclick) + cut.FindAll("input[type=checkbox]")[0].Change(true); + + cut.WaitForAssertion(() => + { + Handler.Requests.ShouldContain(r => + r.Method == HttpMethod.Put && + r.RequestUri!.AbsolutePath.Contains("sentry.enabled", StringComparison.OrdinalIgnoreCase)); + }); + } }