diff --git a/CHANGELOG.md b/CHANGELOG.md index f386f2d0..9e9e00b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +## [2.0.2] - 2024-04-10 + +- [#202](https://github.com/os2display/display-api-service/pull/202) + - Fixed ScreenUser blamable identifier. + ## [2.0.1] - 2024-04-09 - [#201](https://github.com/os2display/display-api-service/pull/201) diff --git a/src/Controller/ApiV1RedirectController.php b/src/Controller/ApiV1RedirectController.php index cacc6ff4..246caf1d 100644 --- a/src/Controller/ApiV1RedirectController.php +++ b/src/Controller/ApiV1RedirectController.php @@ -13,6 +13,6 @@ class ApiV1RedirectController extends AbstractController #[Route('/v1/{endpoint}', name: 'app_api_v1_redirect', requirements: ['endpoint' => '.+'], defaults: ['endpoint' => null], methods: ['GET'])] public function index(string $endpoint): RedirectResponse { - return $this->redirect('/v2/'.$endpoint, 301); + return $this->redirect('/v2/'.$endpoint, \Symfony\Component\HttpFoundation\Response::HTTP_MOVED_PERMANENTLY); } } diff --git a/src/Entity/Interfaces/UserInterface.php b/src/Entity/Interfaces/UserInterface.php new file mode 100644 index 00000000..80670369 --- /dev/null +++ b/src/Entity/Interfaces/UserInterface.php @@ -0,0 +1,10 @@ +screen->getId()?->jsonSerialize(); + } } diff --git a/src/Entity/User.php b/src/Entity/User.php index 307135a2..8e397470 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -5,6 +5,7 @@ namespace App\Entity; use App\Entity\Interfaces\TenantScopedUserInterface; +use App\Entity\Interfaces\UserInterface; use App\Enum\UserTypeEnum; use App\Repository\UserRepository; use App\Utils\Roles; @@ -13,7 +14,6 @@ use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; -use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Serializer\Annotation\Ignore; use Symfony\Component\Validator\Constraints as Assert; @@ -319,4 +319,9 @@ final public function jsonSerialize(): array 'providerId' => $this->providerId, ]; } + + public function getBlamableIdentifier(): string + { + return $this->getEmail(); + } } diff --git a/src/EventListener/BlameableListener.php b/src/EventListener/BlameableListener.php index 9437c8c6..2e5ee09b 100644 --- a/src/EventListener/BlameableListener.php +++ b/src/EventListener/BlameableListener.php @@ -5,7 +5,7 @@ namespace App\EventListener; use App\Entity\Interfaces\BlameableInterface; -use App\Entity\User; +use App\Entity\Interfaces\UserInterface; use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; use Doctrine\ORM\Events; use Doctrine\Persistence\Event\LifecycleEventArgs; @@ -24,12 +24,12 @@ public function prePersist(LifecycleEventArgs $args): void $entity = $args->getObject(); if ($entity instanceof BlameableInterface) { - /** @var User $user */ + /** @var UserInterface $user */ $user = $this->security->getUser(); if (null !== $user) { - $entity->setCreatedBy($user->getEmail()); - $entity->setModifiedBy($user->getEmail()); + $entity->setCreatedBy($user->getBlamableIdentifier()); + $entity->setModifiedBy($user->getBlamableIdentifier()); } } } @@ -39,11 +39,11 @@ public function preUpdate(LifecycleEventArgs $args): void $entity = $args->getObject(); if ($entity instanceof BlameableInterface) { - /** @var User $user */ + /** @var UserInterface $user */ $user = $this->security->getUser(); if (null !== $user) { - $entity->setModifiedBy($user->getEmail()); + $entity->setModifiedBy($user->getBlamableIdentifier()); } } }