Skip to content
Snippets Groups Projects
Commit b4beee8d authored by Donovan Bourlard's avatar Donovan Bourlard
Browse files

Merge branch 'hotfix/v1.6.1' into develop

parents 7232f281 b774ed84
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,10 @@ CHANGELOG
## [UNRELEASED]
## [1.6.1] - 2019-09-23
### Fix
- [ADMINISTRATION] Subrogation / Créer une donnée avec l'admin en tant que créateur ne génère plus de 500, #207
## [1.6.0] - 2019-09-20
### Ajout
- [DUPLICATION] Un administrateur peut maintenant dupliquer des traitements / sous-traitants / actions de protections d'une collectivité vers des autres, #187
......
parameters:
app.version: 1.6.0
app.version: 1.6.1
framework:
secret: '%env(APP_SECRET)%'
......
......@@ -75,6 +75,7 @@ class LinkCreatorSubscriber implements EventSubscriber
*/
public function prePersist(LifecycleEventArgs $args): void
{
$em = $args->getEntityManager();
$object = $args->getObject();
$uses = \class_uses($object);
$token = $this->userProvider->getToken();
......@@ -108,7 +109,9 @@ class LinkCreatorSubscriber implements EventSubscriber
// We link admin, then check it original token
foreach ($token->getRoles() as $role) {
if ($role instanceof SwitchUserRole) {
$object->setCreator($role->getSource()->getUser());
$originalUserId = $role->getSource()->getUser()->getId()->toString();
$originalUser = $em->find(User::class, $originalUserId);
$object->setCreator($originalUser);
return;
}
......
......@@ -30,6 +30,7 @@ use App\Application\Traits\Model\CreatorTrait;
use App\Domain\User\Model;
use App\Tests\Utils\ReflectionTrait;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
......@@ -51,9 +52,9 @@ class LinkCreatorSubscriberTest extends TestCase
private $userProviderProphecy;
/**
* @var bool
* @var EntityManagerInterface
*/
private $linkAdmin;
private $entityManagerProphecy;
/**
* @var LinkCreatorSubscriber
......@@ -64,6 +65,7 @@ class LinkCreatorSubscriberTest extends TestCase
{
$this->lifeCycleEventArgsProphecy = $this->prophesize(LifecycleEventArgs::class);
$this->userProviderProphecy = $this->prophesize(UserProvider::class);
$this->entityManagerProphecy = $this->prophesize(EntityManagerInterface::class);
parent::setUp();
}
......@@ -115,6 +117,7 @@ class LinkCreatorSubscriberTest extends TestCase
$tokenProphecy->getUser()->shouldBeCalled()->willReturn($user);
$this->userProviderProphecy->getToken()->shouldBeCalled()->willReturn($tokenProphecy->reveal());
$this->lifeCycleEventArgsProphecy->getEntityManager()->shouldBeCalled()->willReturn($this->entityManagerProphecy->reveal());
$this->lifeCycleEventArgsProphecy->getObject()->shouldBeCalled()->willReturn($object);
$this->assertFalse(\in_array(CreatorTrait::class, $objectUses));
......@@ -139,6 +142,7 @@ class LinkCreatorSubscriberTest extends TestCase
$tokenProphecy->getUser()->shouldBeCalled()->willReturn($user);
$this->userProviderProphecy->getToken()->shouldBeCalled()->willReturn($tokenProphecy->reveal());
$this->lifeCycleEventArgsProphecy->getEntityManager()->shouldBeCalled()->willReturn($this->entityManagerProphecy->reveal());
$this->lifeCycleEventArgsProphecy->getObject()->shouldBeCalled()->willReturn($object);
$this->assertTrue(\in_array(CreatorTrait::class, $objectUses));
......@@ -164,6 +168,7 @@ class LinkCreatorSubscriberTest extends TestCase
$tokenProphecy->getUser()->shouldBeCalled()->willReturn($loggerUser);
$this->userProviderProphecy->getToken()->shouldBeCalled()->willReturn($tokenProphecy->reveal());
$this->lifeCycleEventArgsProphecy->getEntityManager()->shouldBeCalled()->willReturn($this->entityManagerProphecy->reveal());
$this->lifeCycleEventArgsProphecy->getObject()->shouldBeCalled()->willReturn($object);
$this->assertTrue(\in_array(CreatorTrait::class, $objectUses));
......@@ -189,6 +194,7 @@ class LinkCreatorSubscriberTest extends TestCase
$tokenProphecy->getUser()->shouldBeCalled()->willReturn($user);
$this->userProviderProphecy->getToken()->shouldBeCalled()->willReturn($tokenProphecy->reveal());
$this->lifeCycleEventArgsProphecy->getEntityManager()->shouldBeCalled()->willReturn($this->entityManagerProphecy->reveal());
$this->lifeCycleEventArgsProphecy->getObject()->shouldBeCalled()->willReturn($object);
$this->assertTrue(\in_array(CreatorTrait::class, $objectUses));
......@@ -221,7 +227,9 @@ class LinkCreatorSubscriberTest extends TestCase
$tokenProphecy->getRoles()->shouldBeCalled()->willReturn([$switchUserRole]);
$this->userProviderProphecy->getToken()->shouldBeCalled()->willReturn($tokenProphecy->reveal());
$this->lifeCycleEventArgsProphecy->getEntityManager()->shouldBeCalled()->willReturn($this->entityManagerProphecy->reveal());
$this->lifeCycleEventArgsProphecy->getObject()->shouldBeCalled()->willReturn($object);
$this->entityManagerProphecy->find(Model\User::class, $admin->getId()->toString())->shouldBeCalled()->willReturn($admin);
$this->assertTrue(\in_array(CreatorTrait::class, $objectUses));
$this->assertTrue($user instanceof Model\User);
......@@ -251,6 +259,7 @@ class LinkCreatorSubscriberTest extends TestCase
$tokenProphecy->getRoles()->shouldBeCalled()->willReturn([$role]);
$this->userProviderProphecy->getToken()->shouldBeCalled()->willReturn($tokenProphecy->reveal());
$this->lifeCycleEventArgsProphecy->getEntityManager()->shouldBeCalled()->willReturn($this->entityManagerProphecy->reveal());
$this->lifeCycleEventArgsProphecy->getObject()->shouldBeCalled()->willReturn($object);
$this->assertTrue(\in_array(CreatorTrait::class, $objectUses));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment