mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Feature: [person][creation] api for listing availables centers for person creation
This commit is contained in:
parent
1585a73974
commit
b06a76784a
@ -3,6 +3,11 @@ services:
|
|||||||
autowire: true
|
autowire: true
|
||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
|
|
||||||
|
Chill\MainBundle\Security\:
|
||||||
|
autoconfigure: true
|
||||||
|
autowire: true
|
||||||
|
resource: '../../Security'
|
||||||
|
|
||||||
Chill\MainBundle\Security\Resolver\CenterResolverDispatcher:
|
Chill\MainBundle\Security\Resolver\CenterResolverDispatcher:
|
||||||
arguments:
|
arguments:
|
||||||
- !tagged_iterator chill_main.center_resolver
|
- !tagged_iterator chill_main.center_resolver
|
||||||
|
@ -13,12 +13,13 @@ namespace Chill\PersonBundle\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||||
use Chill\MainBundle\Entity\Address;
|
use Chill\MainBundle\Entity\Address;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
|
||||||
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
|
use Chill\PersonBundle\Security\AuthorizedCenterOnPersonCreationInterface;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
@ -26,16 +27,37 @@ use function in_array;
|
|||||||
|
|
||||||
class PersonApiController extends ApiController
|
class PersonApiController extends ApiController
|
||||||
{
|
{
|
||||||
private AuthorizationHelper $authorizationHelper;
|
private AuthorizedCenterOnPersonCreationInterface $authorizedCenterOnPersonCreation;
|
||||||
|
|
||||||
private ConfigPersonAltNamesHelper $configPersonAltNameHelper;
|
private ConfigPersonAltNamesHelper $configPersonAltNameHelper;
|
||||||
|
|
||||||
|
private bool $showCenters;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AuthorizationHelper $authorizationHelper,
|
AuthorizedCenterOnPersonCreationInterface $authorizedCenterOnPersonCreation,
|
||||||
ConfigPersonAltNamesHelper $configPersonAltNameHelper
|
ConfigPersonAltNamesHelper $configPersonAltNameHelper,
|
||||||
|
ParameterBagInterface $parameterBag
|
||||||
) {
|
) {
|
||||||
$this->authorizationHelper = $authorizationHelper;
|
$this->authorizedCenterOnPersonCreation = $authorizedCenterOnPersonCreation;
|
||||||
$this->configPersonAltNameHelper = $configPersonAltNameHelper;
|
$this->configPersonAltNameHelper = $configPersonAltNameHelper;
|
||||||
|
$this->showCenters = $parameterBag->get('chill_main')['acl']['form_show_centers'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/api/1.0/person/creation/authorized-centers",
|
||||||
|
* name="chill_person_person_creation_authorized_centers"
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function authorizedCentersForCreation(): Response
|
||||||
|
{
|
||||||
|
$centers = $this->authorizedCenterOnPersonCreation->getCenters();
|
||||||
|
|
||||||
|
return $this->json(
|
||||||
|
['showCenters' => $this->showCenters, 'centers' => $centers],
|
||||||
|
Response::HTTP_OK,
|
||||||
|
[],
|
||||||
|
['gropus' => ['read']]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -1938,3 +1938,13 @@ paths:
|
|||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: "OK"
|
description: "OK"
|
||||||
|
|
||||||
|
/1.0/person/creation/authorized-centers:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- person
|
||||||
|
- permissions
|
||||||
|
summary: Return a list of possible centers for person creation
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "OK"
|
||||||
|
@ -47,9 +47,8 @@ services:
|
|||||||
tags: ['controller.service_arguments']
|
tags: ['controller.service_arguments']
|
||||||
|
|
||||||
Chill\PersonBundle\Controller\PersonApiController:
|
Chill\PersonBundle\Controller\PersonApiController:
|
||||||
arguments:
|
autoconfigure: true
|
||||||
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
|
autowire: true
|
||||||
$configPersonAltNameHelper: '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper'
|
|
||||||
tags: ['controller.service_arguments']
|
tags: ['controller.service_arguments']
|
||||||
|
|
||||||
Chill\PersonBundle\Controller\AccompanyingCourseWorkApiController:
|
Chill\PersonBundle\Controller\AccompanyingCourseWorkApiController:
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
services:
|
services:
|
||||||
|
|
||||||
|
Chill\PersonBundle\Security\:
|
||||||
|
autoconfigure: true
|
||||||
|
autowire: true
|
||||||
|
resource: '../../Security'
|
||||||
|
|
||||||
chill.person.security.authorization.person:
|
chill.person.security.authorization.person:
|
||||||
autowire: true
|
autowire: true
|
||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user