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

183 lines
6.4 KiB
C#

using Manager.DTOs;
using ManagerService.DTOs;
using ManagerService.Helpers;
using NetTopologySuite.Geometries;
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 map
/// </summary>
public class SectionMap : Section
{
public int MapZoom { get; set; } // Default = 18
public bool IsListViewEnabled { get; set; } = false;
public MapTypeApp? MapMapType { get; set; } // Default = Hybrid for Google
public MapTypeMapBox? MapTypeMapbox { get; set; } // Default = standard for MapBox
public MapProvider? MapMapProvider { get; set; } // Default = Google
public List<GeoPoint> MapPoints { get; set; }
public string IconResourceId { get; set; }
public Resource IconResource { get; set; } // Icon
[Required]
[Column(TypeName = "jsonb")]
public List<CategorieDTO> MapCategories { get; set; }
public string MapCenterLatitude { get; set; } // Center on
public string MapCenterLongitude { get; set; } // Center on
public override string GetEmbeddableText(string language) =>
JoinText(new[] { BaseText(language) }
.Concat((MapCategories ?? new List<CategorieDTO>())
.OrderBy(c => c.order ?? 0)
.Select(c => Translate(c.label, language)))
.Concat((MapPoints ?? new List<GeoPoint>())
.Select(p => p.GetEmbeddableText(language)))
.ToArray());
public override IEnumerable<string> GetReferencedResourceIds(string language = null) =>
BaseResourceIds()
.Concat(ResourceId(IconResourceId))
.Concat((MapCategories ?? new List<CategorieDTO>())
.SelectMany(c => ResourceId(c.resourceDTO?.id)))
.Concat((MapPoints ?? new List<GeoPoint>())
.SelectMany(p => p.GetReferencedResourceIds()));
public MapDTO ToDTO()
{
return new MapDTO()
{
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,
zoom = MapZoom,
mapType = MapMapType,
mapTypeMapbox = MapTypeMapbox,
mapProvider = MapMapProvider,
iconResourceId = IconResourceId,
categories = MapCategories,
centerLatitude = MapCenterLatitude,
centerLongitude = MapCenterLongitude
};
}
}
public class GeoPoint
{
[Required]
public int? Id { get; set; }
[Required]
[Column(TypeName = "jsonb")]
public List<TranslationDTO> Title { get; set; }
[Required]
[Column(TypeName = "jsonb")]
public List<TranslationDTO> Description { get; set; }
[Required]
[Column(TypeName = "jsonb")]
public List<ContentDTO> Contents { get; set; }
public int? CategorieId { get; set; }
public Geometry Geometry { get; set; }
public string PolyColor { get; set; } // color of the polyline or polygon
public string ImageResourceId { get; set; }
public string ImageUrl { get; set; }
[Required]
[Column(TypeName = "jsonb")]
public List<TranslationDTO> Schedules { get; set; }
[Required]
[Column(TypeName = "jsonb")]
public List<TranslationDTO> Prices { get; set; }
[Required]
[Column(TypeName = "jsonb")]
public List<TranslationDTO> Phone { get; set; }
[Required]
[Column(TypeName = "jsonb")]
public List<TranslationDTO> Email { get; set; }
[Required]
[Column(TypeName = "jsonb")]
public List<TranslationDTO> Site { get; set; }
public string? SectionMapId { get; set; }
[ForeignKey(nameof(SectionMapId))]
public SectionMap? SectionMap { get; set; }
public string? SectionEventId { get; set; }
[ForeignKey(nameof(SectionEventId))]
public SectionEvent? SectionEvent { get; set; }
public string GetEmbeddableText(string language) =>
JoinText(Translate(Title, language),
Translate(Description, language),
TranslateContents(Contents, language),
Translate(Schedules, language),
Translate(Prices, language),
Translate(Phone, language),
Translate(Email, language),
Translate(Site, language));
public IEnumerable<string> GetReferencedResourceIds() =>
ResourceId(ImageResourceId).Concat(ResourceIds(Contents));
public GeoPointDTO ToDTO()
{
return new GeoPointDTO
{
id = Id,
title = Title,
description = Description,
contents = Contents,
categorieId = CategorieId,
geometry = Geometry != null ? Geometry.ToDto() : null,
polyColor = PolyColor,
imageResourceId = ImageResourceId,
imageUrl = ImageUrl,
schedules = Schedules,
prices = Prices,
phone = Phone,
email = Email,
site = Site,
sectionMapId = SectionMapId,
sectionEventId = SectionEventId
};
}
}
// SectionMap "normal" comme avant => Via geopoints. Si il y a des guidedPath lié à la sectionMap alors il y a un parcours lié à la sectionMap, tu peux aussi avoir des geopoints classique mis là + des parcours. et aussi lier un guidedstep à un geopoint (pour le trigger et aussi pour "afficher plus")
}