From f0cc6ddb49ee054bcab039c17d7018a10ef50d53 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 11 Jan 2025 02:19:43 +0100 Subject: [PATCH] Use constructor injection for registration parameter --- src/Controller/Api/UserRestController.php | 2 +- src/Controller/Api/WallabagRestController.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Controller/Api/UserRestController.php b/src/Controller/Api/UserRestController.php index a9319bea2..a0aa528c4 100644 --- a/src/Controller/Api/UserRestController.php +++ b/src/Controller/Api/UserRestController.php @@ -104,7 +104,7 @@ class UserRestController extends WallabagRestController */ public function putUserAction(Request $request, Config $craueConfig, UserManagerInterface $userManager, EntityManagerInterface $entityManager, EventDispatcherInterface $eventDispatcher) { - if (!$this->getParameter('fosuser_registration') || !$craueConfig->get('api_user_registration')) { + if (!$this->registrationEnabled || !$craueConfig->get('api_user_registration')) { $json = $this->serializer->serialize(['error' => "Server doesn't allow registrations"], 'json'); return (new JsonResponse()) diff --git a/src/Controller/Api/WallabagRestController.php b/src/Controller/Api/WallabagRestController.php index 80f0eeb4c..1cfa2c91b 100644 --- a/src/Controller/Api/WallabagRestController.php +++ b/src/Controller/Api/WallabagRestController.php @@ -26,14 +26,16 @@ class WallabagRestController extends AbstractFOSRestController protected AuthorizationCheckerInterface $authorizationChecker; protected TokenStorageInterface $tokenStorage; protected TranslatorInterface $translator; + protected bool $registrationEnabled; - public function __construct(EntityManagerInterface $entityManager, SerializerInterface $serializer, AuthorizationCheckerInterface $authorizationChecker, TokenStorageInterface $tokenStorage, TranslatorInterface $translator) + public function __construct(EntityManagerInterface $entityManager, SerializerInterface $serializer, AuthorizationCheckerInterface $authorizationChecker, TokenStorageInterface $tokenStorage, TranslatorInterface $translator, bool $registrationEnabled) { $this->entityManager = $entityManager; $this->serializer = $serializer; $this->authorizationChecker = $authorizationChecker; $this->tokenStorage = $tokenStorage; $this->translator = $translator; + $this->registrationEnabled = $registrationEnabled; } /** @@ -86,7 +88,7 @@ class WallabagRestController extends AbstractFOSRestController { $info = new ApplicationInfo( $this->getParameter('wallabag.version'), - $this->getParameter('fosuser_registration') && $craueConfig->get('api_user_registration'), + $this->registrationEnabled && $craueConfig->get('api_user_registration'), ); return (new JsonResponse())->setJson($this->serializer->serialize($info, 'json'));