WIP: Implement feedback functionality
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Security\Voter;
|
||||
|
||||
use App\Entity\FeedbackSet;
|
||||
use App\Repository\JobProfileRepository;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||
|
||||
class FeedbackSetVoter extends Voter
|
||||
{
|
||||
public const DELETE = 'DELETE';
|
||||
|
||||
public function __construct(private readonly JobProfileRepository $jobProfileRepository)
|
||||
{
|
||||
}
|
||||
|
||||
protected function supports(string $attribute, mixed $subject): bool
|
||||
{
|
||||
return $subject instanceof FeedbackSet && static::DELETE === $attribute;
|
||||
}
|
||||
|
||||
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
|
||||
{
|
||||
/** @var FeedbackSet $feedbackSet */
|
||||
$feedbackSet = $subject;
|
||||
|
||||
// Feedback sets may only be deleted when not in use
|
||||
$result = $this
|
||||
->jobProfileRepository
|
||||
->findOneBy(['feedbackSet' => $feedbackSet])
|
||||
;
|
||||
|
||||
return null === $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user