diff --git a/migrations/Version20231014151112.php b/migrations/Version20231014151112.php new file mode 100644 index 0000000..cab2a1c --- /dev/null +++ b/migrations/Version20231014151112.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE upload ADD comment LONGTEXT DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE upload DROP comment'); + } +} diff --git a/src/Controller/Admin/Document/CheckController.php b/src/Controller/Admin/Document/CheckController.php index 08489e3..5a16c58 100644 --- a/src/Controller/Admin/Document/CheckController.php +++ b/src/Controller/Admin/Document/CheckController.php @@ -31,6 +31,7 @@ class CheckController extends AbstractController #[Route('/admin/document/check/{uuid}', name: 'app_admin_document_check')] #[IsGranted('ROLE_ADMINISTRATIVE')] + #[IsGranted('CHECK', subject: 'document')] public function index(Upload $document, Request $request): JsonResponse { $response = new AjaxModalResponseDto(); diff --git a/src/Security/Voter/UploadVoter.php b/src/Security/Voter/UploadVoter.php index 29b414f..a18afc9 100644 --- a/src/Security/Voter/UploadVoter.php +++ b/src/Security/Voter/UploadVoter.php @@ -4,7 +4,6 @@ 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; @@ -13,9 +12,7 @@ class UploadVoter extends Voter public const VIEW = 'VIEW'; public const DELETE = 'DELETE'; public const DOWNLOAD = 'DOWNLOAD'; - - public function __construct(private readonly Security $security) - {} + public const CHECK = 'CHECK'; protected function supports(string $attribute, mixed $subject): bool { @@ -23,21 +20,32 @@ class UploadVoter extends Voter return false; } - return in_array($attribute, [static::VIEW, static::DELETE, static::DOWNLOAD]); + return in_array($attribute, [static::VIEW, static::DELETE, static::DOWNLOAD, static::CHECK]); } 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(); + // Administrative users have full access + if (true === in_array('ROLE_ADMINISTRATIVE', $token->getRoleNames())) { + // Only new documents may be checked + if (static::CHECK === $attribute) { + return Upload::STATUS_NEW === $upload->getStatus(); + } - return $upload->getOwner() === $user; + return true; + } + + // Teamers may only access their own documents + if (true === in_array($attribute, [static::VIEW, static::DELETE, static::DOWNLOAD])) { + /** @var User $user */ + $user = $token->getUser(); + + return $upload->getOwner() === $user; + } + + return false; } } \ No newline at end of file diff --git a/templates/admin/document/index.html.twig b/templates/admin/document/index.html.twig index 322b7ef..047927e 100644 --- a/templates/admin/document/index.html.twig +++ b/templates/admin/document/index.html.twig @@ -60,15 +60,17 @@ {{ upload.status|upload_status_badge }}