Julien Fastré c9c29b9105
Add ExportGenerationVoter and integrate it into StoredObjectVoter
Introduced ExportGenerationVoter to handle specific view permissions for ExportGeneration entities. Updated ExportGenerationStoredObjectVoter to delegate permission checks to the new voter using Symfony's security system. This improves separation of concerns and reusability of authorization logic.
2025-03-13 17:53:10 +01:00

33 lines
936 B
PHP

<?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\Security\Authorization;
use Chill\MainBundle\Entity\ExportGeneration;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class ExportGenerationVoter extends Voter
{
public const VIEW = 'view';
protected function supports(string $attribute, $subject)
{
return self::VIEW === $attribute && $subject instanceof ExportGeneration;
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token)
{
/* @var ExportGeneration $subject */
return $token->getUser()->getUserIdentifier() === $subject->getCreatedBy()->getUserIdentifier();
}
}