mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-28 13:06:13 +00:00
Refactor SavedExportVoter to improve export permission check
Revised the permission logic in `canUserGenerate` to enhance clarity and maintainability. Replaced nested condition with early return and updated the export permission check to use `isGrantedForElement`.
This commit is contained in:
parent
a14ed78e25
commit
fc8e3789e0
@ -60,7 +60,12 @@ class SavedExportVoter extends Voter
|
||||
|
||||
private function canUserGenerate(User $user, SavedExport $savedExport): bool
|
||||
{
|
||||
return ($savedExport->getUser() === $user || $savedExport->isSharedWithUser($user))
|
||||
&& $this->security->isGranted(ChillExportVoter::EXPORT, $this->exportManager->getExport($savedExport->getExportAlias()));
|
||||
if (!($savedExport->getUser() === $user || $savedExport->isSharedWithUser($user))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$export = $this->exportManager->getExport($savedExport->getExportAlias());
|
||||
|
||||
return $this->exportManager->isGrantedForElement($export);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Tests\Entity\Workflow;
|
||||
|
||||
use Chill\MainBundle\Entity\SavedExport;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\UserGroup;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class SavedExportTest extends TestCase
|
||||
{
|
||||
public function testIsSharedWithUser(): void
|
||||
|
@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Tests\Security\Authorization;
|
||||
|
||||
use Chill\MainBundle\Entity\SavedExport;
|
||||
@ -15,6 +24,11 @@ use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class SavedExportVoterTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
@ -22,7 +36,7 @@ class SavedExportVoterTest extends TestCase
|
||||
/**
|
||||
* @dataProvider voteProvider
|
||||
*/
|
||||
public function testVote(string $attribute, SavedExport $savedExport, User $user, $expectedResult, bool|null $isGranted = null): void
|
||||
public function testVote(string $attribute, SavedExport $savedExport, User $user, $expectedResult, ?bool $isGranted = null): void
|
||||
{
|
||||
$security = $this->prophesize(Security::class);
|
||||
if (null !== $isGranted) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user