mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 13:03:50 +00:00
add voter for documents
This commit is contained in:
@@ -3,50 +3,27 @@
|
||||
*/
|
||||
namespace Chill\DocStoreBundle\Menu;
|
||||
|
||||
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
|
||||
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Knp\Menu\MenuItem;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class MenuBuilder implements LocalMenuBuilderInterface
|
||||
final class MenuBuilder implements LocalMenuBuilderInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var TokenStorageInterface
|
||||
*/
|
||||
protected $tokenStorage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
private Security $security;
|
||||
protected TranslatorInterface $translator;
|
||||
|
||||
public function __construct(
|
||||
TokenStorageInterface $tokenStorage,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
Security $security,
|
||||
TranslatorInterface $translator
|
||||
){
|
||||
$this->tokenStorage = $tokenStorage;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
) {
|
||||
$this->security = $security;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function buildMenu($menuId, MenuItem $menu, array $parameters)
|
||||
{
|
||||
switch($menuId) {
|
||||
@@ -65,11 +42,8 @@ class MenuBuilder implements LocalMenuBuilderInterface
|
||||
{
|
||||
/* @var $person \Chill\PersonBundle\Entity\Person */
|
||||
$person = $parameters['person'];
|
||||
$user = $this->tokenStorage->getToken()->getUser();
|
||||
|
||||
if ($this->authorizationHelper->userHasAccess($user,
|
||||
$person->getCenter(), PersonDocumentVoter::SEE)) {
|
||||
|
||||
|
||||
if ($this->security->isGranted(PersonDocumentVoter::SEE, $person)) {
|
||||
$menu->addChild($this->translator->trans('Documents'), [
|
||||
'route' => 'person_document_index',
|
||||
'routeParameters' => [
|
||||
@@ -80,24 +54,22 @@ class MenuBuilder implements LocalMenuBuilderInterface
|
||||
'order'=> 350
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function buildMenuAccompanyingCourse(MenuItem $menu, array $parameters){
|
||||
$course = $parameters['accompanyingCourse'];
|
||||
// $user = $this->tokenStorage->getToken()->getUser();
|
||||
|
||||
//TODO : add condition to check user rights?
|
||||
|
||||
$menu->addChild($this->translator->trans('Documents'), [
|
||||
if ($this->security->isGranted(AccompanyingCourseDocumentVoter::SEE, $course)) {
|
||||
$menu->addChild($this->translator->trans('Documents'), [
|
||||
'route' => 'accompanying_course_document_index',
|
||||
'routeParameters' => [
|
||||
'course' => $course->getId()
|
||||
]
|
||||
])
|
||||
->setExtras([
|
||||
'order'=> 400
|
||||
]);
|
||||
->setExtras([
|
||||
'order' => 400
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getMenuIds(): array
|
||||
|
Reference in New Issue
Block a user