Kaynağa Gözat

Enhances organization creation from trial requests

Updates the trial request process to use a dedicated structure identifier for the subdomain.
Removes subdomain generation logic.
Adds validation for the structure identifier.
Adds a public endpoint for subdomain availability check and marks the old one as deprecated.
Updates CORS configuration to allow a new subdomain.
Olivier Massot 5 ay önce
ebeveyn
işleme
3237b7214f

+ 1 - 1
env/.env.docker

@@ -5,7 +5,7 @@ APP_SECRET=211cede3dc4b162da3ec2fbdcd905070
 ###< symfony/framework-bundle ###
 
 ###> nelmio/cors-bundle ###
-CORS_ALLOW_ORIGIN=^https?:\/\/(localhost|127\.0\.0\.1|(local.(admin|app|app|frames|agenda|maestro).opentalent.fr))(:[0-9]+)?$
+CORS_ALLOW_ORIGIN=^https?:\/\/(localhost|127\.0\.0\.1|(local.(admin|app|app|frames|agenda|maestro|logiciels).opentalent.fr))(:[0-9]+)?$
 ###< nelmio/cors-bundle ###
 
 ###> api v1 ###

+ 5 - 0
src/ApiResources/Organization/Subdomain/SubdomainAvailability.php

@@ -11,11 +11,16 @@ use App\State\Provider\Organization\Subdomain\SubdomainAvailabilityProvider;
 
 #[ApiResource(
     operations: [
+        // TODO: route à supprimer quand elle ne sera plus utilisée nulle part, on ne conservera que la route publique
         new Get(
             uriTemplate: '/subdomains/is_available',
             security: 'is_granted("ROLE_ORGANIZATION_VIEW") or is_granted("ROLE_ORGANIZATION")',
             provider: SubdomainAvailabilityProvider::class
         ),
+        new Get(
+            uriTemplate: '/public/subdomains/is_available',
+            provider: SubdomainAvailabilityProvider::class
+        ),
     ]
 )]
 class SubdomainAvailability

+ 16 - 0
src/ApiResources/Shop/NewStructureArtistPremiumTrialRequest.php

@@ -71,6 +71,10 @@ class NewStructureArtistPremiumTrialRequest
 
     private LegalEnum $legalStatus;
 
+    #[Assert\NotBlank]
+    #[Assert\Regex(pattern: '/^[a-z0-9][a-z0-9-]{0,28}[a-z0-9]$/')]
+    private string $structureIdentifier;
+
     #[Assert\Regex(pattern: '/^|(\d{9})$/')]
     private string $siren;
 
@@ -217,6 +221,18 @@ class NewStructureArtistPremiumTrialRequest
         return $this;
     }
 
+    public function getStructureIdentifier(): string
+    {
+        return $this->structureIdentifier;
+    }
+
+    public function setStructureIdentifier(string $structureIdentifier): self
+    {
+        $this->structureIdentifier = $structureIdentifier;
+
+        return $this;
+    }
+
     public function getSiren(): string
     {
         return $this->siren;

+ 2 - 45
src/Service/Shop/ShopService.php

@@ -244,6 +244,7 @@ class ShopService
      * @param NewStructureArtistPremiumTrialRequest $trialRequest The trial request containing organization data
      *
      * @return OrganizationCreationRequest The created organization creation request
+     * @throws \Exception
      */
     protected function createOrganizationCreationRequestFromTrialRequest(
         NewStructureArtistPremiumTrialRequest $trialRequest,
@@ -259,11 +260,7 @@ class ShopService
         $organizationCreationRequest->setLegalStatus($trialRequest->getLegalStatus());
         $organizationCreationRequest->setSiretNumber($trialRequest->getSiren());
         $organizationCreationRequest->setPhoneNumber($trialRequest->getRepresentativePhone());
-
-        // Generate a subdomain from the structure name
-        // TODO: à améliorer
-        $subdomain = $this->generateSubdomain($trialRequest->getStructureName());
-        $organizationCreationRequest->setSubdomain($subdomain);
+        $organizationCreationRequest->setSubdomain($trialRequest->getStructureIdentifier());
 
         // Set default values
         $organizationCreationRequest->setProduct(SettingsProductEnum::FREEMIUM);
@@ -274,44 +271,4 @@ class ShopService
         return $organizationCreationRequest;
     }
 
-    /**
-     * Generate a subdomain from a structure name.
-     *
-     * @param string $name The structure name to generate a subdomain from
-     *
-     * @return string The generated subdomain
-     */
-    protected function generateSubdomain(string $name): string
-    {
-        // Special case for École to ensure it becomes ecole
-        $name = str_replace(['É', 'é'], 'e', $name);
-
-        // Remove accents and special characters
-        if (function_exists('transliterator_transliterate')) {
-            $subdomain = transliterator_transliterate('Any-Latin; Latin-ASCII; [^a-zA-Z0-9] > \'-\'; Lower()', $name);
-            if ($subdomain === false) {
-                // Fallback if transliteration fails
-                $subdomain = iconv('UTF-8', 'ASCII//TRANSLIT', $name);
-            }
-        } else {
-            // Fallback if transliterator is not available
-            $subdomain = iconv('UTF-8', 'ASCII//TRANSLIT', $name);
-        }
-
-        // Replace spaces and special characters with hyphens
-        $subdomain = preg_replace('/[^a-zA-Z0-9]/', '-', $subdomain);
-        // Convert to lowercase
-        $subdomain = strtolower($subdomain);
-        // Remove consecutive hyphens
-        $subdomain = preg_replace('/-+/', '-', $subdomain);
-        // Trim hyphens from beginning and end
-        $subdomain = trim($subdomain, '-');
-        // Limit length
-        $subdomain = substr($subdomain, 0, 30);
-
-        // Ensure no trailing hyphens after truncation
-        $subdomain = rtrim($subdomain, '-');
-
-        return $subdomain;
-    }
 }