فهرست منبع

various fixes and changes

Olivier Massot 3 سال پیش
والد
کامیت
904e6ecb9c
3فایلهای تغییر یافته به همراه19 افزوده شده و 13 حذف شده
  1. 5 7
      src/Commands/BindfileRefreshCommand.php
  2. 13 5
      src/Entity/Organization/Subdomain.php
  3. 1 1
      src/Service/Organization/Utils.php

+ 5 - 7
src/Commands/BindfileRefreshCommand.php

@@ -3,21 +3,19 @@
 namespace App\Commands;
 
 use Symfony\Component\Console\Attribute\AsCommand;
+use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 
 #[AsCommand(
     name: 'opentalent:bindfile-refresh',
-    description: 'Push the latest data from the Opentalent DB to dolibarr'
+    description: 'Refresh the content of /etc/bind/zones/opentalent.fr.db with the latest data from opentalent.Subdomain'
 )]
-class BindfileRefreshCommand
+class BindfileRefreshCommand extends Command
 {
-    protected function configure()
-    {
-    }
-
     protected function execute(InputInterface $input, OutputInterface $output): int
     {
-
+        throw new \RuntimeException('not implemented yet');
+        return Command::SUCCESS;
     }
 }

+ 13 - 5
src/Entity/Organization/Subdomain.php

@@ -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);
                 }

+ 1 - 1
src/Service/Organization/Utils.php

@@ -152,7 +152,7 @@ class Utils
      * @return string | null
      */
     public static function getOrganizationActiveSubdomain(Organization $organization): ?string {
-        foreach ($organization->getParameters()->getSubdomains() as $subdomain) {
+        foreach ($organization->getSubdomains() as $subdomain) {
             if ($subdomain->isActive()) {
                 return $subdomain->getSubdomain();
             }