From 87ab281099d26fa13a9dd9bc537eb38cae5ce2db Mon Sep 17 00:00:00 2001 From: matthieu Date: Sun, 15 Mar 2026 19:23:10 +0100 Subject: [PATCH] feat : extend User entity with client and allowedProjects Co-Authored-By: Claude Sonnet 4.6 --- src/Entity/User.php | 54 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/src/Entity/User.php b/src/Entity/User.php index 5080d65..ea17f47 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -14,6 +14,8 @@ use App\Repository\UserRepository; use App\State\MeProvider; use App\State\UserPasswordHasherProcessor; use DateTimeImmutable; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; @@ -46,11 +48,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] - #[Groups(['me:read', 'task:read', 'user:list', 'time_entry:read'])] + #[Groups(['me:read', 'task:read', 'user:list', 'time_entry:read', 'client_ticket:read'])] private ?int $id = null; #[ORM\Column(length: 180, unique: true)] - #[Groups(['me:read', 'task:read', 'user:list', 'user:write', 'time_entry:read'])] + #[Groups(['me:read', 'task:read', 'user:list', 'user:write', 'time_entry:read', 'client_ticket:read'])] private ?string $username = null; /** @var list */ @@ -65,9 +67,21 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(type: Types::DATETIME_IMMUTABLE)] private ?DateTimeImmutable $createdAt = null; + #[ORM\ManyToOne(targetEntity: Client::class)] + #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')] + #[Groups(['me:read', 'user:list', 'user:write'])] + private ?Client $client = null; + + /** @var Collection */ + #[ORM\ManyToMany(targetEntity: Project::class)] + #[ORM\JoinTable(name: 'user_allowed_projects')] + #[Groups(['me:read', 'user:list', 'user:write'])] + private Collection $allowedProjects; + public function __construct() { - $this->createdAt = new DateTimeImmutable(); + $this->createdAt = new DateTimeImmutable(); + $this->allowedProjects = new ArrayCollection(); } public function getId(): ?int @@ -136,5 +150,39 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + public function getClient(): ?Client + { + return $this->client; + } + + public function setClient(?Client $client): static + { + $this->client = $client; + + return $this; + } + + /** @return Collection */ + public function getAllowedProjects(): Collection + { + return $this->allowedProjects; + } + + public function addAllowedProject(Project $project): static + { + if (!$this->allowedProjects->contains($project)) { + $this->allowedProjects->add($project); + } + + return $this; + } + + public function removeAllowedProject(Project $project): static + { + $this->allowedProjects->removeElement($project); + + return $this; + } + public function eraseCredentials(): void {} }