options added to create person or parcours and to access global history

This commit is contained in:
Julie Lenaerts 2022-03-21 12:10:03 +01:00
parent ff5aeaae17
commit bdb07a3a05
6 changed files with 56 additions and 34 deletions

View File

@ -114,6 +114,11 @@ class ChillMainExtension extends Extension implements
$config['available_countries']
);
$container->setParameter(
'chill_main.access_global_history',
$config['access_global_history']
);
$container->setParameter(
'chill_main.routing.resources',
$config['routing']['resources']

View File

@ -113,6 +113,9 @@ class Configuration implements ConfigurationInterface
->end()
->end()
->end()
->booleanNode('access_global_history')
->defaultTrue()
->end()
->arrayNode('redis')
->children()
->scalarNode('host')

View File

@ -14,6 +14,7 @@ namespace Chill\MainBundle\Routing\MenuBuilder;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Chill\MainBundle\Security\Authorization\ChillExportVoter;
use Knp\Menu\MenuItem;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -22,23 +23,20 @@ use Symfony\Contracts\Translation\TranslatorInterface;
*/
class SectionMenuBuilder implements LocalMenuBuilderInterface
{
/**
* @var AuthorizationCheckerInterface
*/
protected $authorizationChecker;
protected AuthorizationCheckerInterface $authorizationChecker;
/**
* @var TranslatorInterface
*/
protected $translator;
protected TranslatorInterface $translator;
protected ParameterBagInterface $parameterBag;
/**
* SectionMenuBuilder constructor.
*/
public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator)
public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator, ParameterBagInterface $parameterBag)
{
$this->authorizationChecker = $authorizationChecker;
$this->translator = $translator;
$this->parameterBag = $parameterBag;
}
/**
@ -54,14 +52,16 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface
'order' => 0,
]);
$menu->addChild($this->translator->trans('Global timeline'), [
'route' => 'chill_center_timeline',
])
->setExtras(
[
'order' => 10,
]
);
if ($this->parameterBag->get('chill_main.access_global_history')) {
$menu->addChild($this->translator->trans('Global timeline'), [
'route' => 'chill_center_timeline',
])
->setExtras(
[
'order' => 10,
]
);
}
if ($this->authorizationChecker->isGranted(ChillExportVoter::EXPORT)) {
$menu->addChild($this->translator->trans('Export Menu'), [

View File

@ -59,6 +59,16 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
$config['allow_multiple_simultaneous_accompanying_periods']
);
$container->setParameter(
'chill_person.create_person_allowed',
$config['create_person_allowed']
);
$container->setParameter(
'chill_person.create_parcours_allowed',
$config['create_parcours_allowed']
);
// register all configuration in a unique parameter
$container->setParameter('chill_person', $config);

View File

@ -62,6 +62,12 @@ class Configuration implements ConfigurationInterface
->end() // children for 'validation', parent = validation
->end() //validation, parent = children of root
->end() // children of root, parent = root
->booleanNode('create_person_allowed')
->defaultTrue()
->end()
->booleanNode('create_parcours_allowed')
->defaultTrue()
->end()
->arrayNode('person_fields')
->canBeDisabled()
->children()

View File

@ -14,6 +14,7 @@ namespace Chill\PersonBundle\Menu;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Knp\Menu\MenuItem;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -22,23 +23,18 @@ use Symfony\Contracts\Translation\TranslatorInterface;
*/
class SectionMenuBuilder implements LocalMenuBuilderInterface
{
/**
* @var AuthorizationCheckerInterface
*/
protected $authorizationChecker;
protected AuthorizationCheckerInterface $authorizationChecker;
/**
* @var TranslatorInterface
*/
protected $translator;
protected TranslatorInterface $translator;
/**
* SectionMenuBuilder constructor.
*/
public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator)
public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator, ParameterBagInterface $parameterBag)
{
$this->authorizationChecker = $authorizationChecker;
$this->translator = $translator;
$this->parameterBag = $parameterBag;
}
/**
@ -46,7 +42,7 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface
*/
public function buildMenu($menuId, MenuItem $menu, array $parameters)
{
if ($this->authorizationChecker->isGranted(PersonVoter::CREATE)) {
if ($this->authorizationChecker->isGranted(PersonVoter::CREATE) && $this->parameterBag->get('chill_person.create_person_allowed')) {
$menu->addChild($this->translator->trans('Add a person'), [
'route' => 'chill_person_new',
])
@ -56,13 +52,15 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface
]);
}
$menu->addChild($this->translator->trans('Create an accompanying course'), [
'route' => 'chill_person_accompanying_course_new',
])
->setExtras([
'order' => 11,
'icons' => ['plus'],
]);
if ($this->parameterBag->get('chill_person.create_parcours_allowed')) {
$menu->addChild($this->translator->trans('Create an accompanying course'), [
'route' => 'chill_person_accompanying_course_new',
])
->setExtras([
'order' => 11,
'icons' => ['plus'],
]);
}
}
public static function getMenuIds(): array