src/Entity/Vault.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use App\Traits\Timestamps;
  4. use App\Repository\VaultRepository;
  5. use App\Service\EncryptionService;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. #[ORM\Entity(repositoryClassVaultRepository::class)]
  11. #[ORM\Table(name'vault')]
  12. #[ORM\HasLifecycleCallbacks]
  13. class Vault
  14. {
  15.     use Timestamps;
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     private ?int $id null;
  20.     #[ORM\Column(length255)]
  21.     private ?string $projectName null;
  22.     #[ORM\Column(length255)]
  23.     private ?string $login null;
  24.     #[ORM\Column(length1000)]
  25.     private ?string $password null;
  26.     #[ORM\Column(length255nullabletrue)]
  27.     private ?string $url null;
  28.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  29.     private ?string $note null;
  30.     #[ORM\ManyToMany(targetEntityUser::class, inversedBy'vaults')]
  31.     private Collection $authorizedUsers;
  32.     public function __construct()
  33.     {
  34.         $this->authorizedUsers = new ArrayCollection();
  35.     }
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function getProjectName(): ?string
  41.     {
  42.         return $this->projectName;
  43.     }
  44.     public function setProjectName(string $projectName): self
  45.     {
  46.         $this->projectName $projectName;
  47.         return $this;
  48.     }
  49.     public function getLogin(): ?string
  50.     {
  51.         return $this->login;
  52.     }
  53.     public function setLogin(string $login): self
  54.     {
  55.         $this->login $login;
  56.         return $this;
  57.     }
  58.     public function getPassword(): ?string
  59.     {
  60.         return $this->password;
  61.     }
  62.     public function setPassword(string $password): self
  63.     {
  64.         $this->password $password;
  65.         return $this;
  66.     }
  67.     public function getUrl(): ?string
  68.     {
  69.         return $this->url;
  70.     }
  71.     public function setUrl(?string $url): self
  72.     {
  73.         $this->url $url;
  74.         return $this;
  75.     }
  76.     public function getNote(): ?string
  77.     {
  78.         return $this->note;
  79.     }
  80.     public function setNote(?string $note): self
  81.     {
  82.         $this->note $note;
  83.         return $this;
  84.     }
  85.     /**
  86.      * @return Collection<int, User>
  87.      */
  88.     public function getAuthorizedUsers(): Collection
  89.     {
  90.         return $this->authorizedUsers;
  91.     }
  92.     public function addAuthorizedUser(User $user): self
  93.     {
  94.         if (!$this->authorizedUsers->contains($user)) {
  95.             $this->authorizedUsers->add($user);
  96.         }
  97.         return $this;
  98.     }
  99.     public function removeAuthorizedUser(User $user): self
  100.     {
  101.         $this->authorizedUsers->removeElement($user);
  102.         return $this;
  103.     }
  104.     public function hasAccess(User $user): bool
  105.     {
  106.         // Admin always has access
  107.         if ($user->hasRole('ROLE_SUPERUSER') || $user->hasRole('ROLE_ADMINISTRATOR')) {
  108.             return true;
  109.         }
  110.         
  111.         // Check if user is in the authorized list
  112.         return $this->authorizedUsers->contains($user);
  113.     }
  114. }