WIP: Implement profile editing

This commit is contained in:
Björn Fromme
2023-10-02 12:39:52 +02:00
parent d776d37cd5
commit 953aa9c8e0
27 changed files with 598 additions and 43 deletions
+43
View File
@@ -0,0 +1,43 @@
<?php
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;
class UploadVoter extends Voter
{
public const VIEW = 'VIEW';
public const DELETE = 'DELETE';
public const DOWNLOAD = 'DOWNLOAD';
public function __construct(private readonly Security $security)
{}
protected function supports(string $attribute, mixed $subject): bool
{
if (! $subject instanceof Upload) {
return false;
}
return in_array($attribute, [static::VIEW, static::DELETE, static::DOWNLOAD]);
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
if (true === $this->security->isGranted('ROLE_ADMINISTRATIVE')) {
return true;
}
/** @var Upload $upload */
$upload = $subject;
/** @var User $user */
$user = $this->security->getUser();
return $upload->getOwner() === $user;
}
}