Commit b2abce25 authored by Julien Fastré's avatar Julien Fastré

add entry "add a person" in section dynamically + right on exports

parent 318d93c4
Pipeline #63026 failed with stages
in 11 seconds
......@@ -26,6 +26,7 @@ use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Chill\MainBundle\DependencyInjection\MissingBundleException;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Chill\MainBundle\Security\Authorization\ChillExportVoter;
use Chill\PersonBundle\Doctrine\DQL\AddressPart;
/**
......@@ -60,6 +61,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
$loader->load('services/fixtures.yml');
$loader->load('services/controller.yml');
$loader->load('services/search.yml');
$loader->load('services/menu.yml');
}
private function handlePersonFieldsParameters(ContainerBuilder $container, $config)
......@@ -163,7 +165,9 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
$container->prependExtensionConfig('security', array(
'role_hierarchy' => array(
'CHILL_PERSON_UPDATE' => array('CHILL_PERSON_SEE'),
'CHILL_PERSON_CREATE' => array('CHILL_PERSON_SEE')
'CHILL_PERSON_CREATE' => array('CHILL_PERSON_SEE'),
PersonVoter::LISTS => [ ChillExportVoter::EXPORT ],
PersonVoter::STATS => [ ChillExportVoter::EXPORT ]
)
));
}
......
<?php
/*
* Copyright (C) 2018 Champs-Libres <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\PersonBundle\Menu;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Knp\Menu\MenuItem;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class SectionMenuBuilder implements LocalMenuBuilderInterface
{
/**
*
* @var AuthorizationCheckerInterface
*/
protected $authorizationChecker;
public function __construct(AuthorizationCheckerInterface $authorizationChecker)
{
$this->authorizationChecker = $authorizationChecker;
}
public function buildMenu($menuId, MenuItem $menu, array $parameters)
{
if ($this->authorizationChecker->isGranted(PersonVoter::CREATE)) {
$menu->addChild('Add a person', [
'route' => 'chill_person_new'
])
->setExtras([
'order' => 10,
'icons' => [ 'plus' ]
]);
}
}
public static function getMenuIds(): array
{
return [ 'section' ];
}
}
......@@ -18,12 +18,6 @@ chill_person_general_update:
chill_person_new:
path: /{_locale}/person/new
defaults: {_controller: ChillPersonBundle:Person:new }
options:
menus:
section:
order: 10
label: Add a person
icons: [plus]
chill_person_review:
path: /{_locale}/person/review
......
services:
Chill\PersonBundle\Menu\SectionMenuBuilder:
arguments:
$authorizationChecker: '@Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface'
tags:
- { name: 'chill.menu_builder' }
......@@ -139,6 +139,7 @@ Add an address: Ajouter une adresse
Back to the person details: Retour aux détails de la personne
#timeline
Timeline: Historique
Closing the accompanying period: Fermeture de la période d'accompagnement
Opening the accompanying period: Ouverture d'une période d'accompagnement
......
......@@ -26,6 +26,7 @@ use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Chill\PersonBundle\Entity\Person;
use Chill\MainBundle\Entity\Center;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Role\Role;
/**
*
......@@ -61,6 +62,8 @@ class PersonVoter extends AbstractChillVoter implements ProvideRoleHierarchyInte
return \in_array($attribute, [
self::STATS, self::LISTS
]);
} elseif ($subject === null) {
return $attribute === self::CREATE;
} else {
return false;
}
......@@ -72,6 +75,13 @@ class PersonVoter extends AbstractChillVoter implements ProvideRoleHierarchyInte
return false;
}
if ($subject === null) {
$centers = $this->helper->getReachableCenters($token->getUser(),
new Role($attribute));
return count($centers) > 0;
}
return $this->helper->userHasAccess($token->getUser(), $subject, $attribute);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment