Merge branch 'features/person-normalization-resolver-center-dynamically' into 'master'

Use centerResolverDispatcher to normalize a person's center


# Description of changes

There is a normalizer for a person, which include a property "center":

```json
{

    "type": "person",
    "id": 4362539,
    "text": "Diakite BAH",
    "firstName": "Diakite",
    "lastName": "BAH",
    "center": {
        "id": 475,
        "type": "center",
        "name": "Nord Vendée"
    },
    "phonenumber": "",
    "mobilenumber": "",
    "altNames": [ ],
    "gender": "woman",
    "gender_numeric": 1,
    // ...
}
```

Previously, the center was the center attached to the person in the database.

But since September, version 2.0 allow to resolve the center dynamically, for instance with the usage of address. This resolution is done through `CenterResolverDispatcher`.

This `CenterResolverDispatcher` is now used into person normalization.

As a consequence, the center may now be:

* null;
* a center;
* an array of center;

Thoses case are taken into account into `PersonRenderBox` in Vue.



# Issues related

Any issue related.

# Tests

Any new tests.

See merge request Chill-Projet/chill-bundles!205
This commit is contained in:
Julien Fastré 2021-11-08 12:22:11 +00:00
commit ec6828f128
3 changed files with 20 additions and 6 deletions

View File

@ -24,6 +24,7 @@ and this project adheres to
* refactor `AuthorizationHelper` and `UserACLAwareRepository` to fix constructor, and separate logic for parent role helper into `ParentRoleHelper` * refactor `AuthorizationHelper` and `UserACLAwareRepository` to fix constructor, and separate logic for parent role helper into `ParentRoleHelper`
* [main]: filter location and locationType in backend: exclude NULL names, only active and availableToUsers * [main]: filter location and locationType in backend: exclude NULL names, only active and availableToUsers
* [activity]: perform client-side validation & show/hide fields in the "new location" modal * [activity]: perform client-side validation & show/hide fields in the "new location" modal
* [person]: normalize person with CenterResolverDispatcher and handle case where center is null or multiple in PersonRenderBox
* [docstore] voter for PersonDocument and AccompanyingCourseDocument on the 2.0 way (using VoterHelperFactory) * [docstore] voter for PersonDocument and AccompanyingCourseDocument on the 2.0 way (using VoterHelperFactory)
* [docstore] add authorization check inside controller and menu * [docstore] add authorization check inside controller and menu
* [activity]: fix inheritance for role `ACTIVITY FULL` and add missing acl in menu * [activity]: fix inheritance for role `ACTIVITY FULL` and add missing acl in menu
@ -38,6 +39,7 @@ and this project adheres to
* [socialWorkAction]: display of social issue and parent issues + banner context added. * [socialWorkAction]: display of social issue and parent issues + banner context added.
* [DBAL dependencies] Upgrade to DBAL 3.1 * [DBAL dependencies] Upgrade to DBAL 3.1
## Test releases ## Test releases

View File

@ -78,7 +78,7 @@
{{ $t('renderbox.no_data') }} {{ $t('renderbox.no_data') }}
</p> </p>
</li> </li>
<li v-if="person.mobilenumber"> <li v-if="person.mobilenumber">
<i class="fa fa-li fa-mobile"></i> <i class="fa fa-li fa-mobile"></i>
<a :href="'tel: ' + person.mobilenumber">{{ person.mobilenumber }}</a> <a :href="'tel: ' + person.mobilenumber">{{ person.mobilenumber }}</a>
@ -97,8 +97,13 @@
</li> </li>
<li v-if="person.center && options.addCenter"> <li v-if="person.center && options.addCenter">
<i class="fa fa-li fa-long-arrow-right"></i> <i class="fa fa-li fa-long-arrow-right"></i>
{{ person.center.name }} <template v-if="person.center.type !== undefined">
{{ person.center.name }}
</template>
<template v-else>
<template v-for="c in person.center">{{ c.name }}</template>
</template>
</li> </li>
<li v-else-if="options.addNoData"> <li v-else-if="options.addNoData">
<i class="fa fa-li fa-long-arrow-right"></i> <i class="fa fa-li fa-long-arrow-right"></i>

View File

@ -19,6 +19,7 @@
namespace Chill\PersonBundle\Serializer\Normalizer; namespace Chill\PersonBundle\Serializer\Normalizer;
use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
@ -48,16 +49,22 @@ class PersonNormalizer implements
private PersonRepository $repository; private PersonRepository $repository;
private CenterResolverDispatcher $centerResolverDispatcher;
use NormalizerAwareTrait; use NormalizerAwareTrait;
use ObjectToPopulateTrait; use ObjectToPopulateTrait;
use DenormalizerAwareTrait; use DenormalizerAwareTrait;
public function __construct(ChillEntityRenderExtension $render, PersonRepository $repository) public function __construct(
{ ChillEntityRenderExtension $render,
PersonRepository $repository,
CenterResolverDispatcher $centerResolverDispatcher
) {
$this->render = $render; $this->render = $render;
$this->repository = $repository; $this->repository = $repository;
$this->centerResolverDispatcher = $centerResolverDispatcher;
} }
public function normalize($person, string $format = null, array $context = array()) public function normalize($person, string $format = null, array $context = array())
@ -74,7 +81,7 @@ class PersonNormalizer implements
'lastName' => $person->getLastName(), 'lastName' => $person->getLastName(),
'birthdate' => $this->normalizer->normalize($person->getBirthdate()), 'birthdate' => $this->normalizer->normalize($person->getBirthdate()),
'deathdate' => $this->normalizer->normalize($person->getDeathdate()), 'deathdate' => $this->normalizer->normalize($person->getDeathdate()),
'center' => $this->normalizer->normalize($person->getCenter()), 'center' => $this->normalizer->normalize($this->centerResolverDispatcher->resolveCenter($person)),
'phonenumber' => $person->getPhonenumber(), 'phonenumber' => $person->getPhonenumber(),
'mobilenumber' => $person->getMobilenumber(), 'mobilenumber' => $person->getMobilenumber(),
'altNames' => $this->normalizeAltNames($person->getAltNames()), 'altNames' => $this->normalizeAltNames($person->getAltNames()),