ソースを参照

post MR fixes

Olivier Massot 2 年 前
コミット
44b259ac14

+ 13 - 0
src/Repository/Access/AccessRepository.php

@@ -64,6 +64,19 @@ class AccessRepository extends ServiceEntityRepository implements UserLoaderInte
             ->getOneOrNullResult();
     }
 
+    /**
+     * Retourne l'access administrateur de cette organisation
+     *
+     * @param Organization $organization
+     * @return Access
+     */
+    public function findAdminAccess(Organization $organization): Access {
+        return $this->findOneBy([
+            'adminAccess' => 1,
+            'organization' => $organization
+        ]);
+    }
+
     /**
      * @param Access $access
      * @return mixed

+ 15 - 5
src/Service/Typo3/SubdomainService.php

@@ -2,6 +2,7 @@
 
 namespace App\Service\Typo3;
 
+use App\Entity\Access\Access;
 use App\Entity\Organization\Organization;
 use App\Entity\Organization\Subdomain;
 use App\Message\Command\MailerCommand;
@@ -23,8 +24,11 @@ class SubdomainService
     // Max number of subdomains that an organization can own
     const MAX_SUBDOMAINS_NUMBER = 3;
 
+    // Validation regex for subdomains
     const RX_VALIDATE_SUBDOMAIN = '/^[A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])?$/';
 
+    const ADMIN_2IOS_ID = 10984;
+
     public function __construct(
         private readonly SubdomainRepository $subdomainRepository,
         private readonly EntityManagerInterface $em,
@@ -162,10 +166,7 @@ class SubdomainService
      * @return void
      */
     protected function renameAdminUserToMatchSubdomain(Subdomain $subdomain): void {
-        $adminAccess = $this->accessRepository->findOneBy([
-            'adminAccess' => 1,
-            'organization' => $subdomain->getOrganization()
-        ]);
+        $adminAccess = $this->accessRepository->findAdminAccess($subdomain->getOrganization());
 
         $adminAccess->getPerson()->setUsername('admin' . $subdomain->getSubdomain());
         $this->em->flush();
@@ -184,8 +185,17 @@ class SubdomainService
         );
     }
 
+    /**
+     * Build the data model for the confirmation email
+     *
+     * @param Subdomain $subdomain
+     * @return SubdomainChangeModel
+     */
     protected function getMailModel(Subdomain $subdomain): SubdomainChangeModel {
-        $senderId = $this->security->getUser() ? $this->security->getUser()->getId() : 211;
+        /** @var Access $access */
+        $access = $this->security->getUser();
+
+        $senderId = $access ? $access->getId() : self::ADMIN_2IOS_ID;
 
         return (new SubdomainChangeModel())
             ->setSenderId($senderId)