From fdc315d8fe4d5990d63746b3e8af1d8461b6b532 Mon Sep 17 00:00:00 2001 From: Arthur Bassi Date: Thu, 6 Aug 2026 09:47:34 -0300 Subject: [PATCH] !feat(work-orders): enforce media account scope and AddMedia freshness [SH-221] --- .../Auth/ApplicationDbContext.cs | 22 + ...38_SH221_WorkOrderAccountScope.Designer.cs | 3814 +++++++++++++++++ ...60806123838_SH221_WorkOrderAccountScope.cs | 110 + .../ApplicationDbContextModelSnapshot.cs | 27 + Data.SeaHavenIndustries/Models/WorkerOrder.cs | 4 + .../Helpers/WorkOrderBoardQueryFilters.cs | 12 + .../WorkOrderDetailDataService.cs | 16 +- .../WorkOrderMediaDataService.cs | 22 +- .../Interfaces/IWorkOrderDetailDataService.cs | 8 +- .../Interfaces/IWorkOrderMediaDataService.cs | 12 +- .../Helpers/SeaHavenClaimTypes.cs | 9 + .../Helpers/WorkOrderMediaAuthorization.cs | 28 +- .../Implementation/AuthenticationService.cs | 7 + .../Implementation/WorkOrderMediaService.cs | 34 +- .../WorkOrderPhase6Tests.cs | 183 +- docs/adr/0001-work-order-single-org-scope.md | 132 +- 16 files changed, 4308 insertions(+), 132 deletions(-) create mode 100644 Data.SeaHavenIndustries/Migrations/20260806123838_SH221_WorkOrderAccountScope.Designer.cs create mode 100644 Data.SeaHavenIndustries/Migrations/20260806123838_SH221_WorkOrderAccountScope.cs create mode 100644 SeaHaven.Services/Helpers/SeaHavenClaimTypes.cs diff --git a/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs b/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs index c8b2369..342aa88 100644 --- a/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs +++ b/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs @@ -136,6 +136,24 @@ namespace Data.SeaHavenIndustries .HasForeignKey(w => w.PrimaryDispatchId) .OnDelete(DeleteBehavior.Restrict); + builder.Entity() + .HasOne(w => w.Account) + .WithMany() + .HasForeignKey(w => w.AccountId) + .OnDelete(DeleteBehavior.Restrict); + + builder.Entity() + .HasIndex(w => w.AccountId); + + builder.Entity() + .HasOne(u => u.Account) + .WithMany() + .HasForeignKey(u => u.AccountId) + .OnDelete(DeleteBehavior.Restrict); + + builder.Entity() + .HasIndex(u => u.AccountId); + builder.Entity() .HasIndex(c => c.NormalizedName) .IsUnique(); @@ -284,6 +302,10 @@ namespace Data.SeaHavenIndustries public string? Initials { get; set; } public string? Color { get; set; } public int? Type { get; set; } // 1 for users 0 for admin + /// Optional CRM account membership for server-derived media scope (SH-221). + public int? AccountId { get; set; } + [ForeignKey(nameof(AccountId))] + public virtual Accounts? Account { get; set; } public ICollection