|
|
@@ -7,6 +7,7 @@ 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;
|
|
|
|
|
|
@@ -18,9 +19,7 @@ use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
|
|
|
'get' => [
|
|
|
'security' => '(is_granted("ROLE_ORGANIZATION_VIEW") or is_granted("ROLE_ORGANIZATION"))' // TODO: Comment je teste l'organisation sur une collection?
|
|
|
],
|
|
|
- 'post' => [
|
|
|
- 'security' => 'is_granted("ROLE_ORGANIZATION")'
|
|
|
- ]
|
|
|
+ 'post'
|
|
|
],
|
|
|
itemOperations: [
|
|
|
'get' => [
|
|
|
@@ -34,6 +33,7 @@ use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
|
|
|
#[ORM\Entity(repositoryClass: SubdomainRepository::class)]
|
|
|
#[OrganizationDefaultValue(fieldName: "organization")]
|
|
|
#[ApiFilter(SearchFilter::class, properties: ['subdomain' => 'exact'])]
|
|
|
+#[UniqueEntity('email')]
|
|
|
class Subdomain
|
|
|
{
|
|
|
#[ORM\Id]
|
|
|
@@ -44,7 +44,7 @@ class Subdomain
|
|
|
#[ORM\ManyToOne(inversedBy: 'subdomains')]
|
|
|
private Organization $organization;
|
|
|
|
|
|
- #[ORM\Column(length: 60, nullable: false)]
|
|
|
+ #[ORM\Column(type: 'string', length: 60, unique: true, nullable: false)]
|
|
|
#[Groups("subdomain")]
|
|
|
private string $subdomain;
|
|
|
|
|
|
@@ -92,6 +92,14 @@ class Subdomain
|
|
|
return $this->subdomain;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param string $subdomain
|
|
|
+ */
|
|
|
+ public function setSubdomain(string $subdomain): void
|
|
|
+ {
|
|
|
+ $this->subdomain = $subdomain;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return bool
|
|
|
*/
|
|
|
@@ -106,14 +114,5 @@ class Subdomain
|
|
|
public function setActive(bool $active): void
|
|
|
{
|
|
|
$this->active = $active;
|
|
|
-
|
|
|
- // Ensure it is the only active subdomain
|
|
|
- if ($active) {
|
|
|
- foreach ($this->getOrganization()->getSubdomains() as $subdomain) {
|
|
|
- if ($subdomain !== $this) {
|
|
|
- $subdomain->setActive(false);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
}
|