Feature: [saved export] Générate a report from a saved export

This commit is contained in:
2022-11-08 18:02:26 +01:00
parent aec4c52567
commit 79e9906a05
5 changed files with 86 additions and 6 deletions

View File

@@ -0,0 +1,39 @@
<?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\SavedExport;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use UnexpectedValueException;
class SavedExportVoter extends Voter
{
public const GENERATE = 'CHLL_MAIN_EXPORT_SAVED_GENERATE';
protected function supports($attribute, $subject): bool
{
return $subject instanceof SavedExport && self::GENERATE === $attribute;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
/** @var SavedExport $subject */
switch ($attribute) {
case self::GENERATE:
return $subject->getUser() === $token->getUser();
default:
throw new UnexpectedValueException('attribute not supported: ' . $attribute);
}
}
}