Skip to content

Commit

Permalink
fix: Fixed stateless with some listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Feb 7, 2024
1 parent 750e337 commit f9526d1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ security:

# https://symfony.com/bundles/LexikJWTAuthenticationBundle/current/index.html#configure-application-routing
api_login:
stateless: true
pattern: ^/api/token
provider: all_users
login_throttling:
Expand Down
4 changes: 4 additions & 0 deletions config/routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ api_custom_forms_item_definition:
methods: [GET]
path: /api/custom_forms/{id}/definition
controller: RZ\Roadiz\CoreBundle\Controller\CustomFormController::definitionAction
stateless: true
requirements:
id: "[0-9]+"
api_custom_forms_item_post:
methods: [POST]
path: /api/custom_forms/{id}/post
controller: RZ\Roadiz\CoreBundle\Controller\CustomFormController::postAction
stateless: true
requirements:
id: "[0-9]+"

Expand All @@ -28,6 +30,7 @@ customFormSentAction:
healthCheckAction:
methods: [GET]
path: /health-check
stateless: true
controller: RZ\Roadiz\CoreBundle\Controller\HealthCheckController

roadiz_core_themes:
Expand All @@ -36,4 +39,5 @@ roadiz_core_themes:

api_login_check:
methods: [POST]
stateless: true
path: /api/token
19 changes: 12 additions & 7 deletions src/EventSubscriber/LocaleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,26 @@ public function onKernelRequest(RequestEvent $event): void
$request = $event->getRequest();
$locale = $request->query->get('_locale') ?? $request->attributes->get('_locale');

if ($request->hasPreviousSession()) {
/*
* Set default locale
*/
if (null !== $locale && $locale !== '') {
$this->setLocale($event, $locale);
return;
}

if (!$request->attributes->getBoolean('_stateless') && $request->hasPreviousSession()) {
$locale = $request->getSession()->get('_locale', null);
if (null !== $locale) {
$this->setLocale($event, $locale);
return;
}
}

/*
* Set default locale
*/
if (null !== $locale && $locale !== '') {
$this->setLocale($event, $locale);
} elseif (null !== $translation = $this->getDefaultTranslation()) {
if (null !== $translation = $this->getDefaultTranslation()) {
$shortLocale = $translation->getLocale();
$this->setLocale($event, $shortLocale);
return;
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/EventSubscriber/UserLocaleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public static function getSubscribedEvents(): array
*/
public function onInteractiveLogin(InteractiveLoginEvent $event): void
{
if ($this->requestStack->getMainRequest()?->attributes->getBoolean('_stateless')) {
return;
}

$user = $event->getAuthenticationToken()->getUser();

if (
Expand All @@ -59,6 +63,9 @@ public function onInteractiveLogin(InteractiveLoginEvent $event): void
*/
public function onUserUpdated(FilterUserEvent $event): void
{
if ($this->requestStack->getMainRequest()?->attributes->getBoolean('_stateless')) {
return;
}
$user = $event->getUser();

if (
Expand Down

0 comments on commit f9526d1

Please sign in to comment.