瀏覽代碼

make get helloasso form by event id public

Olivier Massot 2 月之前
父節點
當前提交
c07fc5639d

+ 1 - 2
src/ApiResources/HelloAsso/EventForm.php

@@ -25,7 +25,7 @@ use App\State\Provider\HelloAsso\EventFormProvider;
             uriTemplate: '/helloasso/form/{slug}',
         ),
         new Get(
-            uriTemplate: '/helloasso/form/by-event/{eventId}',
+            uriTemplate: '/public/helloasso/form/by-event/{eventId}',
             uriVariables: [
                 'eventId' => new Link(
                     fromProperty: 'eventId',
@@ -35,7 +35,6 @@ use App\State\Provider\HelloAsso\EventFormProvider;
         )
     ],
     provider: EventFormProvider::class,
-    security: 'is_granted("ROLE_ORGANIZATION")'
 )]
 class EventForm
 {

+ 8 - 6
src/Service/HelloAsso/HelloAssoService.php

@@ -271,19 +271,21 @@ class HelloAssoService extends ApiRequestService
         return $this->makeHelloAssoEventForm($data);
     }
 
-    public function getHelloAssoEventFormByEventId(int $organizationId, int $eventId): EventForm
+    public function getHelloAssoEventFormByEventId(int $eventId): EventForm
     {
+        $event = $this->eventRepository->find($eventId);
+        if (!$event) {
+            throw new \RuntimeException('Event not found');
+        }
+
+        $organizationId = $event->getOrganization()->getId();
+
         $helloAssoEntity = $this->getHelloAssoEntityFor($organizationId);
 
         if (!$helloAssoEntity->getOrganizationSlug() || !$helloAssoEntity->getToken()) {
             throw new \RuntimeException('HelloAsso entity incomplete');
         }
 
-        $event = $this->eventRepository->find($eventId);
-        if (!$event) {
-            throw new \RuntimeException('Event not found');
-        }
-
         $helloAssoFormSlug = $event->getHelloAssoSlug();
         if (!$helloAssoFormSlug) {
             throw new \RuntimeException('HelloAsso form slug not found');

+ 8 - 6
src/State/Provider/HelloAsso/EventFormProvider.php

@@ -4,6 +4,7 @@ declare(strict_types=1);
 
 namespace App\State\Provider\HelloAsso;
 
+use ApiPlatform\Metadata\Get;
 use ApiPlatform\Metadata\GetCollection;
 use ApiPlatform\Metadata\Operation;
 use ApiPlatform\State\ProviderInterface;
@@ -35,19 +36,20 @@ final class EventFormProvider implements ProviderInterface
      */
     public function provide(Operation $operation, array $uriVariables = [], array $context = []): ArrayCollection | EventForm
     {
+        if ($operation instanceof Get && isset($uriVariables['eventId'])) {
+            // This is a public endpoint
+            return $this->helloAssoService->getHelloAssoEventFormByEventId($uriVariables['eventId']);
+        }
+
         /** @var Access $access */
         $access = $this->security->getUser();
-
         $organizationId = $access->getOrganization()->getId();
 
         if ($operation instanceof GetCollection) {
             $forms = $this->helloAssoService->getHelloAssoEventForms($organizationId);
-
             return new ArrayCollection($forms);
-        } else if (isset($uriVariables['eventId'])) {
-            return $this->helloAssoService->getHelloAssoEventFormByEventId($organizationId, $uriVariables['eventId']);
-        } else {
-            return $this->helloAssoService->getHelloAssoEventForm($organizationId, $uriVariables['slug']);
         }
+
+        return $this->helloAssoService->getHelloAssoEventForm($organizationId, $uriVariables['slug']);
     }
 }