WIP: Implement feedback functionality
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Security\Voter;
|
||||
|
||||
use App\Entity\Feedback;
|
||||
use App\Entity\User;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||
|
||||
class FeedbackVoter extends Voter
|
||||
{
|
||||
public const VIEW = 'VIEW';
|
||||
public const PUBLISH = 'PUBLISH';
|
||||
public const DELETE = 'DELETE';
|
||||
|
||||
protected function supports(string $attribute, mixed $subject): bool
|
||||
{
|
||||
return $subject instanceof Feedback && in_array($attribute, [static::VIEW, static::PUBLISH, static::DELETE]);
|
||||
}
|
||||
|
||||
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
|
||||
{
|
||||
/** @var Feedback $feedback */
|
||||
$feedback = $subject;
|
||||
|
||||
if (in_array('ROLE_ADMIN', $token->getRoleNames())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (in_array('ROLE_HOUSE_MANAGER', $token->getRoleNames())) {
|
||||
return static::VIEW === $attribute;
|
||||
}
|
||||
|
||||
if (in_array('ROLE_TEAMER', $token->getRoleNames())) {
|
||||
/** @var User $user */
|
||||
$user = $token->getUser();
|
||||
$teamer = $user->getTeamer();
|
||||
|
||||
return $feedback->getTeamer() === $teamer;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user