WIP: Implement feedback functionality

This commit is contained in:
Björn Fromme
2023-11-03 09:20:48 +01:00
parent d024e11f8f
commit d016ee043a
12 changed files with 123 additions and 73 deletions
+36
View File
@@ -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;
}
}