<?php
namespace App\Security\Voter\Permissions\Admin;
use App\Helper\Common\CommonHelper;
use App\Models\Heimdall\Profile;
use Symfony\Component\Security\Core\User\UserInterface;
class AdminPortalVoter extends AdminVoter
{
protected function supports($attribute, $subject): bool
{
if (!in_array($attribute, [Profile::PROFILE_SUPER_ADMIN, Profile::PROFILE_ADMIN_SERVICE, Profile::PROFILE_ADMIN_USER])) {
return false;
}
return is_string($subject) && !CommonHelper::isUuid($subject);
}
protected function getUserProfiles(UserInterface $user, string $entityId): array
{
$heimdallUser = $this->userManager->findUser($user->getUsername());
$userProfiles = $this->userProfileManager->getUserProfiles($heimdallUser);
return array_filter(
$userProfiles,
fn ($userProfile) => in_array($entityId, $userProfile->getPortals())
);
}
}