Feature: [person][creation] api for listing availables centers for person creation

This commit is contained in:
2022-11-22 11:18:33 +01:00
parent 1585a73974
commit b06a76784a
7 changed files with 111 additions and 9 deletions

View File

@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Security;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInterface;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class AuthorizedCenterOnPersonCreation implements AuthorizedCenterOnPersonCreationInterface
{
private AuthorizationHelperForCurrentUserInterface $authorizationHelperForCurrentUser;
private bool $showCenters;
public function __construct(AuthorizationHelperForCurrentUserInterface $authorizationHelperForCurrentUser, ParameterBagInterface $parameterBag)
{
$this->authorizationHelperForCurrentUser = $authorizationHelperForCurrentUser;
$this->showCenter = $parameterBag->get('chill_main')['acl']['form_show_centers'];
}
public function getCenters(): array
{
if (!$this->showCenter) {
return [];
}
return $this->authorizationHelperForCurrentUser->getReachableCenters(PersonVoter::CREATE);
}
}

View File

@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Security;
use Chill\MainBundle\Entity\Center;
interface AuthorizedCenterOnPersonCreationInterface
{
/**
* @return array|Center[]
*/
public function getCenters(): array;
}