145d4362db
Auto Tag Develop / tag (push) Successful in 7s
## ERP-88 — Sous-ressources M2 (contacts / adresses / ribs) Étape 4/7 du pipeline M2. Dépend de #86 (entités) et #87 (Provider/Processor). Bloque #92. ### Contenu Opérations API Platform + Processors d'écriture des sous-collections du fournisseur (POST/PATCH/DELETE + GET unitaire). **SupplierContactProcessor** - Rattachement au fournisseur parent (404 si absent). - Normalisation serveur RG-2.12 (Title Case nom/prénom, téléphones chiffres seuls, email lowercase). - RG-2.04 : firstName **ou** lastName obligatoire (422 sur `firstName`). - DELETE libre (RG-2.13 front-driven : collection peut rester vide côté back). **SupplierAddressProcessor** - Rattachement au fournisseur parent. - RG-2.05 (CP `^[0-9]{4,5}$`), RG-2.06 (≥1 site), RG-2.09 (type d'adresse) portées par les contraintes d'entité (ERP-86). - RG-2.10 (catégorie de type FOURNISSEUR) ajoutée via `Assert\Callback validateCategoryType` (propertyPath=`categories`). **SupplierRibProcessor** - Rattachement au fournisseur parent. - RG-2.08 : refus du DELETE du dernier RIB quand `paymentType.code = LCR` → **409**. ### Security différenciée | Sous-ressource | Écriture | Lecture | |---|---|---| | contacts / adresses | `commercial.suppliers.manage` | `commercial.suppliers.view` | | ribs | `commercial.suppliers.accounting.manage` | `commercial.suppliers.accounting.view` | POST en `read:false` (parent rattaché manuellement) — parade NonUniqueResult héritée du M1. Messages FR (ERP-107) + `violations[].propertyPath` aligné (ERP-101). ### Vérifications - `make php-cs-fixer-allow-risky` : 0 fichier à corriger - `make test` : 483 tests OK - `debug:router` : 12 routes générées (4 par sous-ressource) ### Hors périmètre (tickets suivants) - Déclaration RBAC `commercial.suppliers.*` dans `CommercialModule` (#7) — sans elle, l'accès reste 403. - Tests fonctionnels de la matrice RG (#8) — dépendent du RBAC + fixtures Supplier. ### Notes de review (non bloquantes, alignées M1) - `position` des sous-collections non exposé à l'API (décision ERP-86, géré serveur). - M2M `SupplierAddress.contacts` non vérifié same-supplier — comportement identique au M1 (ClientAddress), à traiter globalement si besoin. --------- Co-authored-by: Matthieu <contact@malio.fr> Reviewed-on: #67 Co-authored-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr> Co-committed-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr>
239 lines
8.1 KiB
PHP
239 lines
8.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Module\Commercial\Domain\Entity;
|
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use ApiPlatform\Metadata\Delete;
|
|
use ApiPlatform\Metadata\Get;
|
|
use ApiPlatform\Metadata\Link;
|
|
use ApiPlatform\Metadata\Patch;
|
|
use ApiPlatform\Metadata\Post;
|
|
use App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor\SupplierContactProcessor;
|
|
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineSupplierContactRepository;
|
|
use App\Shared\Domain\Attribute\Auditable;
|
|
use App\Shared\Domain\Contract\BlamableInterface;
|
|
use App\Shared\Domain\Contract\TimestampableInterface;
|
|
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Serializer\Attribute\Groups;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
/**
|
|
* Contact d'un fournisseur (1:n) — onglet Contacts. Au moins firstName OU
|
|
* lastName doit etre renseigne (RG-2.04) : contrainte portee par un CHECK BDD
|
|
* (chk_supplier_contact_name) et validee au Processor (ERP-88) ; l'entite reste
|
|
* permissive (les deux champs sont nullable).
|
|
*
|
|
* Embarque sous `supplier.contacts` au detail (groupe supplier:item:read,
|
|
* maillon (a) du contrat de serialisation).
|
|
*
|
|
* Sous-ressource API (ERP-88, spec § 4.5) :
|
|
* - POST /api/suppliers/{supplierId}/contacts : creation rattachee au
|
|
* fournisseur parent (Link toProperty 'supplier'), security
|
|
* commercial.suppliers.manage.
|
|
* - PATCH / DELETE /api/supplier_contacts/{id} : security
|
|
* commercial.suppliers.manage. Le DELETE est physique et libre (pas de garde
|
|
* « dernier contact » au M2 — RG-2.13 front-driven, la collection peut rester
|
|
* vide cote back).
|
|
* - GET /api/supplier_contacts/{id} : lecture unitaire (security view) — la
|
|
* lecture courante reste via le parent (le fournisseur embarque ses contacts).
|
|
* Pas de GET collection autonome.
|
|
* Tout passe par le SupplierContactProcessor (normalisation RG-2.12, RG-2.04).
|
|
*
|
|
* Audite (#[Auditable]) + Timestampable / Blamable (pattern Shared standard).
|
|
*/
|
|
#[ApiResource(
|
|
operations: [
|
|
new Get(
|
|
security: "is_granted('commercial.suppliers.view')",
|
|
normalizationContext: ['groups' => ['supplier:item:read']],
|
|
),
|
|
new Post(
|
|
uriTemplate: '/suppliers/{supplierId}/contacts',
|
|
uriVariables: [
|
|
'supplierId' => new Link(fromClass: Supplier::class, toProperty: 'supplier'),
|
|
],
|
|
// read:false : pas de stade lecture du parent. Le Link toProperty
|
|
// resoudrait l'enfant (SELECT SupplierContact ... WHERE supplier = :id)
|
|
// et casse en NonUniqueResult des >= 2 enfants. Le parent est rattache
|
|
// manuellement par SupplierContactProcessor::linkParent (404 si absent).
|
|
read: false,
|
|
security: "is_granted('commercial.suppliers.manage')",
|
|
normalizationContext: ['groups' => ['supplier:item:read']],
|
|
denormalizationContext: ['groups' => ['supplier:write:contacts']],
|
|
processor: SupplierContactProcessor::class,
|
|
),
|
|
new Patch(
|
|
security: "is_granted('commercial.suppliers.manage')",
|
|
normalizationContext: ['groups' => ['supplier:item:read']],
|
|
denormalizationContext: ['groups' => ['supplier:write:contacts']],
|
|
processor: SupplierContactProcessor::class,
|
|
),
|
|
new Delete(
|
|
security: "is_granted('commercial.suppliers.manage')",
|
|
processor: SupplierContactProcessor::class,
|
|
),
|
|
],
|
|
)]
|
|
#[ORM\Entity(repositoryClass: DoctrineSupplierContactRepository::class)]
|
|
#[ORM\Table(name: 'supplier_contact')]
|
|
#[ORM\Index(name: 'idx_supplier_contact_supplier', columns: ['supplier_id'])]
|
|
#[Auditable]
|
|
class SupplierContact implements TimestampableInterface, BlamableInterface
|
|
{
|
|
use TimestampableBlamableTrait;
|
|
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
#[Groups(['supplier:item:read'])]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\ManyToOne(targetEntity: Supplier::class, inversedBy: 'contacts')]
|
|
#[ORM\JoinColumn(name: 'supplier_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
|
private ?Supplier $supplier = null;
|
|
|
|
// RG-2.04 : firstName OU lastName obligatoire (CHECK BDD + Processor). Les
|
|
// deux restent nullable au niveau ORM.
|
|
#[ORM\Column(length: 120, nullable: true)]
|
|
#[Assert\Length(max: 120, maxMessage: 'Le prénom ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
|
#[Groups(['supplier:item:read', 'supplier:write:contacts'])]
|
|
private ?string $firstName = null;
|
|
|
|
#[ORM\Column(length: 120, nullable: true)]
|
|
#[Assert\Length(max: 120, maxMessage: 'Le nom ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
|
#[Groups(['supplier:item:read', 'supplier:write:contacts'])]
|
|
private ?string $lastName = null;
|
|
|
|
#[ORM\Column(length: 120, nullable: true)]
|
|
#[Assert\Length(max: 120, maxMessage: 'La fonction ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
|
#[Groups(['supplier:item:read', 'supplier:write:contacts'])]
|
|
private ?string $jobTitle = null;
|
|
|
|
// RG : pas de validation de format telephone (saisie libre), mais une
|
|
// Assert\Length calee sur la colonne VARCHAR(20) evite l'erreur Postgres
|
|
// (500 non rattachee au champ) au profit d'une 422 propre (ERP-107).
|
|
#[ORM\Column(length: 20, nullable: true)]
|
|
#[Assert\Length(max: 20, maxMessage: 'Le téléphone ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
|
#[Groups(['supplier:item:read', 'supplier:write:contacts'])]
|
|
private ?string $phonePrimary = null;
|
|
|
|
#[ORM\Column(length: 20, nullable: true)]
|
|
#[Assert\Length(max: 20, maxMessage: 'Le téléphone secondaire ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
|
#[Groups(['supplier:item:read', 'supplier:write:contacts'])]
|
|
private ?string $phoneSecondary = null;
|
|
|
|
#[ORM\Column(length: 180, nullable: true)]
|
|
#[Assert\Email(message: 'L\'adresse email n\'est pas valide.')]
|
|
#[Assert\Length(max: 180, maxMessage: 'L\'email ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
|
#[Groups(['supplier:item:read', 'supplier:write:contacts'])]
|
|
private ?string $email = null;
|
|
|
|
// Ordre d'affichage du contact (gere serveur, non expose au M2).
|
|
#[ORM\Column(options: ['default' => 0])]
|
|
private int $position = 0;
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getSupplier(): ?Supplier
|
|
{
|
|
return $this->supplier;
|
|
}
|
|
|
|
public function setSupplier(?Supplier $supplier): static
|
|
{
|
|
$this->supplier = $supplier;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFirstName(): ?string
|
|
{
|
|
return $this->firstName;
|
|
}
|
|
|
|
public function setFirstName(?string $firstName): static
|
|
{
|
|
$this->firstName = $firstName;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getLastName(): ?string
|
|
{
|
|
return $this->lastName;
|
|
}
|
|
|
|
public function setLastName(?string $lastName): static
|
|
{
|
|
$this->lastName = $lastName;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getJobTitle(): ?string
|
|
{
|
|
return $this->jobTitle;
|
|
}
|
|
|
|
public function setJobTitle(?string $jobTitle): static
|
|
{
|
|
$this->jobTitle = $jobTitle;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPhonePrimary(): ?string
|
|
{
|
|
return $this->phonePrimary;
|
|
}
|
|
|
|
public function setPhonePrimary(?string $phonePrimary): static
|
|
{
|
|
$this->phonePrimary = $phonePrimary;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPhoneSecondary(): ?string
|
|
{
|
|
return $this->phoneSecondary;
|
|
}
|
|
|
|
public function setPhoneSecondary(?string $phoneSecondary): static
|
|
{
|
|
$this->phoneSecondary = $phoneSecondary;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getEmail(): ?string
|
|
{
|
|
return $this->email;
|
|
}
|
|
|
|
public function setEmail(?string $email): static
|
|
{
|
|
$this->email = $email;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPosition(): int
|
|
{
|
|
return $this->position;
|
|
}
|
|
|
|
public function setPosition(int $position): static
|
|
{
|
|
$this->position = $position;
|
|
|
|
return $this;
|
|
}
|
|
}
|