From a5cc95e0a390eb724459d130fedf3cadb6263517 Mon Sep 17 00:00:00 2001 From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com> Date: Wed, 10 Apr 2024 10:07:42 +0200 Subject: [PATCH 1/3] 398: Fixed ScreenUser blamable identifier --- CHANGELOG.md | 3 +++ src/Controller/ApiV1RedirectController.php | 2 +- src/Entity/Interfaces/UserInterface.php | 10 ++++++++++ src/Entity/ScreenUser.php | 7 ++++++- src/Entity/User.php | 7 ++++++- src/EventListener/BlameableListener.php | 12 ++++++------ 6 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 src/Entity/Interfaces/UserInterface.php diff --git a/CHANGELOG.md b/CHANGELOG.md index f386f2d0..7ef077a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +- [#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()?->toRfc4122(); + } } 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()); } } } From fa41d537375fa684ad1b59c608eb0c53ef4fb7b9 Mon Sep 17 00:00:00 2001 From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com> Date: Wed, 10 Apr 2024 10:20:34 +0200 Subject: [PATCH 2/3] 398: Changed to jsonSerialize --- src/Entity/ScreenUser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entity/ScreenUser.php b/src/Entity/ScreenUser.php index 96226a47..9c229fa6 100644 --- a/src/Entity/ScreenUser.php +++ b/src/Entity/ScreenUser.php @@ -150,6 +150,6 @@ public function getUserRoleTenants(): Collection public function getBlamableIdentifier(): string { - return 'Screen-'.$this->screen->getId()?->toRfc4122(); + return 'Screen-'.$this->screen->getId()?->jsonSerialize(); } } From 25de2bc6c61bde742bd772498b66740600cf58d4 Mon Sep 17 00:00:00 2001 From: turegjorup Date: Wed, 10 Apr 2024 10:30:50 +0200 Subject: [PATCH 3/3] 1137: Update Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ef077a3..9e9e00b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ 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.