Skip to content

Commit

Permalink
Merge tag '2.0.2' into develop
Browse files Browse the repository at this point in the history
no message
  • Loading branch information
turegjorup committed Apr 10, 2024
2 parents 5d1a9aa + b1f56e5 commit c222069
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ApiV1RedirectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 10 additions & 0 deletions src/Entity/Interfaces/UserInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace App\Entity\Interfaces;

interface UserInterface extends \Symfony\Component\Security\Core\User\UserInterface
{
public function getBlamableIdentifier(): string;
}
7 changes: 6 additions & 1 deletion src/Entity/ScreenUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Entity;

use App\Entity\Interfaces\TenantScopedUserInterface;
use App\Entity\Interfaces\UserInterface;
use App\Entity\Tenant\AbstractTenantScopedEntity;
use App\Entity\Tenant\Screen;
use App\Repository\ScreenUserRepository;
Expand All @@ -13,7 +14,6 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;

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

return new ArrayCollection([$userRoleTenant]);
}

public function getBlamableIdentifier(): string
{
return 'Screen-'.$this->screen->getId()?->jsonSerialize();
}
}
7 changes: 6 additions & 1 deletion src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -319,4 +319,9 @@ final public function jsonSerialize(): array
'providerId' => $this->providerId,
];
}

public function getBlamableIdentifier(): string
{
return $this->getEmail();
}
}
12 changes: 6 additions & 6 deletions src/EventListener/BlameableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
}
Expand All @@ -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());
}
}
}
Expand Down

0 comments on commit c222069

Please sign in to comment.