WIP: Implement profile editing

This commit is contained in:
Björn Fromme
2023-10-02 15:07:02 +02:00
parent 953aa9c8e0
commit d3a0021b7d
12 changed files with 311 additions and 47 deletions
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Security\Voter;
use App\Entity\License;
use App\Entity\User;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class LicenseVoter extends Voter
{
public const VIEW = 'VIEW';
public const DELETE = 'DELETE';
public function __construct(private readonly Security $security)
{}
protected function supports(string $attribute, mixed $subject): bool
{
if (!$subject instanceof License) {
return false;
}
return in_array($attribute, [static::VIEW, static::DELETE]);
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
if (true === $this->security->isGranted('ROLE_ADMINISTRATIVE')) {
return true;
}
/** @var License $license */
$license = $subject;
/** @var User $user */
$user = $this->security->getUser();
return $license->getTeamer() === $user->getTeamer();
}
}