This commit is contained in:
2025-08-01 20:58:12 +02:00
parent 81de4c1a81
commit 4e2971c942
4 changed files with 69 additions and 12 deletions

24
composer.lock generated
View File

@ -79,16 +79,16 @@
},
{
"name": "bnine/filesbundle",
"version": "v1.0.31",
"version": "v1.0.39",
"source": {
"type": "git",
"url": "https://github.com/afornerot/bNine-FilesBundle.git",
"reference": "b9a1cf8d2ec53abf34309ae721f9136a8eca9b66"
"reference": "9fab2530ec5528ce449351886ca6c503acee4b2c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/afornerot/bNine-FilesBundle/zipball/b9a1cf8d2ec53abf34309ae721f9136a8eca9b66",
"reference": "b9a1cf8d2ec53abf34309ae721f9136a8eca9b66",
"url": "https://api.github.com/repos/afornerot/bNine-FilesBundle/zipball/9fab2530ec5528ce449351886ca6c503acee4b2c",
"reference": "9fab2530ec5528ce449351886ca6c503acee4b2c",
"shasum": ""
},
"require": {
@ -109,10 +109,10 @@
],
"description": "Symfony bundle for file-browser",
"support": {
"source": "https://github.com/afornerot/bNine-FilesBundle/tree/v1.0.31",
"source": "https://github.com/afornerot/bNine-FilesBundle/tree/v1.0.39",
"issues": "https://github.com/afornerot/bNine-FilesBundle/issues"
},
"time": "2025-08-01T17:06:06+00:00"
"time": "2025-08-01T18:40:55+00:00"
},
{
"name": "brick/math",
@ -499,16 +499,16 @@
},
{
"name": "doctrine/doctrine-bundle",
"version": "2.15.0",
"version": "2.15.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/DoctrineBundle.git",
"reference": "d88294521a1bca943240adca65fa19ca8a7288c6"
"reference": "5a305c5e776f9d3eb87f5b94d40d50aff439211d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/DoctrineBundle/zipball/d88294521a1bca943240adca65fa19ca8a7288c6",
"reference": "d88294521a1bca943240adca65fa19ca8a7288c6",
"url": "https://api.github.com/repos/doctrine/DoctrineBundle/zipball/5a305c5e776f9d3eb87f5b94d40d50aff439211d",
"reference": "5a305c5e776f9d3eb87f5b94d40d50aff439211d",
"shasum": ""
},
"require": {
@ -601,7 +601,7 @@
],
"support": {
"issues": "https://github.com/doctrine/DoctrineBundle/issues",
"source": "https://github.com/doctrine/DoctrineBundle/tree/2.15.0"
"source": "https://github.com/doctrine/DoctrineBundle/tree/2.15.1"
},
"funding": [
{
@ -617,7 +617,7 @@
"type": "tidelift"
}
],
"time": "2025-06-16T19:53:58+00:00"
"time": "2025-07-30T15:48:28+00:00"
},
{
"name": "doctrine/doctrine-migrations-bundle",

View File

@ -3,6 +3,8 @@ twig:
form_themes: ['bootstrap_5_layout.html.twig']
globals:
appName: "%appName%"
paths:
'%kernel.project_dir%/vendor/bnine/filesbundle/templates': BnineFilesBundle
when@test:
twig:
strict_variables: true

View File

@ -105,6 +105,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this;
}
public function hasRole(string $role): bool
{
return in_array($role, $this->getRoles());
}
/**
* @see PasswordAuthenticatedUserInterface
*/

View File

@ -0,0 +1,50 @@
<?php
namespace App\Security;
use App\Entity\User;
use App\Repository\ProjectRepository;
use Bnine\FilesBundle\Security\AbstractFileVoter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
class FileVoter extends AbstractFileVoter
{
private ProjectRepository $projectRepository;
public function __construct(ProjectRepository $projectRepository)
{
$this->projectRepository = $projectRepository;
}
protected function canView(string $domain, $id, TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
return true;
}
protected function canEdit(string $domain, $id, TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
if ($user->hasRole('ROLE_ADMIN')) {
return true;
}
switch ($domain) {
case 'project':
$project = $this->projectRepository->find($id);
if ($project && $project->getUsers()->contains($user)) {
return true;
}
break;
}
return false;
}
}