Skip to content

Commit 027e126

Browse files
authored
Merge pull request #202 from aroskanalen/feature/398-feed-blamable-bug
Fixed ScreenUser blamable identifier
2 parents 73401c8 + fa41d53 commit 027e126

File tree

6 files changed

+32
-9
lines changed

6 files changed

+32
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
- [#202](https://github.com/os2display/display-api-service/pull/202)
8+
- Fixed ScreenUser blamable identifier.
9+
710
## [2.0.1] - 2024-04-09
811

912
- [#201](https://github.com/os2display/display-api-service/pull/201)

src/Controller/ApiV1RedirectController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ class ApiV1RedirectController extends AbstractController
1313
#[Route('/v1/{endpoint}', name: 'app_api_v1_redirect', requirements: ['endpoint' => '.+'], defaults: ['endpoint' => null], methods: ['GET'])]
1414
public function index(string $endpoint): RedirectResponse
1515
{
16-
return $this->redirect('/v2/'.$endpoint, 301);
16+
return $this->redirect('/v2/'.$endpoint, \Symfony\Component\HttpFoundation\Response::HTTP_MOVED_PERMANENTLY);
1717
}
1818
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Entity\Interfaces;
6+
7+
interface UserInterface extends \Symfony\Component\Security\Core\User\UserInterface
8+
{
9+
public function getBlamableIdentifier(): string;
10+
}

src/Entity/ScreenUser.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Entity;
66

77
use App\Entity\Interfaces\TenantScopedUserInterface;
8+
use App\Entity\Interfaces\UserInterface;
89
use App\Entity\Tenant\AbstractTenantScopedEntity;
910
use App\Entity\Tenant\Screen;
1011
use App\Repository\ScreenUserRepository;
@@ -13,7 +14,6 @@
1314
use Doctrine\Common\Collections\Collection;
1415
use Doctrine\ORM\Mapping as ORM;
1516
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
16-
use Symfony\Component\Security\Core\User\UserInterface;
1717

1818
#[ORM\Entity(repositoryClass: ScreenUserRepository::class)]
1919
class ScreenUser extends AbstractTenantScopedEntity implements UserInterface, TenantScopedUserInterface
@@ -147,4 +147,9 @@ public function getUserRoleTenants(): Collection
147147

148148
return new ArrayCollection([$userRoleTenant]);
149149
}
150+
151+
public function getBlamableIdentifier(): string
152+
{
153+
return 'Screen-'.$this->screen->getId()?->jsonSerialize();
154+
}
150155
}

src/Entity/User.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Entity;
66

77
use App\Entity\Interfaces\TenantScopedUserInterface;
8+
use App\Entity\Interfaces\UserInterface;
89
use App\Enum\UserTypeEnum;
910
use App\Repository\UserRepository;
1011
use App\Utils\Roles;
@@ -13,7 +14,6 @@
1314
use Doctrine\DBAL\Types\Types;
1415
use Doctrine\ORM\Mapping as ORM;
1516
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
16-
use Symfony\Component\Security\Core\User\UserInterface;
1717
use Symfony\Component\Serializer\Annotation\Ignore;
1818
use Symfony\Component\Validator\Constraints as Assert;
1919

@@ -319,4 +319,9 @@ final public function jsonSerialize(): array
319319
'providerId' => $this->providerId,
320320
];
321321
}
322+
323+
public function getBlamableIdentifier(): string
324+
{
325+
return $this->getEmail();
326+
}
322327
}

src/EventListener/BlameableListener.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace App\EventListener;
66

77
use App\Entity\Interfaces\BlameableInterface;
8-
use App\Entity\User;
8+
use App\Entity\Interfaces\UserInterface;
99
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
1010
use Doctrine\ORM\Events;
1111
use Doctrine\Persistence\Event\LifecycleEventArgs;
@@ -24,12 +24,12 @@ public function prePersist(LifecycleEventArgs $args): void
2424
$entity = $args->getObject();
2525

2626
if ($entity instanceof BlameableInterface) {
27-
/** @var User $user */
27+
/** @var UserInterface $user */
2828
$user = $this->security->getUser();
2929

3030
if (null !== $user) {
31-
$entity->setCreatedBy($user->getEmail());
32-
$entity->setModifiedBy($user->getEmail());
31+
$entity->setCreatedBy($user->getBlamableIdentifier());
32+
$entity->setModifiedBy($user->getBlamableIdentifier());
3333
}
3434
}
3535
}
@@ -39,11 +39,11 @@ public function preUpdate(LifecycleEventArgs $args): void
3939
$entity = $args->getObject();
4040

4141
if ($entity instanceof BlameableInterface) {
42-
/** @var User $user */
42+
/** @var UserInterface $user */
4343
$user = $this->security->getUser();
4444

4545
if (null !== $user) {
46-
$entity->setModifiedBy($user->getEmail());
46+
$entity->setModifiedBy($user->getBlamableIdentifier());
4747
}
4848
}
4949
}

0 commit comments

Comments
 (0)