From 02a7074218f5ae98588ee99db2341fdbff54e4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 25 Nov 2022 15:57:50 +0100 Subject: [PATCH 1/7] Fixed: [calendar] Do not require scope when adding calendar roles --- .../Security/Voter/CalendarVoter.php | 10 +++++- .../migrations/Version20221125144205.php | 33 +++++++++++++++++++ .../translations/messages.fr.yml | 6 ++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillCalendarBundle/migrations/Version20221125144205.php diff --git a/src/Bundle/ChillCalendarBundle/Security/Voter/CalendarVoter.php b/src/Bundle/ChillCalendarBundle/Security/Voter/CalendarVoter.php index ded8d2062..996b5ebfb 100644 --- a/src/Bundle/ChillCalendarBundle/Security/Voter/CalendarVoter.php +++ b/src/Bundle/ChillCalendarBundle/Security/Voter/CalendarVoter.php @@ -61,6 +61,9 @@ class CalendarVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn public function getRoles(): array { return [ + self::CREATE, + self::DELETE, + self::EDIT, self::SEE, ]; } @@ -72,7 +75,12 @@ class CalendarVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn public function getRolesWithoutScope(): array { - return []; + return [ + self::CREATE, + self::DELETE, + self::EDIT, + self::SEE, + ]; } protected function supports($attribute, $subject): bool diff --git a/src/Bundle/ChillCalendarBundle/migrations/Version20221125144205.php b/src/Bundle/ChillCalendarBundle/migrations/Version20221125144205.php new file mode 100644 index 000000000..c619dd228 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/migrations/Version20221125144205.php @@ -0,0 +1,33 @@ +addSql( + sprintf( + 'UPDATE role_scopes SET scope_id=NULL WHERE role IN (\'%s\', \'%s\', \'%s\', \'%s\')', + 'CHILL_CALENDAR_CALENDAR_CREATE', + 'CHILL_CALENDAR_CALENDAR_DELETE', + 'CHILL_CALENDAR_CALENDAR_EDIT', + 'CHILL_CALENDAR_CALENDAR_SEE' + )); + } + + public function down(Schema $schema): void + { + $this->throwIrreversibleMigrationException(); + } +} diff --git a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml index a24d6aecb..e5922ada3 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml @@ -130,3 +130,9 @@ docgen: Destinee: Destinataire None: Aucun choix title of the generated document: Titre du document généré + +CHILL_CALENDAR_CALENDAR_CREATE: Créer les rendez-vous +CHILL_CALENDAR_CALENDAR_EDIT: Modifier les rendez-vous +CHILL_CALENDAR_CALENDAR_DELETE: Supprimer les rendez-vous +CHILL_CALENDAR_CALENDAR_SEE: Voir les rendez-vous + From b6e3baa5dc2cd5357736d71a9f4b48d5a63e716d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 25 Nov 2022 16:04:40 +0100 Subject: [PATCH 2/7] DX: fix cs --- .../Export/Filter/BetweenDatesFilter.php | 1 - .../migrations/Version20221125144205.php | 20 +++++++++++++------ .../Form/Type/PickRollingDateType.php | 10 +++++----- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php b/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php index 23887ca2a..59019ac03 100644 --- a/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php +++ b/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php @@ -16,7 +16,6 @@ use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; -use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; diff --git a/src/Bundle/ChillCalendarBundle/migrations/Version20221125144205.php b/src/Bundle/ChillCalendarBundle/migrations/Version20221125144205.php index c619dd228..624fdda00 100644 --- a/src/Bundle/ChillCalendarBundle/migrations/Version20221125144205.php +++ b/src/Bundle/ChillCalendarBundle/migrations/Version20221125144205.php @@ -2,6 +2,13 @@ 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\Migrations\Calendar; use Doctrine\DBAL\Schema\Schema; @@ -9,6 +16,11 @@ use Doctrine\Migrations\AbstractMigration; final class Version20221125144205 extends AbstractMigration { + public function down(Schema $schema): void + { + $this->throwIrreversibleMigrationException(); + } + public function getDescription(): string { return 'Calendar: remove association between scope and calendar'; @@ -23,11 +35,7 @@ final class Version20221125144205 extends AbstractMigration 'CHILL_CALENDAR_CALENDAR_DELETE', 'CHILL_CALENDAR_CALENDAR_EDIT', 'CHILL_CALENDAR_CALENDAR_SEE' - )); - } - - public function down(Schema $schema): void - { - $this->throwIrreversibleMigrationException(); + ) + ); } } diff --git a/src/Bundle/ChillMainBundle/Form/Type/PickRollingDateType.php b/src/Bundle/ChillMainBundle/Form/Type/PickRollingDateType.php index 5b5bff6b3..a4492526f 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/PickRollingDateType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/PickRollingDateType.php @@ -44,6 +44,11 @@ class PickRollingDateType extends AbstractType $builder->setDataMapper(new RollingDateDataMapper()); } + public function buildView(FormView $view, FormInterface $form, array $options) + { + $view->vars['uniqid'] = uniqid('rollingdate-'); + } + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ @@ -65,9 +70,4 @@ class PickRollingDateType extends AbstractType ->addViolation(); } } - - public function buildView(FormView $view, FormInterface $form, array $options) - { - $view->vars['uniqid'] = uniqid('rollingdate-'); - } } From 6eb23c607334bcf72c8af73bced23e7203592dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 25 Nov 2022 16:28:00 +0100 Subject: [PATCH 3/7] Feature: [calendar] add proper location on short message text for next rendez-vous --- .../Resources/views/CalendarShortMessage/short_message.txt.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/CalendarShortMessage/short_message.txt.twig b/src/Bundle/ChillCalendarBundle/Resources/views/CalendarShortMessage/short_message.txt.twig index d6c46a7e9..1669ac1d1 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/CalendarShortMessage/short_message.txt.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/CalendarShortMessage/short_message.txt.twig @@ -1 +1 @@ -Votre travailleur social {{ calendar.mainUser.label }} vous rencontrera le {{ calendar.startDate|format_date('short', locale='fr') }} à {{ calendar.startDate|format_time('short', locale='fr') }} - LIEU.{% if calendar.mainUser.mainLocation is not null and calendar.mainUser.mainLocation.phonenumber1 is not null %} En cas d'indisponibilité, appelez-nous au {{ calendar.mainUser.mainLocation.phonenumber1|chill_format_phonenumber }}.{% endif %} +Votre travailleur social {{ calendar.mainUser.label }} vous rencontrera le {{ calendar.startDate|format_date('short', locale='fr') }} à {{ calendar.startDate|format_time('short', locale='fr') }} - {% if calendar.location is not null%}{{ calendar.location.name }}{% endif %}{% if calendar.mainUser.mainLocation is not null and calendar.mainUser.mainLocation.phonenumber1 is not null %} En cas d'indisponibilité, appelez-nous au {{ calendar.mainUser.mainLocation.phonenumber1|chill_format_phonenumber }}.{% endif %} From 57e1786b994fea721c8c8749980a37cba025530b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 25 Nov 2022 16:50:56 +0100 Subject: [PATCH 4/7] Fixed: [calendar] Always show filter of calendars in list --- .../Resources/views/Calendar/_list.html.twig | 2 -- .../Resources/views/Calendar/listByAccompanyingCourse.html.twig | 2 ++ .../Resources/views/Calendar/listByPerson.html.twig | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig index 3eb1d6634..af22a96ec 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig @@ -1,7 +1,5 @@ {# list used in context of person or accompanyingPeriod #} -{{ filterOrder|chill_render_filter_order_helper }} - {% if calendarItems|length > 0 %}
diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig index f1b0c6110..56c1ba880 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig @@ -23,6 +23,8 @@

{{ 'Calendar list' |trans }}

+ {{ filterOrder|chill_render_filter_order_helper }} + {% if calendarItems|length == 0 %}

{{ "There is no calendar items."|trans }} diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByPerson.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByPerson.html.twig index 6d991fb53..dc849202e 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByPerson.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByPerson.html.twig @@ -22,6 +22,8 @@

{{ 'Calendar list' |trans }}

+ {{ filterOrder|chill_render_filter_order_helper }} + {% if calendarItems|length == 0 %}

{{ "There is no calendar items."|trans }} From 788b1e9eeb31df17f24f1df760c2ff1aa91e2aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 25 Nov 2022 16:51:41 +0100 Subject: [PATCH 5/7] Fixed: [calendar] Fix picking calendar document templating, when adding document in person context --- .../Controller/CalendarDocController.php | 22 ++++++++---- ...ck_template_accompanying_period.html.twig} | 13 +++++++ .../pick_template_person.html.twig | 35 +++++++++++++++++++ 3 files changed, 64 insertions(+), 6 deletions(-) rename src/Bundle/ChillCalendarBundle/Resources/views/CalendarDoc/{pick_template.html.twig => pick_template_accompanying_period.html.twig} (58%) create mode 100644 src/Bundle/ChillCalendarBundle/Resources/views/CalendarDoc/pick_template_person.html.twig diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php index 2c9074488..cdadb65e5 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php @@ -72,11 +72,21 @@ class CalendarDocController ); } - return new Response( - $this->engine->render('@ChillCalendar/CalendarDoc/pick_template.html.twig', [ - 'calendar' => $calendar, - 'accompanyingCourse' => $calendar->getAccompanyingPeriod(), - ]) - ); + switch ($calendar->getContext()) { + case 'person': + return new Response( + $this->engine->render('@ChillCalendar/CalendarDoc/pick_template_person.html.twig', [ + 'calendar' => $calendar, + ]) + ); + case 'accompanying_period': + return new Response( + $this->engine->render('@ChillCalendar/CalendarDoc/pick_template_accompanying_period.html.twig', [ + 'calendar' => $calendar, + ]) + ); + default: + throw new \UnexpectedValueException("calendar context not expected : " . $calendar->getContext()); + } } } diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/CalendarDoc/pick_template.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/CalendarDoc/pick_template_accompanying_period.html.twig similarity index 58% rename from src/Bundle/ChillCalendarBundle/Resources/views/CalendarDoc/pick_template.html.twig rename to src/Bundle/ChillCalendarBundle/Resources/views/CalendarDoc/pick_template_accompanying_period.html.twig index 561f92f0c..8e5226faa 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/CalendarDoc/pick_template.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/CalendarDoc/pick_template_accompanying_period.html.twig @@ -5,6 +5,7 @@ {% block title %}{{ 'chill_calendar.Add a document' |trans }}{% endblock title %} {% set user_id = null %} +{% set accompanyingCourse = calendar.accompanyingPeriod %} {% set accompanying_course_id = accompanyingCourse.id %} {% block js %} @@ -19,6 +20,18 @@ {% block content %} +

{{ 'chill_calendar.Add a document'|trans }}

+ +

+ {% if calendar.endDate.diff(calendar.startDate).days >= 1 %} + {{ calendar.startDate|format_datetime('short', 'short') }} + - {{ calendar.endDate|format_datetime('short', 'short') }} + {% else %} + {{ calendar.startDate|format_datetime('short', 'short') }} + - {{ calendar.endDate|format_datetime('none', 'short') }} + {% endif %} +

+
{% endblock %} diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/CalendarDoc/pick_template_person.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/CalendarDoc/pick_template_person.html.twig new file mode 100644 index 000000000..a331f7fd7 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/views/CalendarDoc/pick_template_person.html.twig @@ -0,0 +1,35 @@ +{% extends "@ChillPerson/Person/layout.html.twig" %} + +{% set activeRouteKey = 'chill_calendar_calendar_list' %} + +{% block title %}{{ 'chill_calendar.Add a document' |trans }}{% endblock title %} + +{% set person = calendar.person %} + +{% block js %} + {{ parent() }} + {{ encore_entry_script_tags('mod_docgen_picktemplate') }} +{% endblock %} + +{% block css %} + {{ parent() }} + {{ encore_entry_link_tags('mod_docgen_picktemplate') }} +{% endblock %} + +{% block content %} + +

{{ 'chill_calendar.Add a document'|trans }}

+ +

+ {% if calendar.endDate.diff(calendar.startDate).days >= 1 %} + {{ calendar.startDate|format_datetime('short', 'short') }} + - {{ calendar.endDate|format_datetime('short', 'short') }} + {% else %} + {{ calendar.startDate|format_datetime('short', 'short') }} + - {{ calendar.endDate|format_datetime('none', 'short') }} + {% endif %} +

+ +
+ +{% endblock %} From 9b32ce53c8e4bce0b8543eaa15a24d09b4a9384c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 25 Nov 2022 17:02:12 +0100 Subject: [PATCH 6/7] Fixed: [calendar] add a return path to calendar doc See https://gitlab.com/Chill-Projet/chill-bundles/-/issues/23 --- .../Controller/CalendarDocController.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php index cdadb65e5..ba7951225 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php @@ -16,6 +16,7 @@ use Chill\CalendarBundle\Security\Voter\CalendarVoter; use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository; use RuntimeException; use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -47,7 +48,7 @@ class CalendarDocController /** * @Route("/{_locale}/calendar/docgen/pick/{id}", name="chill_calendar_calendardoc_pick_template") */ - public function pickTemplate(Calendar $calendar): Response + public function pickTemplate(Calendar $calendar, Request $request): Response { if (!$this->security->isGranted(CalendarVoter::SEE, $calendar)) { throw new AccessDeniedException('Not authorized to see this calendar'); @@ -60,14 +61,21 @@ class CalendarDocController if (1 === $number) { $templates = $this->docGeneratorTemplateRepository->findByEntity(Calendar::class); + if ($request->query->has('returnPath')) { + $returnPathParam = ['returnPath' => $request->query->get('returnPath')]; + } + return new RedirectResponse( $this->urlGenerator->generate( 'chill_docgenerator_generate_from_template', - [ - 'template' => $templates[0]->getId(), - 'entityClassName' => Calendar::class, - 'entityId' => $calendar->getId(), - ] + array_merge( + $returnPathParam ?? [], + [ + 'template' => $templates[0]->getId(), + 'entityClassName' => Calendar::class, + 'entityId' => $calendar->getId(), + ] + ) ) ); } From 8cbfe16c244d8b38712253d8d96d8992ffa0e1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 25 Nov 2022 17:02:57 +0100 Subject: [PATCH 7/7] DX: Fix cs --- .../ChillCalendarBundle/Controller/CalendarDocController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php index ba7951225..1f6b42dea 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php @@ -24,6 +24,7 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\Security; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Templating\EngineInterface; +use UnexpectedValueException; class CalendarDocController { @@ -87,14 +88,16 @@ class CalendarDocController 'calendar' => $calendar, ]) ); + case 'accompanying_period': return new Response( $this->engine->render('@ChillCalendar/CalendarDoc/pick_template_accompanying_period.html.twig', [ 'calendar' => $calendar, ]) ); + default: - throw new \UnexpectedValueException("calendar context not expected : " . $calendar->getContext()); + throw new UnexpectedValueException('calendar context not expected : ' . $calendar->getContext()); } } }