| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace App\Entity\Organization;
- use ApiPlatform\Core\Annotation\ApiFilter;
- use App\Annotation\OrganizationDefaultValue;
- use App\Repository\Organization\SubdomainRepository;
- use Doctrine\ORM\Mapping as ORM;
- use ApiPlatform\Core\Annotation\ApiResource;
- use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
- use Symfony\Component\Serializer\Annotation\Groups;
- use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
- /**
- * Sous-domaine enregistré par une organisation
- */
- #[ApiResource(
- collectionOperations: [
- 'get' => [
- 'security' => '(is_granted("ROLE_ORGANIZATION_VIEW") or is_granted("ROLE_ORGANIZATION"))' // TODO: Comment je teste l'organisation sur une collection?
- ],
- 'post'
- ],
- itemOperations: [
- 'get' => [
- 'security' => '(is_granted("ROLE_ORGANIZATION_VIEW") or is_granted("ROLE_ORGANIZATION")) and object.getOrganization().getId() == user.getOrganization().getId()'
- ],
- 'put' => [
- 'security' => 'is_granted("ROLE_ORGANIZATION") and object.getOrganization().getId() == user.getOrganization().getId()'
- ]
- ]
- )]
- #[ORM\Entity(repositoryClass: SubdomainRepository::class)]
- #[OrganizationDefaultValue(fieldName: "organization")]
- #[ApiFilter(SearchFilter::class, properties: ['subdomain' => 'exact'])]
- #[UniqueEntity('subdomain')]
- class Subdomain
- {
- #[ORM\Id]
- #[ORM\Column]
- #[ORM\GeneratedValue]
- private ?int $id = null;
- #[ORM\ManyToOne(inversedBy: 'subdomains')]
- private Organization $organization;
- #[ORM\Column(type: 'string', length: 60, unique: true, nullable: false)]
- #[Groups("subdomain")]
- private string $subdomain;
- #[ORM\Column(options: ['default' => false])]
- #[Groups("subdomain")]
- private bool $active = false;
- /**
- * @return int|null
- */
- public function getId(): ?int
- {
- return $this->id;
- }
- /**
- * @param int|null $id
- */
- public function setId(?int $id): void
- {
- $this->id = $id;
- }
- /**
- * @return Organization
- */
- public function getOrganization(): Organization
- {
- return $this->organization;
- }
- /**
- * @param Organization $organization
- */
- public function setOrganization(Organization $organization): void
- {
- $this->organization = $organization;
- }
- /**
- * @return string
- */
- public function getSubdomain(): string
- {
- return $this->subdomain;
- }
- /**
- * @param string $subdomain
- */
- public function setSubdomain(string $subdomain): void
- {
- $this->subdomain = $subdomain;
- }
- /**
- * @return bool
- */
- public function isActive(): bool
- {
- return $this->active;
- }
- /**
- * @param bool $active
- */
- public function setActive(bool $active): void
- {
- $this->active = $active;
- }
- }
|