Merge branch 'master' into testing

This commit is contained in:
Julien Fastré 2022-07-11 20:03:37 +02:00
commit 3782cf35ff
31 changed files with 747 additions and 610 deletions

View File

@ -24,6 +24,7 @@ parameters:
- "/spec/"
- "/var/"
- "/vendor/"
- "/tests/app"
# Psalm
tasks.psalm.blocking: true

File diff suppressed because it is too large Load Diff

View File

@ -25,16 +25,6 @@ parameters:
count: 1
path: src/Bundle/ChillActivityBundle/Form/ActivityType.php
-
message: "#^Only booleans are allowed in &&, mixed given on the right side\\.$#"
count: 3
path: src/Bundle/ChillActivityBundle/Form/ActivityType.php
-
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
count: 2
path: src/Bundle/ChillActivityBundle/Form/ActivityType.php
-
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
count: 3

View File

@ -203,7 +203,7 @@ final class ActivityController extends AbstractController
// $this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity);
$form = $this->createForm(ActivityType::class, $entity, [
'center' => $entity->getCenter(),
'center' => $entity->getCenters()[0] ?? null,
'role' => new Role('CHILL_ACTIVITY_UPDATE'),
'activityType' => $entity->getActivityType(),
'accompanyingPeriod' => $accompanyingPeriod,

View File

@ -61,8 +61,6 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf
ActivityVoter::DELETE => [ActivityVoter::SEE_DETAILS],
ActivityVoter::SEE_DETAILS => [ActivityVoter::SEE],
ActivityVoter::FULL => [
ActivityVoter::CREATE_PERSON,
ActivityVoter::CREATE_ACCOMPANYING_COURSE,
ActivityVoter::DELETE,
ActivityVoter::UPDATE,
],

View File

@ -16,8 +16,8 @@ use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable;
use Chill\MainBundle\Entity\HasCenterInterface;
use Chill\MainBundle\Entity\HasScopeInterface;
use Chill\MainBundle\Entity\HasCentersInterface;
use Chill\MainBundle\Entity\HasScopesInterface;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
@ -55,7 +55,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* getUserFunction="getUser",
* path="scope")
*/
class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterface, HasCenterInterface, HasScopeInterface
class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterface, HasCentersInterface, HasScopesInterface
{
public const SENTRECEIVED_RECEIVED = 'received';
@ -306,13 +306,17 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
* get the center
* center is extracted from person.
*/
public function getCenter(): ?Center
public function getCenters(): array
{
if ($this->person instanceof Person) {
return $this->person->getCenter();
return [$this->person->getCenter()];
}
return null;
if ($this->getAccompanyingPeriod() instanceof AccompanyingPeriod) {
return $this->getAccompanyingPeriod()->getCenters();
}
return [];
}
public function getComment(): CommentEmbeddable
@ -422,6 +426,19 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
return $this->scope;
}
public function getScopes(): iterable
{
if (null !== $this->getAccompanyingPeriod()) {
return $this->getAccompanyingPeriod()->getScopes();
}
if (null !== $this->getPerson()) {
return [$this->scope];
}
return [];
}
public function getSentReceived(): string
{
return $this->sentReceived;

View File

@ -14,17 +14,20 @@ namespace Chill\ActivityBundle\Form;
use Chill\ActivityBundle\Entity\Activity;
use Chill\ActivityBundle\Entity\ActivityPresence;
use Chill\ActivityBundle\Entity\ActivityReason;
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
use Chill\DocStoreBundle\Form\StoredObjectType;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Form\Type\ChillCollectionType;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\CommentType;
use Chill\MainBundle\Form\Type\PickUserDynamicType;
use Chill\MainBundle\Form\Type\PrivateCommentType;
use Chill\MainBundle\Form\Type\ScopePickerType;
use Chill\MainBundle\Form\Type\UserPickerType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
@ -50,6 +53,7 @@ use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Role\Role;
use function in_array;
class ActivityType extends AbstractType
@ -109,19 +113,18 @@ class ActivityType extends AbstractType
$activityType = $options['activityType'];
// TODO revoir la gestion des center au niveau du form des activité.
if ($options['center']) {
if ($options['center'] instanceof Center && null !== $options['data']->getPerson()) {
$builder->add('scope', ScopePickerType::class, [
'center' => $options['center'],
'role' => $options['role'],
// TODO make required again once scope and rights are fixed
'required' => false,
'role' => ActivityVoter::CREATE === (string) $options['role'] ? ActivityVoter::CREATE_PERSON : (string) $options['role'],
'required' => true,
]);
}
/** @var ? \Chill\PersonBundle\Entity\AccompanyingPeriod $accompanyingPeriod */
$accompanyingPeriod = null;
if ($options['accompanyingPeriod']) {
if ($options['accompanyingPeriod'] instanceof AccompanyingPeriod) {
$accompanyingPeriod = $options['accompanyingPeriod'];
}
@ -218,12 +221,10 @@ class ActivityType extends AbstractType
]);
}
if ($activityType->isVisible('user') && $options['center']) {
$builder->add('user', UserPickerType::class, [
if ($activityType->isVisible('user') && $options['center'] instanceof Center) {
$builder->add('user', PickUserDynamicType::class, [
'label' => $activityType->getLabel('user'),
'required' => $activityType->isRequired('user'),
'center' => $options['center'],
'role' => $options['role'],
]);
}
@ -442,8 +443,8 @@ class ActivityType extends AbstractType
$resolver
->setRequired(['center', 'role', 'activityType', 'accompanyingPeriod'])
->setAllowedTypes('center', ['null', 'Chill\MainBundle\Entity\Center'])
->setAllowedTypes('role', 'Symfony\Component\Security\Core\Role\Role')
->setAllowedTypes('center', ['null', Center::class])
->setAllowedTypes('role', [Role::class, 'string'])
->setAllowedTypes('activityType', \Chill\ActivityBundle\Entity\ActivityType::class)
->setAllowedTypes('accompanyingPeriod', [\Chill\PersonBundle\Entity\AccompanyingPeriod::class, 'null']);
}

View File

@ -120,3 +120,11 @@
{{ form_end(edit_form) }}
{# {{ form(delete_form) }} #}
{% block js %}
{{ encore_entry_script_tags('mod_pickentity_type') }}
{% endblock %}
{% block css %}
{{ encore_entry_link_tags('mod_pickentity_type') }}
{% endblock %}

View File

@ -46,7 +46,7 @@
{% include 'ChillActivityBundle:Activity:list.html.twig' with {'context': 'person'} %}
{% if is_granted('CHILL_ACTIVITY_CREATE_PERSON', person) %}
{% if is_granted('CHILL_ACTIVITY_CREATE', person) %}
<ul class="record_actions sticky-form-buttons">
<li>
<a href="{{ path('chill_activity_activity_new', {'person_id': person_id, 'accompanying_period_id': accompanying_course_id}) }}"

View File

@ -119,3 +119,11 @@
</li>
</ul>
{{ form_end(form) }}
{% block js %}
{{ encore_entry_script_tags('mod_pickentity_type') }}
{% endblock %}
{% block css %}
{{ encore_entry_link_tags('mod_pickentity_type') }}
{% endblock %}

View File

@ -133,7 +133,7 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
// change attribute CREATE
if (self::CREATE === $attribute) {
$attribute = self::CREATE_PERSON;
return $this->voterHelper->voteOnAttribute(self::CREATE_PERSON, $subject->getPerson(), $token);
}
} elseif ($subject->getAccompanyingPeriod() instanceof AccompanyingPeriod) {
if (!$this->security->isGranted(AccompanyingPeriodVoter::SEE, $subject->getAccompanyingPeriod())) {
@ -144,7 +144,8 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
if (AccompanyingPeriod::STEP_CLOSED === $subject->getAccompanyingPeriod()->getStep()) {
return false;
}
$attribute = self::CREATE_ACCOMPANYING_COURSE;
return $this->voterHelper->voteOnAttribute(self::CREATE_ACCOMPANYING_COURSE, $subject->getAccompanyingPeriod(), $token);
}
} else {
throw new RuntimeException('Could not determine context of activity.');
@ -158,12 +159,12 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
// transform the attribute
if (self::CREATE === $attribute) {
$attribute = self::CREATE_ACCOMPANYING_COURSE;
return $this->voterHelper->voteOnAttribute(self::CREATE_ACCOMPANYING_COURSE, $subject, $token);
}
} elseif ($subject instanceof Person) {
// transform the attribute
if (self::CREATE === $attribute) {
$attribute = self::CREATE_PERSON;
return $this->voterHelper->voteOnAttribute(self::CREATE_PERSON, $subject, $token);
}
}

View File

@ -130,8 +130,10 @@ class ActivityContext implements
return $this->personRender->renderString($p, []);
},
'multiple' => false,
'required' => false,
'expanded' => true,
'label' => $options[$key . 'Label'],
'placeholder' => $this->translator->trans('Any person selected'),
]);
}
}

View File

@ -126,7 +126,7 @@ class Version20160318111334 extends AbstractMigration
$this->addSql('ALTER TABLE chill_event_participation '
. 'ADD CONSTRAINT FK_4E7768AC217BBB47 '
. 'FOREIGN KEY (person_id) '
. 'REFERENCES Person (id) '
. 'REFERENCES chill_person_person(id) '
. 'NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_event_participation '
. 'ADD CONSTRAINT FK_4E7768ACD60322AC '

View File

@ -92,5 +92,8 @@ final class PostalCodeAPIController extends ApiController
$qb->where('e.country = :country')
->setParameter('country', $request->query->get('country'));
}
$qb->andWhere('e.origin = :zero')
->setParameter('zero', 0);
}
}

View File

@ -12,7 +12,9 @@ declare(strict_types=1);
namespace Chill\MainBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class UserApiController extends ApiController
@ -58,4 +60,14 @@ class UserApiController extends ApiController
['groups' => ['read']]
);
}
/**
* @param QueryBuilder $query
*/
protected function customizeQuery(string $action, Request $request, $query): void
{
if ('_index' === $action) {
$query->andWhere($query->expr()->eq('e.enabled', "'TRUE'"));
}
}
}

View File

@ -0,0 +1,25 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Symfony\Component\HttpFoundation\Request;
class UserJobApiController extends ApiController
{
protected function customizeQuery(string $action, Request $request, $query): void
{
if ('_index' === $action) {
$query->andWhere($query->expr()->eq('e.active', "'TRUE'"));
}
}
}

View File

@ -19,6 +19,7 @@ use Chill\MainBundle\Controller\LanguageController;
use Chill\MainBundle\Controller\LocationController;
use Chill\MainBundle\Controller\LocationTypeController;
use Chill\MainBundle\Controller\UserController;
use Chill\MainBundle\Controller\UserJobApiController;
use Chill\MainBundle\Controller\UserJobController;
use Chill\MainBundle\DependencyInjection\Widget\Factory\WidgetFactoryInterface;
use Chill\MainBundle\Doctrine\DQL\GetJsonFieldByKey;
@ -504,6 +505,7 @@ class ChillMainExtension extends Extension implements
'name' => 'user_job',
'base_path' => '/api/1.0/main/user-job',
'base_role' => 'ROLE_USER',
'controller' => UserJobApiController::class,
'actions' => [
'_index' => [
'methods' => [

View File

@ -0,0 +1,39 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20220711150006 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_main_workflow_entity_step
DROP CONSTRAINT chill_custom_only_one_step_opened');
}
public function getDescription(): string
{
return 'Add a constraint to ensure that only one step is available at a time';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_main_workflow_entity_step
ADD CONSTRAINT chill_custom_only_one_step_opened
EXCLUDE (
entityworkflow_id WITH =
) WHERE (transitionafter IS NULL)
DEFERRABLE INITIALLY DEFERRED');
}
}

View File

@ -177,7 +177,7 @@ class AccompanyingCourseController extends Controller
*/
public function editAction(AccompanyingPeriod $accompanyingCourse): Response
{
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::SEE, $accompanyingCourse);
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::EDIT, $accompanyingCourse);
return $this->render('@ChillPerson/AccompanyingCourse/edit.html.twig', [
'accompanyingCourse' => $accompanyingCourse,
@ -215,7 +215,7 @@ class AccompanyingCourseController extends Controller
// get persons without household
$withoutHousehold = [];
foreach ($accompanyingCourse->getParticipations() as $p) {
foreach ($accompanyingCourse->getCurrentParticipations() as $p) {
if (false === $p->getPerson()->isSharingHousehold()) {
$withoutHousehold[] = $p->getPerson();
}

View File

@ -40,7 +40,7 @@ class Comment implements TrackCreationInterface, TrackUpdateInterface
/**
* @ORM\Column(type="text")
* @Groups({"read", "write"})
* @Groups({"read", "write", "docgen:read"})
* @Assert\NotBlank
* @Assert\NotNull
*/
@ -48,14 +48,14 @@ class Comment implements TrackCreationInterface, TrackUpdateInterface
/**
* @ORM\Column(type="datetime")
* @Groups({"read"})
* @Groups({"read", "docgen:read"})
*/
private $createdAt;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false)
* @Groups({"read"})
* @Groups({"read", "docgen:read"})
*/
private $creator;
@ -63,7 +63,7 @@ class Comment implements TrackCreationInterface, TrackUpdateInterface
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"read"})
* @Groups({"read", "docgen:read"})
*/
private $id;

View File

@ -14,6 +14,7 @@ namespace Chill\PersonBundle\Entity\Household;
use ArrayIterator;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder;
use DateTime;
use DateTimeImmutable;
@ -354,7 +355,12 @@ class Household
return $this->members;
}
public function getMembersDuringMembership(HouseholdMember $membership)
/**
* get all the members during a given membership.
*
* @return Collection|HouseholdMember[]
*/
public function getMembersDuringMembership(HouseholdMember $membership): Collection
{
return $this->getMembersOnRange(
$membership->getStartDate(),
@ -441,6 +447,28 @@ class Household
return $this->getNonCurrentMembers($now)->matching($criteria);
}
/**
* get all the unique persons during a given membership.
*
* same as @see(self::getMembersDuringMembership}, except that the collection is filtered to
* return unique members.
*
* @return Collection|Person[]
*/
public function getPersonsDuringMembership(HouseholdMember $member): Collection
{
// make list unique
$membersByHash = [];
foreach ($this->getMembersDuringMembership($member) as $m) {
if (null !== $m && null !== $m->getPerson()) {
$membersByHash[spl_object_hash($m->getPerson())] = $m->getPerson();
}
}
return new ArrayCollection(array_values($membersByHash));
}
public function getPreviousAddressOf(Address $address): ?Address
{
$iterator = new ArrayIterator($this->getAddressesOrdered());

View File

@ -1,7 +1,7 @@
<div class="alert alert-warning alert-with-actions">
<div class="float-button bottom">
<div class="box">
{% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_UPDATE', accompanyingCourse) %}
<div class="action">
<ul class="record_actions">
<li>
@ -13,6 +13,8 @@
</li>
</ul>
</div>
{% endif %}
<p>{{ 'Some peoples does not belong to any household currently. Add them to an household soon'|trans }}</p>
</div>
</div>

View File

@ -3,6 +3,7 @@
<div class="alert alert-danger {% if hasPersonLocation %}alert-with-actions{% endif %}">
<div class="float-button bottom">
<div class="box">
{% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_UPDATE', accompanyingCourse) %}
<div class="action">
<ul class="record_actions">
<li>
@ -14,6 +15,7 @@
</li>
</ul>
</div>
{% endif %}
<p>
{{ 'This course is located at a temporarily address. You should locate this course to an user'|trans }}</p>
{% if not hasPersonLocation %}

View File

@ -14,7 +14,7 @@
{% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_UPDATE', period) %}
<div class="item-col item-meta">
{% set job_id = null %}
{% if period.job is defined %}
{% if period.job is not null %}
{% set job_id = period.job.id %}
{% endif %}
<span

View File

@ -48,13 +48,57 @@
{% endmacro %}
{% block content %}
<div class="flex-table accompanyingcourse-list">
{% for period in accompanying_periods %}
{%- set acps = [] %}
{%- set acpsClosed = [] %}
{% for acp in accompanying_periods %}
{% if acp.step == 'CLOSED' or (acp.requestorPerson is not same as(person) and acp.openParticipationContainsPerson(person) is null ) %}
{%- set acpsClosed = acpsClosed|merge([acp]) %}
{% else %}
{%- set acps = acps|merge([acp]) %}
{% endif %}
{% endfor %}
<div class="flex-table accompanyingcourse-list">
{% for period in acps %}
{% include 'ChillPersonBundle:AccompanyingPeriod:_list_item.html.twig' with {
'recordAction': _self.recordAction(period, contextEntity)
} %}
{% else %}
<p class="chill-no-data-statement">{{ 'Any accompanying periods are open'|trans }}</p>
{% endfor %}
</div>
{% if acpsClosed|length > 0 %}
<div class="accordion" id="member_{{ person.id }}">
<div class="accordion-item">
<h2 class="accordion-header" id="heading_{{ person.id }}">
<button
class="accordion-button collapsed"
type="button"
data-bs-toggle="collapse"
data-bs-target="#collapse_{{ person.id }}"
aria-expanded="false"
aria-controls="collapse_{{ person.id }}">
<span class="folded">{{ 'periods.show closed periods'|trans({ 'nb_items': acpsClosed|length }) }}</span>
<span class="unfolded text-secondary">{{ 'periods.hide closed periods'|trans({ 'nb_items': acpsClosed|length }) }}</span>
</button>
</h2>
<div id="collapse_{{ person.id }}"
class="accordion-collapse collapse"
aria-labelledby="heading_{{ person.id }}"
data-bs-parent="#nonCurrent">
<div class="flex-table accompanyingcourse-list">
{% for period in acpsClosed %}
{% include 'ChillPersonBundle:AccompanyingPeriod:_list_item.html.twig' with {
'recordAction': _self.recordAction(period, contextEntity)
} %}
{% endfor %}
</div>
</div>
</div>
</div>
{% endif %}
{% endblock content %}

View File

@ -65,18 +65,18 @@
<h3>{{ 'household.Members at same time'|trans }}</h3>
</div>
<div class="wl-col list">
{% set simultaneous = p.household.getMembersDuringMembership(p) %}
{% set simultaneous = p.household.getPersonsDuringMembership(p) %}
{% if simultaneous|length == 0 %}
<p class="chill-no-data-statement">
{{ 'household.Any simultaneous members'|trans }}
</p>
{% else %}
{% for m in simultaneous -%}
{% for person in simultaneous -%}
{% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with {
action: 'show', displayBadge: true,
targetEntity: { name: 'person', id: m.person.id },
buttonText: m.person|chill_entity_render_string,
isDead: m.person.deathdate is not null
targetEntity: { name: 'person', id: person.id },
buttonText: person|chill_entity_render_string,
isDead: person.deathdate is not null
} %}
{%- endfor -%}
{% endif %}

View File

@ -1,13 +1,15 @@
{% macro button_person_after(person) %}
{% set household = person.getCurrentHousehold %}
{% if household is not null %}
{% if household is not null and is_granted('CHILL_PERSON_HOUSEHOLD_SEE', household) %}
<li>
<a href="{{ path('chill_person_household_summary', { 'household_id': household.id }) }}" class="btn btn-sm btn-chill-beige"><i class="fa fa-home"></i></a>
</li>
{% endif %}
<li>
<a href="{{ path('chill_person_accompanying_course_new', { 'person_id': [ person.id ]}) }}" class="btn btn-sm btn-create change-icon" title="{{ 'Create an accompanying period'|trans }}"><i class="fa fa-random"></i></a>
</li>
{% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_CREATE', person) %}
<li>
<a href="{{ path('chill_person_accompanying_course_new', { 'person_id': [ person.id ]}) }}" class="btn btn-sm btn-create change-icon" title="{{ 'Create an accompanying period'|trans }}"><i class="fa fa-random"></i></a>
</li>
{% endif %}
{% endmacro %}
{% macro accompanying_period(acp, person) %}
@ -251,7 +253,8 @@
{%- set acpsClosed = [] %}
{%- for acp in person.accompanyingPeriodInvolved %}
{%- if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', acp) %}
{% if acp.step == 'CLOSED' %}
{# filter for "current" periods: either the person is a requestor, or is member of the period and not closed #}
{% if acp.step == 'CLOSED' or (acp.requestorPerson is not same as(person) and acp.openParticipationContainsPerson(person) is null ) %}
{%- set acpsClosed = acpsClosed|merge([acp]) %}
{% else %}
{%- set acps = acps|merge([acp]) %}

View File

@ -113,7 +113,7 @@ class AccompanyingPeriodVoter extends AbstractChillVoter implements ProvideRoleH
->generate(self::class)
->addCheckFor(null, [self::CREATE, self::REASSIGN_BULK])
->addCheckFor(AccompanyingPeriod::class, [self::TOGGLE_CONFIDENTIAL, ...self::ALL])
->addCheckFor(Person::class, [self::SEE])
->addCheckFor(Person::class, [self::SEE, self::CREATE])
->build();
}

View File

@ -71,6 +71,7 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
'location' => Address::class,
'locationPerson' => Person::class,
'administrativeLocation' => Location::class,
'pinnedComment' => AccompanyingPeriod\Comment::class,
];
private ClosingMotiveRender $closingMotiveRender;
@ -164,6 +165,8 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
'location' => $this->normalizer->normalize($period->getLocation(), $format, $addressContext),
'administrativeLocation' => $this->normalizer->normalize($period->getAdministrativeLocation(), $format, $administrativeLocationContext),
'works' => $this->normalizer->normalize($period->getWorks(), $format, $workContext),
'comments' => $this->normalizer->normalize($period->getComments(), $format, array_merge($context, ['docgen:expects' => AccompanyingPeriod\Comment::class])),
'pinnedComment' => $this->normalizer->normalize($period->getPinnedComment(), $format, array_merge($context, ['docgen:expects' => AccompanyingPeriod\Comment::class])),
];
}
@ -183,6 +186,7 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
'hasLocationPerson' => false,
'hasAdministrativeLocation' => false,
'works' => [],
'comments' => [],
]
);
}

View File

@ -135,4 +135,51 @@ final class HouseholdTest extends TestCase
$this->assertEquals(new DateTimeImmutable('2021-12-31'), $second->getStartDate());
$this->assertEquals(new DateTimeImmutable('2021-12-31'), $inside->getEndDate());
}
public function testHouseholdGetPersonsDuringMembership()
{
$household = new Household();
$person1 = new Person();
$person2 = new Person();
$personOut = new Person();
$household->addMember(
$member1 = (new HouseholdMember())
->setStartDate(new DateTimeImmutable('2021-01-01'))
->setEndDate(new DateTimeImmutable('2021-12-01'))
->setPerson($person1)
);
$household->addMember(
$member2a = (new HouseholdMember())
->setStartDate(new DateTimeImmutable('2021-01-01'))
->setEndDate(new DateTimeImmutable('2021-05-01'))
->setPerson($person2)
);
$household->addMember(
$member2b = (new HouseholdMember())
->setStartDate(new DateTimeImmutable('2021-11-01'))
->setEndDate(new DateTimeImmutable('2022-06-01'))
->setPerson($person2)
);
$household->addMember(
$memberOut = (new HouseholdMember())
->setStartDate(new DateTimeImmutable('2019-01-01'))
->setEndDate(new DateTimeImmutable('2019-12-01'))
->setPerson($personOut)
);
$this->assertCount(0, $household->getPersonsDuringMembership($memberOut));
$this->assertCount(1, $household->getPersonsDuringMembership($member1));
$this->assertContains($person2, $household->getPersonsDuringMembership($member1));
$this->assertCount(1, $household->getPersonsDuringMembership($member2a));
$this->assertContains($person1, $household->getPersonsDuringMembership($member2a));
$this->assertCount(1, $household->getPersonsDuringMembership($member2b));
$this->assertContains($person1, $household->getPersonsDuringMembership($member2b));
}
}

View File

@ -68,6 +68,8 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
'closingMotive' => '@ignored',
'confidential' => true,
'confidentialText' => 'confidentiel',
'comments' => '@ignored',
'pinnedComment' => '@ignored',
'createdAt' => '@ignored',
'createdBy' => '@ignored',
'emergency' => true,