Backend: - Add role hierarchy (ADMIN > GESTIONNAIRE > VIEWER > USER) in security.yaml - Add password authentication on profile activation (SessionProfileController) - Add SessionProfileAuthenticator with stateless API firewall - Add ProfilePasswordHasher state processor for API Platform - Add security annotations on all 18 API Platform entities - Add denyAccessUnlessGranted on all 13 custom controllers - Add AdminProfileController for profile/role management (/api/admin/profiles) - Add InitProfilePasswordsCommand for initial admin setup - Simplify SessionProfilesController to list-only (removed create/delete) Frontend (submodule update): - Add usePermissions composable (isAdmin, canEdit, canView, isGranted) - Add password login modal on profiles page - Add admin backoffice page for profile management - Disable all form fields for ROLE_VIEWER across all edit/create pages - Show navigation buttons for all roles, hide destructive actions for viewers - Add readonly mode to ModelTypeForm and site/constructeur modals - Guard /admin routes in middleware - Configure Vite proxy for API requests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
215 lines
6.1 KiB
PHP
215 lines
6.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\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 ApiPlatform\Metadata\Put;
|
|
use App\Repository\MachineComponentLinkRepository;
|
|
use DateTimeImmutable;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
#[ORM\Entity(repositoryClass: MachineComponentLinkRepository::class)]
|
|
#[ORM\Table(name: 'machine_component_links')]
|
|
#[ORM\HasLifecycleCallbacks]
|
|
#[ApiResource(
|
|
operations: [
|
|
new Get(security: "is_granted('ROLE_VIEWER')"),
|
|
new GetCollection(security: "is_granted('ROLE_VIEWER')"),
|
|
new Post(security: "is_granted('ROLE_GESTIONNAIRE')"),
|
|
new Put(security: "is_granted('ROLE_GESTIONNAIRE')"),
|
|
new Patch(security: "is_granted('ROLE_GESTIONNAIRE')"),
|
|
new Delete(security: "is_granted('ROLE_GESTIONNAIRE')"),
|
|
]
|
|
)]
|
|
class MachineComponentLink
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\Column(type: Types::STRING, length: 36)]
|
|
private ?string $id = null;
|
|
|
|
#[ORM\ManyToOne(targetEntity: Machine::class, inversedBy: 'componentLinks')]
|
|
#[ORM\JoinColumn(name: 'machineId', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
|
private Machine $machine;
|
|
|
|
#[ORM\ManyToOne(targetEntity: Composant::class, inversedBy: 'machineLinks')]
|
|
#[ORM\JoinColumn(name: 'composantId', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
|
private Composant $composant;
|
|
|
|
#[ORM\ManyToOne(targetEntity: MachineComponentLink::class, inversedBy: 'childLinks')]
|
|
#[ORM\JoinColumn(name: 'parentLinkId', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
|
|
private ?MachineComponentLink $parentLink = null;
|
|
|
|
/**
|
|
* @var Collection<int, MachineComponentLink>
|
|
*/
|
|
#[ORM\OneToMany(mappedBy: 'parentLink', targetEntity: MachineComponentLink::class)]
|
|
private Collection $childLinks;
|
|
|
|
#[ORM\ManyToOne(targetEntity: TypeMachineComponentRequirement::class, inversedBy: 'machineComponentLinks')]
|
|
#[ORM\JoinColumn(name: 'typeMachineComponentRequirementId', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
|
|
private ?TypeMachineComponentRequirement $typeMachineComponentRequirement = null;
|
|
|
|
/**
|
|
* @var Collection<int, MachinePieceLink>
|
|
*/
|
|
#[ORM\OneToMany(mappedBy: 'parentLink', targetEntity: MachinePieceLink::class)]
|
|
private Collection $pieceLinks;
|
|
|
|
/**
|
|
* @var Collection<int, MachineProductLink>
|
|
*/
|
|
#[ORM\OneToMany(mappedBy: 'parentComponentLink', targetEntity: MachineProductLink::class)]
|
|
private Collection $productLinks;
|
|
|
|
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, name: 'nameOverride')]
|
|
private ?string $nameOverride = null;
|
|
|
|
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, name: 'referenceOverride')]
|
|
private ?string $referenceOverride = null;
|
|
|
|
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true, name: 'prixOverride')]
|
|
private ?string $prixOverride = null;
|
|
|
|
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')]
|
|
private DateTimeImmutable $createdAt;
|
|
|
|
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'updatedAt')]
|
|
private DateTimeImmutable $updatedAt;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->childLinks = new ArrayCollection();
|
|
$this->pieceLinks = new ArrayCollection();
|
|
$this->productLinks = new ArrayCollection();
|
|
}
|
|
|
|
#[ORM\PrePersist]
|
|
public function setCreatedAtValue(): void
|
|
{
|
|
$now = new DateTimeImmutable();
|
|
$this->createdAt = $now;
|
|
$this->updatedAt = $now;
|
|
|
|
if (null === $this->id) {
|
|
$this->id = $this->generateCuid();
|
|
}
|
|
}
|
|
|
|
#[ORM\PreUpdate]
|
|
public function setUpdatedAtValue(): void
|
|
{
|
|
$this->updatedAt = new DateTimeImmutable();
|
|
}
|
|
|
|
public function getId(): ?string
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function setId(string $id): static
|
|
{
|
|
$this->id = $id;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getMachine(): Machine
|
|
{
|
|
return $this->machine;
|
|
}
|
|
|
|
public function setMachine(Machine $machine): static
|
|
{
|
|
$this->machine = $machine;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getComposant(): Composant
|
|
{
|
|
return $this->composant;
|
|
}
|
|
|
|
public function setComposant(Composant $composant): static
|
|
{
|
|
$this->composant = $composant;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getParentLink(): ?MachineComponentLink
|
|
{
|
|
return $this->parentLink;
|
|
}
|
|
|
|
public function setParentLink(?MachineComponentLink $parentLink): static
|
|
{
|
|
$this->parentLink = $parentLink;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getTypeMachineComponentRequirement(): ?TypeMachineComponentRequirement
|
|
{
|
|
return $this->typeMachineComponentRequirement;
|
|
}
|
|
|
|
public function setTypeMachineComponentRequirement(?TypeMachineComponentRequirement $requirement): static
|
|
{
|
|
$this->typeMachineComponentRequirement = $requirement;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getNameOverride(): ?string
|
|
{
|
|
return $this->nameOverride;
|
|
}
|
|
|
|
public function setNameOverride(?string $nameOverride): static
|
|
{
|
|
$this->nameOverride = $nameOverride;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getReferenceOverride(): ?string
|
|
{
|
|
return $this->referenceOverride;
|
|
}
|
|
|
|
public function setReferenceOverride(?string $referenceOverride): static
|
|
{
|
|
$this->referenceOverride = $referenceOverride;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPrixOverride(): ?string
|
|
{
|
|
return $this->prixOverride;
|
|
}
|
|
|
|
public function setPrixOverride(?string $prixOverride): static
|
|
{
|
|
$this->prixOverride = $prixOverride;
|
|
|
|
return $this;
|
|
}
|
|
|
|
private function generateCuid(): string
|
|
{
|
|
return 'cl'.bin2hex(random_bytes(12));
|
|
}
|
|
}
|