feat: pending roles from crm to be confirmed by superadmins

This commit is contained in:
Björn Fromme
2026-08-10 12:26:21 +02:00
parent 681734533f
commit b01c2e84c7
26 changed files with 907 additions and 150 deletions
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace App\Security\Voter;
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 UserVoter extends Voter
{
public const EDIT = 'CAN_EDIT_USER';
public function __construct(private readonly Security $security)
{
}
protected function supports(string $attribute, mixed $subject): bool
{
return self::EDIT === $attribute && $subject instanceof User;
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
$currentUser = $token->getUser();
$targetUser = $subject;
if (!$currentUser instanceof User || !$targetUser instanceof User) {
return false;
}
// editing your own roles or super admin flag is not allowed
if ($currentUser === $targetUser) {
return false;
}
// if the current user is impersonating, do not grant access
if ($this->security->isGranted('IS_IMPERSONATOR')) {
return false;
}
return $currentUser->isSuperAdmin();
}
}