fix(commercial) : corrige le contrat de sérialisation du répertoire clients (ERP-80/81/82/83) (#45)
Auto Tag Develop / tag (push) Successful in 7s
Auto Tag Develop / tag (push) Successful in 7s
## Contexte
Correctifs des 4 bugs de contrat de sérialisation du répertoire clients M1, révélés par la capture du JSON réel le 02/06/2026 (cf. `docs/specs/M2-suppliers/spec-back.md` § 4.0.ter). Tous étaient des oublis **silencieux** (aucune erreur levée).
## Changements
- **ERP-80 — Fuite RIB (sécurité)** : `Client::getRibs()` et les propriétés de `ClientRib` passent sous le groupe gaté `client:read:accounting` (ajouté au contexte par `ClientReadGroupContextBuilder` uniquement si `accounting.view`). La clé `ribs` est désormais **absente** du détail pour la Commerciale. La sous-ressource autonome `/api/client_ribs/{id}` conserve `client_rib:read` (écriture/PATCH intacts).
- **ERP-81 — Booléens d'adresse** : `#[Groups]` + `#[SerializedName]` portés sur les **getters** `isProspect()/isDelivery()/isBilling()` (le getter booléen strippait le préfixe `is` et droppait la clé — même pattern que `Client::isArchived`).
- **ERP-82 — Embed Category/Site** : `category:read` + `site:read` ajoutés au `normalizationContext` du `Get` Client → `categories[].code/.name` et `addresses[].sites[].name` embarqués.
- **ERP-83 — Tests anti-régression** : nouveau `ClientSerializationContractTest` (7 tests, 64 assertions) assertant sur le **corps JSON réel**.
## Dépendance signalée
⚠️ L'entité **`Site` n'a pas de champ `code`** (ni `SiteInterface`) — son libellé est `name`. Les « codes 86/17/82 » de la spec M2 sont en réalité le préfixe du code postal des sites fixtures. À planifier côté module Sites si un `Site.code` est requis (notamment pour `getSiteCodes()` au M2).
## Vérifications
- `make test` : **460 tests, 1535 assertions, exit 0** ✅
- `make php-cs-fixer-allow-risky` : 0 fix ✅
- Capture JSON réelle AVANT/APRÈS (client 6 TRANSPORTS RAPIDES) :
- **Admin** : `ribs` présents, `siren`/`accountNumber`/`nTva` présents, `categories[].code/.name` + `addresses[].sites[].name` embarqués, booléens d'adresse présents.
- **Commerciale** : `ribs` **absent**, scalaires comptables **absents** (omission), embed Category/Site + booléens visibles.
Tickets : ERP-80, ERP-81, ERP-82, ERP-83 (passés « En review »).
---------
Co-authored-by: admin malio <malio@yuno.malio.fr>
Co-authored-by: Matthieu <contact@malio.fr>
Reviewed-on: #45
Co-authored-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr>
Co-committed-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr>
This commit was merged in pull request #45.
This commit is contained in:
@@ -22,6 +22,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
@@ -104,16 +105,23 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
||||
#[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
||||
private ?Client $client = null;
|
||||
|
||||
// Groupe d'ECRITURE uniquement sur la propriete (denormalisation PATCH/POST).
|
||||
// Le groupe de LECTURE est porte par le getter isProspect()/isDelivery()/
|
||||
// isBilling() avec SerializedName : sans cela, Symfony strip le prefixe "is"
|
||||
// des getters booleens et exposerait les cles "prospect"/"delivery"/"billing"
|
||||
// — en pratique le #[Groups] etant sur la propriete `isX` et le getter
|
||||
// derivant l'attribut `x`, la cle etait totalement DROPPEE du JSON (meme bug
|
||||
// que Client::isArchived). Pattern corrige : Groups + SerializedName sur le getter.
|
||||
#[ORM\Column(name: 'is_prospect', options: ['default' => false])]
|
||||
#[Groups(['client_address:read', 'client_address:write'])]
|
||||
#[Groups(['client_address:write'])]
|
||||
private bool $isProspect = false;
|
||||
|
||||
#[ORM\Column(name: 'is_delivery', options: ['default' => false])]
|
||||
#[Groups(['client_address:read', 'client_address:write'])]
|
||||
#[Groups(['client_address:write'])]
|
||||
private bool $isDelivery = false;
|
||||
|
||||
#[ORM\Column(name: 'is_billing', options: ['default' => false])]
|
||||
#[Groups(['client_address:read', 'client_address:write'])]
|
||||
#[Groups(['client_address:write'])]
|
||||
private bool $isBilling = false;
|
||||
|
||||
#[ORM\Column(length: 80, options: ['default' => 'France'])]
|
||||
@@ -276,6 +284,12 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Groupe de lecture + nom serialise explicite (cf. note sur la propriete) :
|
||||
// sans SerializedName, Symfony exposerait la cle "prospect" (strip du prefixe
|
||||
// "is" sur les getters) et, le groupe etant declare sur la propriete `isProspect`,
|
||||
// droppait silencieusement la cle du JSON.
|
||||
#[Groups(['client_address:read'])]
|
||||
#[SerializedName('isProspect')]
|
||||
public function isProspect(): bool
|
||||
{
|
||||
return $this->isProspect;
|
||||
@@ -288,6 +302,8 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
#[Groups(['client_address:read'])]
|
||||
#[SerializedName('isDelivery')]
|
||||
public function isDelivery(): bool
|
||||
{
|
||||
return $this->isDelivery;
|
||||
@@ -300,6 +316,8 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
#[Groups(['client_address:read'])]
|
||||
#[SerializedName('isBilling')]
|
||||
public function isBilling(): bool
|
||||
{
|
||||
return $this->isBilling;
|
||||
|
||||
Reference in New Issue
Block a user