feat(directory) : type prestataire, validateurs front, autocomplete adresse BAN
Pull Request — Quality gate / Backend (PHP CS + PHPUnit) (pull_request) Successful in 1m20s
Pull Request — Quality gate / Frontend (build) (pull_request) Successful in 1m26s

- Prestataire : entité/repo + ressource API Platform (RBAC directory.providers.*),
  ownership prestataire sur contacts/adresses/comptes-rendus (CHECK XOR à 3),
  DTO/service/drawer/fiche détail + onglet dédié dans le répertoire.
- Prospect : société uniquement (suppression du champ name, company requis) ;
  migration de backfill, conversion prospect→client et MCP adaptés.
- Champ site web sur client/prospect/prestataire (entités, DTO, onglet Information, MCP).
- Validateurs front email / téléphone FR (0549200910) / URL sur Information et Contacts,
  enregistrement bloqué tant qu'un champ est invalide.
- Autocomplete adresse branché sur la Base Adresse Nationale (api-adresse.data.gouv.fr)
  avec mode dégradé en saisie libre.
- Administration : retrait de l'onglet Clients.
This commit is contained in:
Matthieu
2026-06-24 17:55:09 +02:00
parent 052ef55c79
commit 5764d8f472
48 changed files with 1251 additions and 130 deletions
+2
View File
@@ -38,6 +38,8 @@ final class DirectoryModule implements ModuleInterface
['code' => 'directory.clients.manage', 'label' => 'Gérer les clients'],
['code' => 'directory.prospects.view', 'label' => 'Voir les prospects'],
['code' => 'directory.prospects.manage', 'label' => 'Gérer les prospects'],
['code' => 'directory.providers.view', 'label' => 'Voir les prestataires'],
['code' => 'directory.providers.manage', 'label' => 'Gérer les prestataires'],
];
}
}
+23 -6
View File
@@ -23,17 +23,17 @@ use Symfony\Component\Serializer\Attribute\Groups;
#[Auditable]
#[ApiResource(
operations: [
new GetCollection(paginationEnabled: false, security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view')"),
new Get(security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view')"),
new Post(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new Patch(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new Delete(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new GetCollection(paginationEnabled: false, security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view') or is_granted('directory.providers.view')"),
new Get(security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view') or is_granted('directory.providers.view')"),
new Post(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
new Patch(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
new Delete(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
],
normalizationContext: ['groups' => ['address:read']],
denormalizationContext: ['groups' => ['address:write']],
order: ['id' => 'ASC'],
)]
#[ApiFilter(SearchFilter::class, properties: ['client' => 'exact', 'prospect' => 'exact'])]
#[ApiFilter(SearchFilter::class, properties: ['client' => 'exact', 'prospect' => 'exact', 'prestataire' => 'exact'])]
#[ORM\Entity(repositoryClass: DoctrineAddressRepository::class)]
#[ORM\Table(name: 'directory_address')]
class Address implements TimestampableInterface, BlamableInterface
@@ -80,6 +80,11 @@ class Address implements TimestampableInterface, BlamableInterface
#[Groups(['address:read', 'address:write'])]
private ?Prospect $prospect = null;
#[ORM\ManyToOne(targetEntity: Prestataire::class)]
#[ORM\JoinColumn(name: 'prestataire_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
#[Groups(['address:read', 'address:write'])]
private ?Prestataire $prestataire = null;
public function getId(): ?int
{
return $this->id;
@@ -180,4 +185,16 @@ class Address implements TimestampableInterface, BlamableInterface
return $this;
}
public function getPrestataire(): ?Prestataire
{
return $this->prestataire;
}
public function setPrestataire(?Prestataire $prestataire): static
{
$this->prestataire = $prestataire;
return $this;
}
}
@@ -58,6 +58,10 @@ class Client implements ClientInterface, TimestampableInterface, BlamableInterfa
#[Groups(['client:read', 'client:write'])]
private ?string $phone = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['client:read', 'client:write'])]
private ?string $website = null;
/** @var Collection<int, ProjectInterface> */
#[ORM\OneToMany(targetEntity: ProjectInterface::class, mappedBy: 'client')]
private Collection $projects;
@@ -108,6 +112,18 @@ class Client implements ClientInterface, TimestampableInterface, BlamableInterfa
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite(?string $website): static
{
$this->website = $website;
return $this;
}
/** @return Collection<int, ProjectInterface> */
public function getProjects(): Collection
{
@@ -26,17 +26,17 @@ use Symfony\Component\Serializer\Attribute\Groups;
#[ApiResource(
operations: [
new GetCollection(paginationEnabled: false, security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view')"),
new Get(security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view')"),
new Post(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new Patch(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new Delete(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new GetCollection(paginationEnabled: false, security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view') or is_granted('directory.providers.view')"),
new Get(security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view') or is_granted('directory.providers.view')"),
new Post(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
new Patch(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
new Delete(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
],
normalizationContext: ['groups' => ['commercial_report:read']],
denormalizationContext: ['groups' => ['commercial_report:write']],
order: ['occurredAt' => 'DESC'],
)]
#[ApiFilter(SearchFilter::class, properties: ['client' => 'exact', 'prospect' => 'exact'])]
#[ApiFilter(SearchFilter::class, properties: ['client' => 'exact', 'prospect' => 'exact', 'prestataire' => 'exact'])]
#[ORM\Entity(repositoryClass: DoctrineCommercialReportRepository::class)]
#[ORM\Table(name: 'commercial_report')]
class CommercialReport implements TimestampableInterface
@@ -80,6 +80,11 @@ class CommercialReport implements TimestampableInterface
#[Groups(['commercial_report:read', 'commercial_report:write'])]
private ?Prospect $prospect = null;
#[ORM\ManyToOne(targetEntity: Prestataire::class)]
#[ORM\JoinColumn(name: 'prestataire_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
#[Groups(['commercial_report:read', 'commercial_report:write'])]
private ?Prestataire $prestataire = null;
/** @var Collection<int, ReportDocument> */
#[ORM\OneToMany(targetEntity: ReportDocument::class, mappedBy: 'commercialReport', cascade: ['remove'])]
#[Groups(['commercial_report:read'])]
@@ -179,6 +184,18 @@ class CommercialReport implements TimestampableInterface
return $this;
}
public function getPrestataire(): ?Prestataire
{
return $this->prestataire;
}
public function setPrestataire(?Prestataire $prestataire): static
{
$this->prestataire = $prestataire;
return $this;
}
/** @return Collection<int, ReportDocument> */
public function getDocuments(): Collection
{
+23 -6
View File
@@ -23,17 +23,17 @@ use Symfony\Component\Serializer\Attribute\Groups;
#[Auditable]
#[ApiResource(
operations: [
new GetCollection(paginationEnabled: false, security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view')"),
new Get(security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view')"),
new Post(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new Patch(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new Delete(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new GetCollection(paginationEnabled: false, security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view') or is_granted('directory.providers.view')"),
new Get(security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view') or is_granted('directory.providers.view')"),
new Post(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
new Patch(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
new Delete(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
],
normalizationContext: ['groups' => ['contact:read']],
denormalizationContext: ['groups' => ['contact:write']],
order: ['lastName' => 'ASC'],
)]
#[ApiFilter(SearchFilter::class, properties: ['client' => 'exact', 'prospect' => 'exact'])]
#[ApiFilter(SearchFilter::class, properties: ['client' => 'exact', 'prospect' => 'exact', 'prestataire' => 'exact'])]
#[ORM\Entity(repositoryClass: DoctrineContactRepository::class)]
#[ORM\Table(name: 'directory_contact')]
class Contact implements TimestampableInterface, BlamableInterface
@@ -80,6 +80,11 @@ class Contact implements TimestampableInterface, BlamableInterface
#[Groups(['contact:read', 'contact:write'])]
private ?Prospect $prospect = null;
#[ORM\ManyToOne(targetEntity: Prestataire::class)]
#[ORM\JoinColumn(name: 'prestataire_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
#[Groups(['contact:read', 'contact:write'])]
private ?Prestataire $prestataire = null;
public function getId(): ?int
{
return $this->id;
@@ -180,4 +185,16 @@ class Contact implements TimestampableInterface, BlamableInterface
return $this;
}
public function getPrestataire(): ?Prestataire
{
return $this->prestataire;
}
public function setPrestataire(?Prestataire $prestataire): static
{
$this->prestataire = $prestataire;
return $this;
}
}
@@ -0,0 +1,114 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\Module\Directory\Infrastructure\Doctrine\DoctrinePrestataireRepository;
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;
#[Auditable]
#[ApiResource(
operations: [
new GetCollection(paginationEnabled: false, security: "is_granted('directory.providers.view')"),
new Get(security: "is_granted('directory.providers.view')"),
new Post(security: "is_granted('directory.providers.manage')"),
new Patch(security: "is_granted('directory.providers.manage')"),
new Delete(security: "is_granted('directory.providers.manage')"),
],
normalizationContext: ['groups' => ['prestataire:read']],
denormalizationContext: ['groups' => ['prestataire:write']],
order: ['name' => 'ASC'],
)]
#[ORM\Entity(repositoryClass: DoctrinePrestataireRepository::class)]
#[ORM\Table(name: 'prestataire')]
class Prestataire implements TimestampableInterface, BlamableInterface
{
use TimestampableBlamableTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['prestataire:read'])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['prestataire:read', 'prestataire:write'])]
private ?string $name = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['prestataire:read', 'prestataire:write'])]
private ?string $email = null;
#[ORM\Column(length: 50, nullable: true)]
#[Groups(['prestataire:read', 'prestataire:write'])]
private ?string $phone = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['prestataire:read', 'prestataire:write'])]
private ?string $website = null;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): static
{
$this->email = $email;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): static
{
$this->phone = $phone;
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite(?string $website): static
{
$this->website = $website;
return $this;
}
}
+18 -18
View File
@@ -40,7 +40,7 @@ use Symfony\Component\Serializer\Attribute\Groups;
],
normalizationContext: ['groups' => ['prospect:read']],
denormalizationContext: ['groups' => ['prospect:write']],
order: ['name' => 'ASC'],
order: ['company' => 'ASC'],
)]
#[ApiFilter(SearchFilter::class, properties: ['status' => 'exact'])]
#[ORM\Entity(repositoryClass: DoctrineProspectRepository::class)]
@@ -57,10 +57,6 @@ class Prospect implements TimestampableInterface, BlamableInterface
#[ORM\Column(length: 255)]
#[Groups(['prospect:read', 'prospect:write'])]
private ?string $name = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['prospect:read', 'prospect:write'])]
private ?string $company = null;
#[ORM\Column(length: 255, nullable: true)]
@@ -71,6 +67,10 @@ class Prospect implements TimestampableInterface, BlamableInterface
#[Groups(['prospect:read', 'prospect:write'])]
private ?string $phone = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['prospect:read', 'prospect:write'])]
private ?string $website = null;
#[ORM\Column(type: Types::STRING, length: 32, enumType: ProspectStatus::class)]
#[Groups(['prospect:read', 'prospect:write'])]
private ProspectStatus $status = ProspectStatus::New;
@@ -93,24 +93,12 @@ class Prospect implements TimestampableInterface, BlamableInterface
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getCompany(): ?string
{
return $this->company;
}
public function setCompany(?string $company): static
public function setCompany(string $company): static
{
$this->company = $company;
@@ -141,6 +129,18 @@ class Prospect implements TimestampableInterface, BlamableInterface
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite(?string $website): static
{
$this->website = $website;
return $this;
}
public function getStatus(): ProspectStatus
{
return $this->status;
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Domain\Repository;
use App\Module\Directory\Domain\Entity\Prestataire;
interface PrestataireRepositoryInterface
{
public function findById(int $id): ?Prestataire;
/**
* @param array<string, mixed> $criteria
* @param null|array<string, string> $orderBy
*
* @return Prestataire[]
*/
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array;
}
@@ -46,9 +46,10 @@ final readonly class ConvertProspectProcessor implements ProcessorInterface
}
$client = new Client();
$client->setName($prospect->getCompany() ?: (string) $prospect->getName());
$client->setName((string) $prospect->getCompany());
$client->setEmail($prospect->getEmail());
$client->setPhone($prospect->getPhone());
$client->setWebsite($prospect->getWebsite());
$this->entityManager->persist($client);
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Doctrine;
use App\Module\Directory\Domain\Entity\Prestataire;
use App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Prestataire>
*/
final class DoctrinePrestataireRepository extends ServiceEntityRepository implements PrestataireRepositoryInterface
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Prestataire::class);
}
public function findById(int $id): ?Prestataire
{
return $this->find($id);
}
}
@@ -42,9 +42,10 @@ class ConvertProspectTool
if (null === $prospect->getConvertedClient()) {
$client = new Client();
$client->setName($prospect->getCompany() ?: (string) $prospect->getName());
$client->setName((string) $prospect->getCompany());
$client->setEmail($prospect->getEmail());
$client->setPhone($prospect->getPhone());
$client->setWebsite($prospect->getWebsite());
$this->entityManager->persist($client);
@@ -23,6 +23,7 @@ class CreateClientTool
string $name,
?string $email = null,
?string $phone = null,
?string $website = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
@@ -32,6 +33,7 @@ class CreateClientTool
$client->setName($name);
$client->setEmail($email);
$client->setPhone($phone);
$client->setWebsite($website);
$this->entityManager->persist($client);
$this->entityManager->flush();
@@ -15,7 +15,7 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(name: 'create-prospect', description: 'Create a prospect (admin). Only name is required. Status defaults to "new".')]
#[McpTool(name: 'create-prospect', description: 'Create a prospect (admin). Only company is required. Status defaults to "new".')]
class CreateProspectTool
{
public function __construct(
@@ -24,10 +24,10 @@ class CreateProspectTool
) {}
public function __invoke(
string $name,
?string $company = null,
string $company,
?string $email = null,
?string $phone = null,
?string $website = null,
?string $status = null,
?string $source = null,
?string $notes = null,
@@ -37,10 +37,10 @@ class CreateProspectTool
}
$prospect = new Prospect();
$prospect->setName($name);
$prospect->setCompany($company);
$prospect->setEmail($email);
$prospect->setPhone($phone);
$prospect->setWebsite($website);
$prospect->setSource($source);
$prospect->setNotes($notes);
@@ -33,10 +33,10 @@ class DeleteProspectTool
throw new InvalidArgumentException(sprintf('Prospect with ID %d not found.', $id));
}
$name = $prospect->getName();
$company = $prospect->getCompany();
$this->entityManager->remove($prospect);
$this->entityManager->flush();
return json_encode(['success' => true, 'message' => sprintf('Prospect "%s" deleted.', $name)]);
return json_encode(['success' => true, 'message' => sprintf('Prospect "%s" deleted.', $company)]);
}
}
@@ -37,7 +37,7 @@ class ListProspectsTool
$criteria['status'] = $statusEnum;
}
$prospects = $this->prospectRepository->findBy($criteria, ['name' => 'ASC']);
$prospects = $this->prospectRepository->findBy($criteria, ['company' => 'ASC']);
return json_encode(array_map(static fn ($prospect) => Serializer::prospect($prospect), $prospects));
}
@@ -28,6 +28,7 @@ class UpdateClientTool
?string $name = null,
?string $email = null,
?string $phone = null,
?string $website = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
@@ -47,6 +48,9 @@ class UpdateClientTool
if (null !== $phone) {
$client->setPhone($phone);
}
if (null !== $website) {
$client->setWebsite($website);
}
$this->entityManager->flush();
@@ -26,10 +26,10 @@ class UpdateProspectTool
public function __invoke(
int $id,
?string $name = null,
?string $company = null,
?string $email = null,
?string $phone = null,
?string $website = null,
?string $status = null,
?string $source = null,
?string $notes = null,
@@ -43,9 +43,6 @@ class UpdateProspectTool
throw new InvalidArgumentException(sprintf('Prospect with ID %d not found.', $id));
}
if (null !== $name) {
$prospect->setName($name);
}
if (null !== $company) {
$prospect->setCompany($company);
}
@@ -55,6 +52,9 @@ class UpdateProspectTool
if (null !== $phone) {
$prospect->setPhone($phone);
}
if (null !== $website) {
$prospect->setWebsite($website);
}
if (null !== $status) {
$statusEnum = ProspectStatus::tryFrom($status);
if (null === $statusEnum) {