feat(commercial) : enforce address validations RG-1.06/07/08/11/29 → 422
Mirror applicatif des CHECK Postgres d'adresse via Assert\Callback sur ClientAddress, joue avant la base pour remonter une 422 Hydra au lieu d'une 500 DBAL, et durcit RG-1.29 (categorie d'adresse limitee a SECTEUR/AUTRE) : - validateProspectExclusivity : isProspect exclusif de isDelivery/isBilling (RG-1.06/07/08, mirror chk_client_address_prospect_exclusive). - validateBillingEmailPresence : billingEmail obligatoire ssi isBilling (RG-1.11, mirror chk_client_address_billing_email). - validateCategoryTypes : refuse une categorie DISTRIBUTEUR/COURTIER sur une adresse (RG-1.29, violation 'categories'), via CategoryInterface. Les CHECK BDD restent en filet de securite. Tests ClientAddressTest durcis de >= 400 vers 422 explicite + 4 cas RG-1.29. Cahier de test M1 mis a jour.
This commit is contained in:
@@ -23,19 +23,23 @@ use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
* Adresse d'un client (1:n) — onglet Adresse. Une adresse de prospection
|
||||
* (isProspect) est exclusive d'une adresse de livraison/facturation
|
||||
* (RG-1.06/07/08, CHECK BDD). Un email de facturation est obligatoire ssi
|
||||
* isBilling (RG-1.11, CHECK BDD). Au moins un site doit etre rattache
|
||||
* (RG-1.10, Assert\Count).
|
||||
* (RG-1.06/07/08). Un email de facturation est obligatoire ssi isBilling
|
||||
* (RG-1.11). Au moins un site doit etre rattache (RG-1.10, Assert\Count). Ces
|
||||
* regles sont portees par des Assert\Callback (cf. validateProspectExclusivity /
|
||||
* validateBillingEmailPresence, ERP-76) qui remontent une 422 avant la base ;
|
||||
* les CHECK Postgres (chk_client_address_prospect_exclusive /
|
||||
* chk_client_address_billing_email) restent en filet de securite.
|
||||
*
|
||||
* Relations M2M :
|
||||
* - sites : SiteInterface (module Sites) via resolve_target_entities
|
||||
* - contacts : ClientContact (meme module)
|
||||
* - categories : CategoryInterface (module Catalog) via resolve_target_entities
|
||||
* — limitees aux types SECTEUR/AUTRE cote validation (RG-1.29, hors ERP-57)
|
||||
* — limitees aux types SECTEUR/AUTRE (RG-1.29, validateCategoryTypes, ERP-76)
|
||||
*
|
||||
* Audite (#[Auditable]) + Timestampable/Blamable.
|
||||
*
|
||||
@@ -83,6 +87,9 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
||||
{
|
||||
use TimestampableBlamableTrait;
|
||||
|
||||
/** RG-1.29 : seuls ces types de categorie qualifient une adresse physique. */
|
||||
private const array ALLOWED_CATEGORY_TYPES = ['SECTEUR', 'AUTRE'];
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
@@ -130,7 +137,7 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
||||
#[Groups(['client_address:read', 'client_address:write'])]
|
||||
private ?string $streetComplement = null;
|
||||
|
||||
// RG-1.11 : obligatoire ssi isBilling (CHECK BDD + futur Processor).
|
||||
// RG-1.11 : obligatoire ssi isBilling (validateBillingEmailPresence + CHECK BDD).
|
||||
#[ORM\Column(length: 180, nullable: true)]
|
||||
#[Assert\Email]
|
||||
#[Groups(['client_address:read', 'client_address:write'])]
|
||||
@@ -158,7 +165,7 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
||||
#[Groups(['client_address:read', 'client_address:write'])]
|
||||
private Collection $contacts;
|
||||
|
||||
// RG-1.29 : categories de type SECTEUR/AUTRE uniquement (filtre au Processor).
|
||||
// RG-1.29 : categories de type SECTEUR/AUTRE uniquement (validateCategoryTypes).
|
||||
/** @var Collection<int, CategoryInterface> */
|
||||
#[ORM\ManyToMany(targetEntity: CategoryInterface::class)]
|
||||
#[ORM\JoinTable(name: 'client_address_category')]
|
||||
@@ -174,6 +181,69 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
||||
$this->categories = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* RG-1.06 / RG-1.07 / RG-1.08 : une adresse de prospection est exclusive
|
||||
* d'une adresse de livraison ou de facturation. Mirror applicatif (422) du
|
||||
* CHECK chk_client_address_prospect_exclusive, joue avant la base afin de
|
||||
* remonter une violation Hydra plutot qu'une 500 DBAL.
|
||||
*/
|
||||
#[Assert\Callback]
|
||||
public function validateProspectExclusivity(ExecutionContextInterface $context): void
|
||||
{
|
||||
if ($this->isProspect && ($this->isDelivery || $this->isBilling)) {
|
||||
$context->buildViolation('Une adresse de prospection ne peut pas être une adresse de livraison ni de facturation.')
|
||||
->atPath('isProspect')
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* RG-1.11 : l'email de facturation est obligatoire si l'adresse est de
|
||||
* facturation, et interdit sinon. Mirror applicatif (422) du CHECK
|
||||
* chk_client_address_billing_email.
|
||||
*/
|
||||
#[Assert\Callback]
|
||||
public function validateBillingEmailPresence(ExecutionContextInterface $context): void
|
||||
{
|
||||
if ($this->isBilling && null === $this->billingEmail) {
|
||||
$context->buildViolation('L\'email de facturation est obligatoire pour une adresse de facturation.')
|
||||
->atPath('billingEmail')
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
|
||||
if (!$this->isBilling && null !== $this->billingEmail) {
|
||||
$context->buildViolation('L\'email de facturation n\'est autorisé que sur une adresse de facturation.')
|
||||
->atPath('billingEmail')
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* RG-1.29 : seules les categories de type SECTEUR / AUTRE qualifient une
|
||||
* adresse physique. Les types DISTRIBUTEUR / COURTIER decrivent une relation
|
||||
* entre clients (RG-1.03) et n'ont pas de sens sur une adresse -> 422 avec
|
||||
* violation sur le champ `categories`. S'appuie sur
|
||||
* CategoryInterface::getCategoryTypeCode() (pas d'import du module Catalog).
|
||||
*/
|
||||
#[Assert\Callback]
|
||||
public function validateCategoryTypes(ExecutionContextInterface $context): void
|
||||
{
|
||||
foreach ($this->categories as $category) {
|
||||
if ($category instanceof CategoryInterface
|
||||
&& !in_array($category->getCategoryTypeCode(), self::ALLOWED_CATEGORY_TYPES, true)) {
|
||||
$context->buildViolation('Type de catégorie non autorisé sur une adresse.')
|
||||
->atPath('categories')
|
||||
->addViolation()
|
||||
;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
|
||||
Reference in New Issue
Block a user