From a1baf992949a2cbde7fd69813096c17a2bddf1ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 7 Apr 2022 15:54:53 +0200 Subject: [PATCH] able to see the workflow if the evaluation document has been deleted --- .../Authorization/EntityWorkflowVoter.php | 8 +- .../Workflow/_evaluation_document.html.twig | 246 +++++++++--------- ...dWorkEvaluationDocumentWorkflowHandler.php | 12 +- .../translations/messages.fr.yml | 1 + 4 files changed, 145 insertions(+), 122 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/EntityWorkflowVoter.php b/src/Bundle/ChillMainBundle/Security/Authorization/EntityWorkflowVoter.php index fe0597e6b..d8d74fbb9 100644 --- a/src/Bundle/ChillMainBundle/Security/Authorization/EntityWorkflowVoter.php +++ b/src/Bundle/ChillMainBundle/Security/Authorization/EntityWorkflowVoter.php @@ -59,7 +59,13 @@ class EntityWorkflowVoter extends Voter return true; } - return $this->security->isGranted($entityAttribute, $handler->getRelatedEntity($subject)); + $relatedEntity = $handler->getRelatedEntity($subject); + + if (null === $relatedEntity) { + return true; + } + + return $this->security->isGranted($entityAttribute, $relatedEntity); case self::DELETE: return $subject->getStep() === 'initial'; diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Workflow/_evaluation_document.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Workflow/_evaluation_document.html.twig index 2e05a6648..984277297 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Workflow/_evaluation_document.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Workflow/_evaluation_document.html.twig @@ -1,133 +1,139 @@ {%- import "@ChillDocStore/Macro/macro.html.twig" as m -%} -
-
-
-

{{ doc.title }}

-
-
-

- - - {{ evaluation.accompanyingPeriodWork.socialAction|chill_entity_render_string }} -
    -
  • - {{ 'accompanying_course_work.start_date'|trans ~ ' : ' }} - {{ evaluation.accompanyingPeriodWork.startDate|format_date('short') }} -
  • - {% if evaluation.accompanyingPeriodWork.endDate %} +{% if doc is null %} +
    + {{ 'workflow.doc for evaluation deleted'|trans }} +
    +{% else %} +
    +
    +
    +

    {{ doc.title }}

    +
    +
    +

    + + + {{ evaluation.accompanyingPeriodWork.socialAction|chill_entity_render_string }} +
    • - {{ 'accompanying_course_work.end_date'|trans ~ ' : ' }} - {{ evaluation.accompanyingPeriodWork.endDate|format_date('short') }} + {{ 'accompanying_course_work.start_date'|trans ~ ' : ' }} + {{ evaluation.accompanyingPeriodWork.startDate|format_date('short') }}
    • - {% endif %} -
    -
    -

    -
    -
    -
    -

    - {{ 'Participants'|trans }} -

    -
    -
    - {% for p in evaluation.accompanyingPeriodWork.persons %} - {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with { - targetEntity: { name: 'person', id: p.id }, - action: 'show', - displayBadge: true, - buttonText: p|chill_entity_render_string, - isDead: p.deathdate is not null - } %} - {% endfor %} -
    -
    -
    - - - - - - - - - - - -
    -

    - {{ 'Évaluation'|trans }} -

    -
    -
      -
    • - {{ evaluation.evaluation.title|localize_translatable_string }} -
        -
      • - {{ 'accompanying_course_work.start_date'|trans ~ ' : ' }} - {{ evaluation.startDate|format_date('short') }} -
      • - {% if evaluation.endDate %} -
      • - {{ 'accompanying_course_work.end_date'|trans ~ ' : ' }} - {{ evaluation.endDate|format_date('short') }} -
      • - {% endif %} - {% if evaluation.maxDate %} -
      • - {{ 'accompanying_course_work.max_date'|trans ~ ' : ' }} - {{ evaluation.maxDate|format_date('short') }} -
      • - {% endif %} - {% if evaluation.warningInterval and evaluation.warningInterval.d > 0 %} -
      • - {% set days = (evaluation.warningInterval.d + evaluation.warningInterval.m * 30) %} - {{ 'accompanying_course_work.warning_interval'|trans ~ ' : ' }} - {{ 'accompanying_course_work.%days% days before max_date'|trans({'%days%': days }) }} -
      • - {% endif %} -
      • - {% if evaluation.createdBy is not null %} - créé par - {{ evaluation.createdBy.username }} - {% endif %} - {% if evaluation.createdAt is not null %} - {{ 'le'|trans }} - {{ evaluation.createdAt|format_date('short') }} - {% endif %} -
      • -
      - {% if evaluation.comment %} -
      - {{ evaluation.comment }} -
      - {% endif %} + {% if evaluation.accompanyingPeriodWork.endDate %} +
    • + {{ 'accompanying_course_work.end_date'|trans ~ ' : ' }} + {{ evaluation.accompanyingPeriodWork.endDate|format_date('short') }}
    • -
    -
    -
    -
    - {% import '@ChillPerson/Macro/updatedBy.html.twig' as macro %} - {{ macro.updatedBy(evaluation) }} + {% endif %} +
+
+

+
+
+
+

+ {{ 'Participants'|trans }} +

+
+
+ {% for p in evaluation.accompanyingPeriodWork.persons %} + {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with { + targetEntity: { name: 'person', id: p.id }, + action: 'show', + displayBadge: true, + buttonText: p|chill_entity_render_string, + isDead: p.deathdate is not null + } %} + {% endfor %} +
+
+
+ + + + + + + + + + + +
+

+ {{ 'Évaluation'|trans }} +

+
+
    +
  • + {{ evaluation.evaluation.title|localize_translatable_string }} +
      +
    • + {{ 'accompanying_course_work.start_date'|trans ~ ' : ' }} + {{ evaluation.startDate|format_date('short') }} +
    • + {% if evaluation.endDate %} +
    • + {{ 'accompanying_course_work.end_date'|trans ~ ' : ' }} + {{ evaluation.endDate|format_date('short') }} +
    • + {% endif %} + {% if evaluation.maxDate %} +
    • + {{ 'accompanying_course_work.max_date'|trans ~ ' : ' }} + {{ evaluation.maxDate|format_date('short') }} +
    • + {% endif %} + {% if evaluation.warningInterval and evaluation.warningInterval.d > 0 %} +
    • + {% set days = (evaluation.warningInterval.d + evaluation.warningInterval.m * 30) %} + {{ 'accompanying_course_work.warning_interval'|trans ~ ' : ' }} + {{ 'accompanying_course_work.%days% days before max_date'|trans({'%days%': days }) }} +
    • + {% endif %} +
    • + {% if evaluation.createdBy is not null %} + créé par + {{ evaluation.createdBy.username }} + {% endif %} + {% if evaluation.createdAt is not null %} + {{ 'le'|trans }} + {{ evaluation.createdAt|format_date('short') }} + {% endif %} +
    • +
    + {% if evaluation.comment %} +
    + {{ evaluation.comment }} +
    + {% endif %} +
  • +
+
+
+
+ {% import '@ChillPerson/Macro/updatedBy.html.twig' as macro %} + {{ macro.updatedBy(evaluation) }} +
- -{% if display_action is defined and display_action == true %} - {% if is_granted('CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_UPDATE', evaluation.accompanyingPeriodWork) %} - {% endif %} {% endif %} diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php index d7ce1ed4b..578d8e195 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php @@ -48,6 +48,12 @@ class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityW { $doc = $this->getRelatedEntity($entityWorkflow); + if (null === $doc) { + return [ + 'persons' => [], + ]; + } + return [ 'persons' => $doc->getAccompanyingPeriodWorkEvaluation() ->getAccompanyingPeriodWork()->getPersons(), @@ -58,6 +64,10 @@ class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityW { $doc = $this->getRelatedEntity($entityWorkflow); + if (null === $doc) { + return $this->translator->trans('workflow.doc for evaluation deleted'); + } + return $this->translator->trans( 'workflow.Doc for evaluation (n°%eval%)', ['%eval%' => $entityWorkflow->getRelatedEntityId()] @@ -98,7 +108,7 @@ class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityW return [ 'entity_workflow' => $entityWorkflow, - 'evaluation' => $doc->getAccompanyingPeriodWorkEvaluation(), + 'evaluation' => null !== $doc ? $doc->getAccompanyingPeriodWorkEvaluation() : $doc, 'doc' => $doc, ]; } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index ae7687324..ab8ab0c67 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -581,6 +581,7 @@ My accompanying periods in draft: Mes parcours brouillons workflow: Doc for evaluation (n°%eval%): Document de l'évaluation n°%eval% + doc for evaluation deleted: Document supprimé dans une évaluation period_by_user_list: Period by user: Parcours d'accompagnement par utilisateur