diff --git a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml index 81a34d47d..051497b69 100644 --- a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml @@ -76,7 +76,7 @@ activity: Insert a document: Insérer un document Remove a document: Supprimer le document comment: Commentaire -No documents: Pas de documents +No documents: Aucun document #timeline '%user% has done an %activity_type%': '%user% a effectué une activité de type "%activity_type%"' diff --git a/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php b/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php index 199f88c60..ae8db17f6 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php @@ -21,6 +21,8 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod; use DateTime; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\Form\Extension\Core\Type\FormType; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -59,21 +61,37 @@ class DocumentAccompanyingCourseController extends AbstractController } /** - * @Route("/{id}", name="accompanying_course_document_delete", methods="DELETE") + * @Route("/{id}/delete", name="chill_docstore_accompanying_course_document_delete") */ public function delete(Request $request, AccompanyingPeriod $course, AccompanyingCourseDocument $document): Response { $this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::DELETE, $document); - if ($this->isCsrfTokenValid('delete' . $document->getId(), $request->request->get('_token'))) { - $em = $this->getDoctrine()->getManager(); - $em->remove($document); - $em->flush(); + $form = $this->createForm(FormType::class); + $form->add('submit', SubmitType::class, ['label' => 'Delete']); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->getDoctrine()->getManager()->remove($document); + $this->getDoctrine()->getManager()->flush(); + + $this->addFlash('success', $this->translator->trans('The document is successfully removed')); + + if ($request->query->has('returnPath')) { + return $this->redirect($request->query->get('returnPath')); + } + + return $this->redirectToRoute('accompanying_course_document_index', ['course' => $course->getId()]); } - return $this->redirectToRoute( - 'accompanying_course_document_index', - ['accompanyingCourse' => $course->getId()] + return $this->render( + 'ChillDocStoreBundle:AccompanyingCourseDocument:delete.html.twig', + [ + 'document' => $document, + 'delete_form' => $form->createView(), + 'accompanyingCourse' => $course, + ] ); } diff --git a/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php b/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php index eb9698aee..42e49ad3c 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php @@ -14,6 +14,7 @@ namespace Chill\DocStoreBundle\Controller; use Chill\DocStoreBundle\Entity\PersonDocument; use Chill\DocStoreBundle\Form\PersonDocumentType; use Chill\DocStoreBundle\Repository\PersonDocumentACLAwareRepositoryInterface; +use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\PersonBundle\Entity\Person; @@ -22,6 +23,8 @@ use Chill\PersonBundle\Security\Authorization\PersonVoter; use DateTime; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\Form\Extension\Core\Type\FormType; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -64,22 +67,37 @@ class DocumentPersonController extends AbstractController } /** - * @Route("/{id}", name="person_document_delete", methods="DELETE") + * @Route("/{id}/delete", name="chill_docstore_person_document_delete") */ public function delete(Request $request, Person $person, PersonDocument $document): Response { - $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); - $this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_DELETE', $document); + $this->denyAccessUnlessGranted(PersonDocumentVoter::DELETE, $document); - if ($this->isCsrfTokenValid('delete' . $document->getId(), $request->request->get('_token'))) { - $em = $this->getDoctrine()->getManager(); - $em->remove($document); - $em->flush(); + $form = $this->createForm(FormType::class); + $form->add('submit', SubmitType::class, ['label' => 'Delete']); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->getDoctrine()->getManager()->remove($document); + $this->getDoctrine()->getManager()->flush(); + + $this->addFlash('success', $this->translator->trans('The document is successfully removed')); + + if ($request->query->has('returnPath')) { + return $this->redirect($request->query->get('returnPath')); + } + + return $this->redirectToRoute('person_document_index', ['person' => $person->getId()]); } - return $this->redirectToRoute( - 'person_document_index', - ['person' => $person->getId()] + return $this->render( + 'ChillDocStoreBundle:PersonDocument:delete.html.twig', + [ + 'document' => $document, + 'delete_form' => $form->createView(), + 'person' => $person, + ] ); } diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/_delete_form.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/_delete_form.html.twig deleted file mode 100644 index 90ee734e0..000000000 --- a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/_delete_form.html.twig +++ /dev/null @@ -1,5 +0,0 @@ -
- - - -
diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/delete.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/delete.html.twig new file mode 100644 index 000000000..a6679829b --- /dev/null +++ b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/delete.html.twig @@ -0,0 +1,43 @@ +{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %} + +{% set activeRouteKey = '' %} + +{% block title %}{{ 'Delete document ?' }}{% endblock %} + +{% block docdescription %} +
+
{{ 'Title'|trans }}
+
{{ document.title }}
+ + {% if document.scope is not null %} +
{{ 'Scope' | trans }}
+
{{ document.scope.name | localize_translatable_string }}
+ {% endif %} + +
{{ 'Category'|trans }}
+
{{ document.category.name|localize_translatable_string }}
+ +
{{ 'Description' | trans }}
+
+ {% if document.description is empty %} + {{ 'Any description'|trans }} + {% else %} +
+ {{ document.description|chill_markdown_to_html }} +
+ {% endif %} +
+
+{% endblock %} + +{% block content %} +{{ include('@ChillMain/Util/confirmation_template.html.twig', + { + 'title' : 'Delete document ?'|trans, + 'display_content' : block('docdescription'), + 'confirm_question' : 'Are you sure you want to remove this document ?'|trans, + 'cancel_route' : 'accompanying_course_document_index', + 'cancel_parameters' : {'course' : accompanyingCourse.id, 'id': document.id}, + 'form' : delete_form + } ) }} +{% endblock %} diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/edit.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/edit.html.twig index d7a5325cf..0ca5661fc 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/edit.html.twig +++ b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/edit.html.twig @@ -25,8 +25,13 @@ {{ 'Back to the list' | trans }} -
  • - + {% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_DELETE', document) %} +
  • + +
  • + {% endif %} +
  • +
  • diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/show.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/show.html.twig index 1e4fdb8e6..45ed3988b 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/show.html.twig +++ b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/show.html.twig @@ -49,12 +49,9 @@ {{ 'Back to the list' | trans }} -
  • - {{ m.download_button(document.object, document.title) }} -
  • - {% if chill_document_is_editable(document.object) %} -
  • - {{ document.object|chill_document_edit_button }} + {% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_DELETE', document) %} +
  • +
  • {% endif %} {% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_UPDATE', document) %} @@ -63,6 +60,14 @@ class="btn btn-edit" title="{{ 'Edit attributes' | trans }}"> {% endif %} +
  • + {{ m.download_button(document.object, document.title) }} +
  • + {% if chill_document_is_editable(document.object) %} +
  • + {{ document.object|chill_document_edit_button }} +
  • + {% endif %} {% set workflows_frame = chill_entity_workflow_list('Chill\\DocStoreBundle\\Entity\\AccompanyingCourseDocument', document.id) %} {% if workflows_frame is not empty %}
  • diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/List/list_item.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/List/list_item.html.twig index 5ce03091b..8fbc3fa5c 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/views/List/list_item.html.twig +++ b/src/Bundle/ChillDocStoreBundle/Resources/views/List/list_item.html.twig @@ -44,6 +44,16 @@ - + diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/delete.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/delete.html.twig new file mode 100644 index 000000000..e3f6687fd --- /dev/null +++ b/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/delete.html.twig @@ -0,0 +1,43 @@ +{% extends "@ChillPerson/Person/layout.html.twig" %} + +{% set activeRouteKey = '' %} + +{% block title %}{{ 'Delete document ?' }}{% endblock %} + +{% block docdescription %} +
    +
    {{ 'Title'|trans }}
    +
    {{ document.title }}
    + + {% if document.scope is not null %} +
    {{ 'Scope' | trans }}
    +
    {{ document.scope.name | localize_translatable_string }}
    + {% endif %} + +
    {{ 'Category'|trans }}
    +
    {{ document.category.name|localize_translatable_string }}
    + +
    {{ 'Description' | trans }}
    +
    + {% if document.description is empty %} + {{ 'Any description'|trans }} + {% else %} +
    + {{ document.description|chill_markdown_to_html }} +
    + {% endif %} +
    +
    +{% endblock %} + +{% block personcontent %} +{{ include('@ChillMain/Util/confirmation_template.html.twig', + { + 'title' : 'Delete document ?'|trans, + 'display_content' : block('docdescription'), + 'confirm_question' : 'Are you sure you want to remove this document ?'|trans, + 'cancel_route' : 'person_document_index', + 'cancel_parameters' : {'person' : person.id, 'id': document.id}, + 'form' : delete_form + } ) }} +{% endblock %} diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/edit.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/edit.html.twig index 7533f1120..4a9eab8e3 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/edit.html.twig +++ b/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/edit.html.twig @@ -36,20 +36,20 @@ {{ form_row(form.description) }} {{ form_row(form.object, { 'label': 'Document', 'existing': document.object }) }} -