feat: integrate with htmx
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Security\Voter;
|
||||
|
||||
use App\Entity\Application;
|
||||
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;
|
||||
|
||||
@@ -15,6 +16,10 @@ class ApplicationVoter extends Voter
|
||||
public const DISPOSE = 'DISPOSE';
|
||||
public const STATUS = 'STATUS';
|
||||
|
||||
public function __construct(private readonly Security $security)
|
||||
{
|
||||
}
|
||||
|
||||
protected function supports(string $attribute, mixed $subject): bool
|
||||
{
|
||||
if (!$subject instanceof Application) {
|
||||
@@ -36,7 +41,7 @@ class ApplicationVoter extends Voter
|
||||
$adminAttributes = [static::VIEW, static::DELETE, static::DISPOSE, static::STATUS];
|
||||
$teamerAttributes = [static::VIEW, static::WITHDRAW, static::DELETE, static::STATUS];
|
||||
|
||||
if ($user->hasRole('ROLE_ADMINISTRATIVE') && in_array($attribute, $adminAttributes)) {
|
||||
if ($this->security->isGranted('ROLE_ADMINISTRATIVE') && in_array($attribute, $adminAttributes)) {
|
||||
$assignment = $application->getAssignment();
|
||||
return match ($attribute) {
|
||||
static::VIEW, static::STATUS => Application::STATUS_REJECTED !== $status,
|
||||
@@ -47,7 +52,7 @@ class ApplicationVoter extends Voter
|
||||
};
|
||||
}
|
||||
|
||||
if ($user->hasRole('ROLE_TEAMER') && in_array($attribute, $teamerAttributes)) {
|
||||
if ($this->security->isGranted('ROLE_TEAMER') && in_array($attribute, $teamerAttributes)) {
|
||||
$teamer = $user->getTeamer();
|
||||
return match ($attribute) {
|
||||
static::WITHDRAW => $teamer === $application->getTeamer(),
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Entity\Assignment;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||
|
||||
@@ -16,8 +17,11 @@ class AssignmentVoter extends Voter
|
||||
public const EDIT = 'EDIT';
|
||||
public const APPLY = 'APPLY';
|
||||
|
||||
public function __construct(private readonly EntityManagerInterface $entityManager)
|
||||
{}
|
||||
public function __construct(
|
||||
private readonly Security $security,
|
||||
private readonly EntityManagerInterface $entityManager
|
||||
) {
|
||||
}
|
||||
|
||||
protected function supports(string $attribute, mixed $subject): bool
|
||||
{
|
||||
@@ -40,7 +44,7 @@ class AssignmentVoter extends Voter
|
||||
|
||||
// Only users with administrative role may edit assignments
|
||||
if (static::EDIT === $attribute) {
|
||||
return in_array('ROLE_ADMINISTRATIVE', $token->getRoleNames());
|
||||
return $this->security->isGranted('ROLE_ADMINISTRATIVE');
|
||||
}
|
||||
|
||||
// Only allow applications to open assignments
|
||||
@@ -61,7 +65,7 @@ class AssignmentVoter extends Voter
|
||||
}
|
||||
|
||||
// Only teamers without existing applications may apply to the assignment
|
||||
if (in_array('ROLE_TEAMER', $token->getRoleNames())) {
|
||||
if ($this->security->isGranted('ROLE_TEAMER')) {
|
||||
/** @var User $user */
|
||||
$user = $token->getUser();
|
||||
$teamer = $user->getTeamer();
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Security\Voter;
|
||||
use App\BusProNet\DataProvider\HotelDataProvider;
|
||||
use App\BusProNet\Model\Hotel;
|
||||
use App\Entity\Disposition;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||
|
||||
@@ -17,8 +18,10 @@ class DispositionVoter extends Voter
|
||||
public const INVOICE = 'INVOICE';
|
||||
public const FEEDBACK = 'FEEDBACK';
|
||||
|
||||
public function __construct(private readonly HotelDataProvider $hotelDataProvider)
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Security $security,
|
||||
private readonly HotelDataProvider $hotelDataProvider
|
||||
) {
|
||||
}
|
||||
|
||||
protected function supports(string $attribute, mixed $subject): bool
|
||||
@@ -52,12 +55,12 @@ class DispositionVoter extends Voter
|
||||
|
||||
private function assertAdministrativeAccess(TokenInterface $token): bool
|
||||
{
|
||||
return in_array('ROLE_ADMINISTRATIVE', $token->getRoleNames());
|
||||
return $this->security->isGranted('ROLE_ADMINISTRATIVE');
|
||||
}
|
||||
|
||||
private function assertHouseManagerAccess(TokenInterface $token, Disposition $disposition): bool
|
||||
{
|
||||
if (false === in_array('ROLE_HOUSE_MANAGER', $token->getRoleNames())) {
|
||||
if (false === $this->security->isGranted('ROLE_HOUSE_MANAGER')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -79,7 +82,7 @@ class DispositionVoter extends Voter
|
||||
|
||||
private function assertTeamerAccess(TokenInterface $token, Disposition $disposition): bool
|
||||
{
|
||||
if (false === in_array('ROLE_TEAMER', $token->getRoleNames())) {
|
||||
if (false === $this->security->isGranted('ROLE_TEAMER')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Security\Voter;
|
||||
|
||||
use App\Entity\Upload;
|
||||
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;
|
||||
|
||||
@@ -14,6 +15,10 @@ class UploadVoter extends Voter
|
||||
public const DOWNLOAD = 'DOWNLOAD';
|
||||
public const CHECK = 'CHECK';
|
||||
|
||||
public function __construct(private readonly Security $security)
|
||||
{
|
||||
}
|
||||
|
||||
protected function supports(string $attribute, mixed $subject): bool
|
||||
{
|
||||
if (! $subject instanceof Upload) {
|
||||
@@ -29,7 +34,7 @@ class UploadVoter extends Voter
|
||||
$upload = $subject;
|
||||
|
||||
// Administrative users have full access
|
||||
if (true === in_array('ROLE_ADMINISTRATIVE', $token->getRoleNames())) {
|
||||
if (true === $this->security->isGranted('ROLE_ADMINISTRATIVE')) {
|
||||
// Only new documents may be checked
|
||||
if (static::CHECK === $attribute) {
|
||||
return in_array($upload->getStatus(), [Upload::STATUS_NEW, Upload::STATUS_PENDING]);
|
||||
|
||||
Reference in New Issue
Block a user