Thomas Fransolet 7625487806 Lot B : geler le schéma, plus sécurité rapide et calculateur de stockage
LOT B — une seule migration EF (LotB_FreezeSchema) :
- SectionMap.MapResourceId → IconResourceId. L'écart (g) de la bascule tombe
  avec. Il fallait renommer aussi la propriété de navigation MapResource :
  la convention EF l'appariait au FK, la laisser aurait fabriqué un FK
  fantôme. Elle n'était utilisée nulle part ailleurs.
- SectionEvent.ParcoursIds supprimé (champ, DTO, SectionFactory, et une
  initialisation dans un montage de test).
- Instance.IsImageWatermark remplace le `instanceId == "633ee379…"` en dur
  de ResourceController.

EF a généré un RenameColumn, pas un drop+add : les icônes déjà configurées
survivent. L'avertissement de perte de données ne porte que sur le DropColumn
de ParcoursIds, ce qui est l'intention.

Non fait, et c'était une erreur de doc : « supprimer SectionEvent.IconResourceId ».
Ce champ n'existe pas — la ligne visée appartient à la classe imbriquée
MapAnnotation, partagée par SectionEvent, SectionAgenda et SectionMap, lue par
cinq contrôleurs et par GetReferencedResourceIds. La supprimer aurait cassé
les icônes d'annotation des trois types et la collecte offline.

SÉCURITÉ (lot A, même repo) :
- AuthenticationController.Authenticate : un bloc #if DEBUG écrasait l'email
  et le mot de passe reçus par un compte de test, donc toute compilation en
  Debug authentifiait n'importe quelle saisie. Retiré.
- EnableSensitiveDataLogging (qui écrit les valeurs des paramètres dans les
  logs) passe sous #if DEBUG, l'idiome déjà employé dans Startup.cs pour le
  CORS et Hangfire. Le Dockerfile publiant en -c Release, c'est un verrou réel.

LOT C1 :
- Calculateur StoragePath/SizeBytes extrait dans Helpers/ResourceStorage.cs,
  avec 13 tests fixant l'invariant des types URL. Il ferme le lien L5 : le
  backfill (C2) et l'écart (e) de la migration appelleront le même code.
- L'extraction a révélé la divergence qu'elle devait empêcher : des deux
  chemins de création de ResourceController, le chemin multipart écrivait
  SizeBytes mais laissait StoragePath nul.

dotnet build Debug et Release verts, dotnet test 143/143 (130 + 13).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 15:32:19 +02:00

171 lines
6.2 KiB
C#

using ManagerService.DTOs;
using ManagerService.Helpers;
using NetTopologySuite.Geometries;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using static ManagerService.Data.SectionText;
namespace ManagerService.Data.SubSection
{
/// <summary>
/// Section event
/// </summary>
public class SectionEvent : Section
{
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public string? BaseSectionMapId { get; set; }
[ForeignKey(nameof(BaseSectionMapId))]
public SectionMap? BaseMap { get; set; }
public List<MapAnnotation> GlobalMapAnnotations { get; set; } = new();
public List<ProgrammeBlock> Programme { get; set; } = new();
public override string GetEmbeddableText(string language) =>
JoinText(new[]
{
BaseText(language),
StartDate.HasValue ? $"{StartDate:yyyy-MM-dd} → {EndDate:yyyy-MM-dd}" : null
}
.Concat((Programme ?? new List<ProgrammeBlock>())
.OrderBy(b => b.StartTime)
.SelectMany(b => new[]
{
Translate(b.Title, language),
Translate(b.Description, language)
}))
.Concat((GlobalMapAnnotations ?? new List<MapAnnotation>())
.Select(a => Translate(a.Label, language)))
.ToArray());
public override IEnumerable<string> GetReferencedResourceIds(string language = null) =>
BaseResourceIds()
.Concat((GlobalMapAnnotations ?? new List<MapAnnotation>())
.SelectMany(a => ResourceId(a.IconResourceId)))
.Concat((Programme ?? new List<ProgrammeBlock>())
.SelectMany(b => b.MapAnnotations ?? new List<MapAnnotation>())
.SelectMany(a => ResourceId(a.IconResourceId)));
public class ProgrammeBlock
{
[Key]
public string Id { get; set; }
[Column(TypeName = "jsonb")]
public List<TranslationDTO> Title { get; set; }
[Column(TypeName = "jsonb")]
public List<TranslationDTO> Description { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public List<MapAnnotation> MapAnnotations { get; set; }
public ProgrammeBlockDTO ToDTO()
{
return new ProgrammeBlockDTO
{
id = this.Id,
title = this.Title,
description = this.Description,
startTime = this.StartTime,
endTime = this.EndTime,
mapAnnotations = this.MapAnnotations?.Select(ma => ma.ToDTO()).ToList()
};
}
public ProgrammeBlock FromDTO(ProgrammeBlockDTO dto)
{
Title = dto.title;
Description = dto.description;
StartTime = dto.startTime;
EndTime = dto.endTime;
//MapAnnotations = dto.MapAnnotations?.Select(ma => new MapAnnotation.FromDTO(ma)).ToList() // Other method
return this;
}
}
public class MapAnnotation
{
[Key]
public string Id { get; set; }
public string? SectionEventId { get; set; } // FK for global event-level annotation (null = block annotation)
[Column(TypeName = "jsonb")]
public List<TranslationDTO> Type { get; set; } // "first_aid", "parking", etc.
[Column(TypeName = "jsonb")]
public List<TranslationDTO> Label { get; set; }
public GeometryType GeometryType { get; set; }
public Geometry Geometry { get; set; } // Peut être Point, LineString, Polygon
public string PolyColor { get; set; }
public string Icon { get; set; } // icon material if point
public string IconResourceId { get; set; } // Icon resource id
public Resource IconResource { get; set; } // Icon resource
public MapAnnotationDTO ToDTO()
{
return new MapAnnotationDTO
{
id = Id,
type = Type,
label = Label,
geometryType = GeometryType,
geometry = Geometry.ToDto(),
polyColor = PolyColor,
icon = Icon,
iconResourceId = IconResourceId,
iconResource = IconResource?.ToDTO()
};
}
public MapAnnotation FromDTO(MapAnnotationDTO dto)
{
Type = dto.type;
Label = dto.label;
GeometryType = dto.geometryType;
Geometry = dto.geometry.FromDto();
PolyColor = dto.polyColor;
Icon = dto.icon;
IconResourceId = dto.iconResourceId;
//IconResource = dto.IconResource?.ToModel()
return this;
}
}
public enum GeometryType
{
Point,
Polyline,
Circle,
Polygon
}
/*public EventDTO ToDTO()
{
return new EventDTO()
{
id = Id,
label = Label,
title = Title.ToList(),
description = Description.ToList(),
order = Order,
type = Type,
imageId = ImageId,
imageSource = ImageSource,
configurationId = ConfigurationId,
isSubSection = IsSubSection,
parentId = ParentId,
dateCreation = DateCreation,
instanceId = InstanceId,
isBeacon = IsBeacon,
beaconId = BeaconId,
latitude = Latitude,
longitude = Longitude,
meterZoneGPS = MeterZoneGPS,
};
}*/
}
}