|
|
@@ -2,9 +2,13 @@
|
|
|
|
|
|
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\Component\Serializer\Annotation\Groups;
|
|
|
+use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
|
|
|
|
|
|
/**
|
|
|
* Sous-domaine enregistré par une organisation
|
|
|
@@ -12,22 +16,24 @@ use ApiPlatform\Core\Annotation\ApiResource;
|
|
|
#[ApiResource(
|
|
|
collectionOperations: [
|
|
|
'get' => [
|
|
|
- 'security' => '(is_granted("ROLE_ORGANIZATION_VIEW") or is_granted("ROLE_ORGANIZATION")) and object.getParameters().getOrganization().getId() == user.getOrganization().getId()'
|
|
|
+ '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") and object.getParameters().getOrganization().getId() == user.getOrganization().getId()'
|
|
|
+ 'security' => 'is_granted("ROLE_ORGANIZATION")'
|
|
|
]
|
|
|
],
|
|
|
itemOperations: [
|
|
|
'get' => [
|
|
|
- 'security' => '(is_granted("ROLE_ORGANIZATION_VIEW") or is_granted("ROLE_ORGANIZATION")) and object.getParameters().getOrganization().getId() == user.getOrganization().getId()'
|
|
|
+ '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.getParameters().getOrganization().getId() == user.getOrganization().getId()'
|
|
|
+ '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'])]
|
|
|
class Subdomain
|
|
|
{
|
|
|
#[ORM\Id]
|
|
|
@@ -39,9 +45,11 @@ class Subdomain
|
|
|
private Organization $organization;
|
|
|
|
|
|
#[ORM\Column(length: 60, nullable: false)]
|
|
|
+ #[Groups("subdomain")]
|
|
|
private string $subdomain;
|
|
|
|
|
|
#[ORM\Column(options: ['default' => false])]
|
|
|
+ #[Groups("subdomain")]
|
|
|
private bool $active = false;
|
|
|
|
|
|
/**
|
|
|
@@ -109,7 +117,7 @@ class Subdomain
|
|
|
|
|
|
// Ensure it is the only active subdomain
|
|
|
if ($active) {
|
|
|
- foreach ($this->getParameters()->getSubdomains() as $subdomain) {
|
|
|
+ foreach ($this->getOrganization()->getSubdomains() as $subdomain) {
|
|
|
if ($subdomain !== $this) {
|
|
|
$subdomain->setActive(false);
|
|
|
}
|