Selaa lähdekoodia

ajout par défaut lors de la création du profil

Vincent 1 vuosi sitten
vanhempi
commit
9087cbb5ea

+ 1 - 1
config/packages/nelmio_cors.yaml

@@ -1,7 +1,7 @@
 nelmio_cors:
     defaults:
         origin_regex: true
-        allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
+        allow_origin: ['*']
         allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
         allow_headers: ['Content-Type', 'Authorization', 'x-accessid', 'x-switch-user', 'profileHash']
         expose_headers: ['Link']

+ 15 - 8
src/ApiResources/Profile/AccessProfile.php

@@ -83,6 +83,9 @@ class AccessProfile implements ApiResourcesInterface
     #[Groups('access_profile_read')]
     private ?AccessProfile $originalAccess = null;
 
+    #[Groups('access_profile_read')]
+    private ?int $accessPreferenceId = null;
+
     #[Pure]
     public function __construct()
     {
@@ -298,23 +301,27 @@ class AccessProfile implements ApiResourcesInterface
         return $this;
     }
 
-    /**
-     * @return bool[]
-     */
     public function getHistorical(): array
     {
         return $this->historical;
     }
 
-    /**
-     * @param bool[] $historical
-     *
-     * @return $this
-     */
     public function setHistorical(array $historical): self
     {
         $this->historical = $historical;
 
         return $this;
     }
+
+    public function getAccessPreferenceId(): ?int
+    {
+        return $this->accessPreferenceId;
+    }
+
+    public function setAccessPreferenceId(?int $accessPreferenceId): self
+    {
+        $this->accessPreferenceId = $accessPreferenceId;
+
+        return $this;
+    }
 }

+ 20 - 2
src/Service/Access/AccessProfileCreator.php

@@ -6,9 +6,10 @@ namespace App\Service\Access;
 
 use App\ApiResources\Profile\AccessProfile;
 use App\Entity\Access\Access;
+use App\Entity\Access\AccessPreference;
 use App\Repository\Access\AccessRepository;
 use App\Service\Organization\OrganizationProfileCreator;
-use App\Test\Service\Access\AccessProfileCreatorTest;
+use Doctrine\ORM\EntityManagerInterface;
 use Symfony\Component\Security\Core\Exception\AuthenticationException;
 
 /**
@@ -20,6 +21,7 @@ class AccessProfileCreator
         private readonly OrganizationProfileCreator $organizationProfileCreator,
         private readonly AccessRepository $accessRepository,
         private readonly Utils $accessUtils,
+        private readonly EntityManagerInterface $entityManager
     ) {
     }
 
@@ -37,6 +39,10 @@ class AccessProfileCreator
             throw new AuthenticationException('no_valid_access', 401);
         }
 
+        if(is_null($access->getPreferences())){
+            $this->createAccessPrefence($access);
+        }
+
         // L'Access en paramètre est celui de la connexion
         $mainAccessProfile = $this->createCompleteAccessProfile($access);
 
@@ -102,6 +108,18 @@ class AccessProfileCreator
             ->setIsSuperAdminAccess($access->getSuperAdminAccess())
             ->setOrganization(
                 $this->organizationProfileCreator->createLightOrganizationProfile($access->getOrganization())
-            );
+            )
+            ->setAccessPreferenceId($access->getPreferences()->getId());
+    }
+
+    /**
+     * Créer l'entrée des AccessPreference en base
+     * @see AccessProfileCreatorTest::testCreateAccessPreference()
+     * @param Access $access
+     * @return void
+     */
+    public function createAccessPrefence(Access $access){
+        $access->setPreferences(new AccessPreference());
+        $this->entityManager->flush($access);
     }
 }