mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
add entry "add a person" in section dynamically + right on exports
This commit is contained in:
parent
318d93c456
commit
b2abce256d
@ -26,6 +26,7 @@ use Symfony\Component\DependencyInjection\Loader;
|
|||||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||||
use Chill\MainBundle\DependencyInjection\MissingBundleException;
|
use Chill\MainBundle\DependencyInjection\MissingBundleException;
|
||||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
|
use Chill\MainBundle\Security\Authorization\ChillExportVoter;
|
||||||
use Chill\PersonBundle\Doctrine\DQL\AddressPart;
|
use Chill\PersonBundle\Doctrine\DQL\AddressPart;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,6 +61,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
$loader->load('services/fixtures.yml');
|
$loader->load('services/fixtures.yml');
|
||||||
$loader->load('services/controller.yml');
|
$loader->load('services/controller.yml');
|
||||||
$loader->load('services/search.yml');
|
$loader->load('services/search.yml');
|
||||||
|
$loader->load('services/menu.yml');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function handlePersonFieldsParameters(ContainerBuilder $container, $config)
|
private function handlePersonFieldsParameters(ContainerBuilder $container, $config)
|
||||||
@ -163,7 +165,9 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
$container->prependExtensionConfig('security', array(
|
$container->prependExtensionConfig('security', array(
|
||||||
'role_hierarchy' => array(
|
'role_hierarchy' => array(
|
||||||
'CHILL_PERSON_UPDATE' => array('CHILL_PERSON_SEE'),
|
'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 ]
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
61
Menu/SectionMenuBuilder.php
Normal file
61
Menu/SectionMenuBuilder.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?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:
|
chill_person_new:
|
||||||
path: /{_locale}/person/new
|
path: /{_locale}/person/new
|
||||||
defaults: {_controller: ChillPersonBundle:Person:new }
|
defaults: {_controller: ChillPersonBundle:Person:new }
|
||||||
options:
|
|
||||||
menus:
|
|
||||||
section:
|
|
||||||
order: 10
|
|
||||||
label: Add a person
|
|
||||||
icons: [plus]
|
|
||||||
|
|
||||||
chill_person_review:
|
chill_person_review:
|
||||||
path: /{_locale}/person/review
|
path: /{_locale}/person/review
|
||||||
|
6
Resources/config/services/menu.yml
Normal file
6
Resources/config/services/menu.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
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
|
Back to the person details: Retour aux détails de la personne
|
||||||
|
|
||||||
#timeline
|
#timeline
|
||||||
|
Timeline: Historique
|
||||||
Closing the accompanying period: Fermeture de la période d'accompagnement
|
Closing the accompanying period: Fermeture de la période d'accompagnement
|
||||||
Opening the accompanying period: Ouverture d'une 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\PersonBundle\Entity\Person;
|
||||||
use Chill\MainBundle\Entity\Center;
|
use Chill\MainBundle\Entity\Center;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
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, [
|
return \in_array($attribute, [
|
||||||
self::STATS, self::LISTS
|
self::STATS, self::LISTS
|
||||||
]);
|
]);
|
||||||
|
} elseif ($subject === null) {
|
||||||
|
return $attribute === self::CREATE;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -72,6 +75,13 @@ class PersonVoter extends AbstractChillVoter implements ProvideRoleHierarchyInte
|
|||||||
return false;
|
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);
|
return $this->helper->userHasAccess($token->getUser(), $subject, $attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user