diff --git a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php index 8c742c627..aed805bcf 100644 --- a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php +++ b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php @@ -29,6 +29,10 @@ use Symfony\Component\Translation\TranslatorInterface; use Chill\TaskBundle\Event\UI\UIEvent; use Chill\MainBundle\Repository\CenterRepository; use Chill\MainBundle\Timeline\TimelineBuilder; +use Chill\PersonBundle\Entity\AccompanyingPeriod; +use Chill\PersonBundle\Repository\AccompanyingPeriodRepository; +use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; +use Symfony\Component\HttpFoundation\RequestStack; /** * Class SingleTaskController @@ -53,6 +57,11 @@ class SingleTaskController extends AbstractController * @var LoggerInterface */ protected $logger; + + /** + * @var RequestStack + */ + protected $request; /** * SingleTaskController constructor. @@ -62,11 +71,25 @@ class SingleTaskController extends AbstractController public function __construct( EventDispatcherInterface $eventDispatcher, TimelineBuilder $timelineBuilder, - LoggerInterface $logger + LoggerInterface $logger, + RequestStack $requestStack ) { $this->eventDispatcher = $eventDispatcher; $this->timelineBuilder = $timelineBuilder; $this->logger = $logger; + $this->request = $requestStack->getCurrentRequest(); + } + + + public function getEntity() + { + if($this->request->query->has('person_id')){ + return 'person'; + } else if ($this->request->query->has('course_id')) { + return 'course'; + } else { + return null; + } } @@ -77,7 +100,6 @@ class SingleTaskController extends AbstractController * ) */ public function newAction( - Request $request, TranslatorInterface $translator ) { @@ -85,18 +107,12 @@ class SingleTaskController extends AbstractController ->setAssignee($this->getUser()) ->setType('task_default') ; - - if($request->query->has('person_id')){ - $entityType = 'person'; - } else if ($request->query->has('course_id')) { - $entityType = 'course'; - } else { - $entityType = null; - } + + $entityType = $this->getEntity(); if ($entityType !== null) { - $entityId = $request->query->getInt("{$entityType}_id", 0); // sf4 check: + $entityId = $this->request->query->getInt("{$entityType}_id", 0); // sf4 check: // prevent error: `Argument 2 passed to ::getInt() must be of the type int, null given` if ($entityId === null) { @@ -134,12 +150,18 @@ class SingleTaskController extends AbstractController } + // error message: You should associate a person with task in order to check autorizations. + // consequently adapting TaskVoter to take into account accompanyinCourse throws new errors linked to authorizationHelper on line 151 + $this->denyAccessUnlessGranted(TaskVoter::CREATE, $task, 'You are not ' . 'allowed to create this task'); + // error message: An error has occurred resolving the options of the form "Chill\TaskBundle\Form\SingleTaskType": + //The option "center" with value null is expected to be of type "Chill\MainBundle\Entity\Center", but is of type "null". + $form = $this->setCreateForm($task, new Role(TaskVoter::CREATE)); - $form->handleRequest($request); + $form->handleRequest($this->request); if ($form->isSubmitted()) { if ($form->isValid()) { @@ -184,13 +206,22 @@ class SingleTaskController extends AbstractController * name="chill_task_single_task_show" * ) */ - public function showAction(Request $request, $id) + public function showAction($id) { $em = $this->getDoctrine()->getManager(); $task = $em->getRepository(SingleTask::class)->find($id); + // In case no task is found + + if (!$task) { + throw $this->createNotFoundException('Unable to find Task entity.'); + } + + // In case task belongs to person + if ($task->getPerson() !== null) { + $personId = $task->getPerson()->getId(); if ($personId === null) { @@ -204,23 +235,42 @@ class SingleTaskController extends AbstractController if ($person === null) { throw $this->createNotFoundException("Invalid person id"); } - } - $this->denyAccessUnlessGranted(TaskVoter::SHOW, $task, 'You are not ' - . 'allowed to view this task'); - if (!$task) { - throw $this->createNotFoundException('Unable to find Task entity.'); - } - - $timeline = $this->timelineBuilder - ->getTimelineHTML('task', array('task' => $task)); - - $event = new PrivacyEvent($person, array( + $event = new PrivacyEvent($person, array( 'element_class' => SingleTask::class, 'element_id' => $task->getId(), 'action' => 'show' - )); - $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); + )); + $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); + + } + + // In case task belongs to accompanying course + + if ($task->getCourse() !== null) + { + $courseId = $task->getCourse()->getId(); + + if ($courseId === null) { + return new Response("You must provide a course_id", Response::HTTP_BAD_REQUEST); + } + + $course = $this->getDoctrine()->getManager() + ->getRepository(AccompanyingPeriod::class) + ->find($courseId); + + if ($course === null) + { + throw $this->createNotFoundException("Invalid course id"); + } + } + + + $this->denyAccessUnlessGranted(TaskVoter::SHOW, $task, 'You are not ' + . 'allowed to view this task'); + + $timeline = $this->timelineBuilder + ->getTimelineHTML('task', array('task' => $task)); return $this->render('ChillTaskBundle:SingleTask:show.html.twig', array( 'task' => $task, @@ -236,7 +286,6 @@ class SingleTaskController extends AbstractController * ) */ public function editAction( - Request $request, $id, TranslatorInterface $translator ) { @@ -273,7 +322,7 @@ class SingleTaskController extends AbstractController $form = $event->getForm(); - $form->handleRequest($request); + $form->handleRequest($this->request); if ($form->isSubmitted()) { if ($form->isValid()) { @@ -294,7 +343,7 @@ class SingleTaskController extends AbstractController return $this->redirectToRoute( 'chill_task_singletask_list', - $request->query->get('list_params', []) + $this->request->query->get('list_params', []) ); } else { @@ -440,6 +489,7 @@ class SingleTaskController extends AbstractController * Arguments: * - user_id * - scope_id + * - course_id * - person_id * - hide_form (hide the form to filter the tasks) * - status: date state, amongst SingleTaskRepository::DATE_STATUSES, or 'closed' @@ -450,10 +500,10 @@ class SingleTaskController extends AbstractController * ) */ public function listAction( - Request $request, PaginatorFactory $paginatorFactory, SingleTaskRepository $taskRepository, PersonRepository $personRepository, + AccompanyingPeriodRepository $courseRepository, CenterRepository $centerRepository, FormFactoryInterface $formFactory ) { @@ -466,12 +516,13 @@ class SingleTaskController extends AbstractController $params['user'] = null; $viewParams['center'] = null; $params['types'] = null; + $viewParams['accompanyingCourse'] = null; // Get parameters from url - if (!empty($request->query->get('person_id', NULL))) { + if (!empty($this->request->query->get('person_id', NULL))) { - $personId = $request->query->getInt('person_id', 0); + $personId = $this->request->query->getInt('person_id', 0); $person = $personRepository->find($personId); if ($person === null) { @@ -482,28 +533,42 @@ class SingleTaskController extends AbstractController $viewParams['person'] = $person; $params['person'] = $person; } + + if (!empty($this->request->query->get('course_id', NULL))) { + + $courseId = $this->request->query->getInt('course_id', 0); + $course = $courseRepository->find($courseId); + + if ($course === null) { + throw $this->createNotFoundException("This accompanying course ' $courseId ' does not exist."); + } + $this->denyAccessUnlessGranted(AccompanyingPeriodVoter::SEE, $course); + + $viewParams['accompanyingCourse'] = $course; + $params['accompanyingCourse'] = $course; + } - if (!empty($request->query->get('center_id', NULL))) { - $center = $centerRepository->find($request->query->getInt('center_id')); + if (!empty($this->request->query->get('center_id', NULL))) { + $center = $centerRepository->find($this->request->query->getInt('center_id')); if ($center === null) { throw $this->createNotFoundException('center not found'); } $params['center'] = $center; } - if(!empty($request->query->get('types', []))) { - $types = $request->query->get('types', []); + if(!empty($this->request->query->get('types', []))) { + $types = $this->request->query->get('types', []); if (count($types) > 0) { $params['types'] = $types; } } - if (!empty($request->query->get('user_id', null))) { - if ($request->query->get('user_id') === '_unassigned') { + if (!empty($this->request->query->get('user_id', null))) { + if ($this->request->query->get('user_id') === '_unassigned') { $params['unassigned'] = true; } else { - $userId = $request->query->getInt('user_id', 0); + $userId = $this->request->query->getInt('user_id', 0); $user = $this->getDoctrine()->getManager() ->getRepository('ChillMainBundle:User') ->find($userId); @@ -517,9 +582,9 @@ class SingleTaskController extends AbstractController } } - if (!empty($request->query->get('scope_id'))) { + if (!empty($this->request->query->get('scope_id'))) { - $scopeId = $request->query->getInt('scope_id', 0); + $scopeId = $this->request->query->getInt('scope_id', 0); $scope = $this->getDoctrine()->getManager() ->getRepository('ChillMainBundle:Scope') @@ -535,7 +600,7 @@ class SingleTaskController extends AbstractController // collect parameters for filter $possibleStatuses = \array_merge(SingleTaskRepository::DATE_STATUSES, [ 'closed' ]); - $statuses = $request->query->get('status', $possibleStatuses); + $statuses = $this->request->query->get('status', $possibleStatuses); // check for invalid statuses $diff = \array_diff($statuses, $possibleStatuses); @@ -551,7 +616,7 @@ class SingleTaskController extends AbstractController $tasks_count = 0; foreach($statuses as $status) { - if($request->query->has('status') + if($this->request->query->has('status') && FALSE === \in_array($status, $statuses)) { continue; } @@ -586,6 +651,8 @@ class SingleTaskController extends AbstractController if ($viewParams['person'] !== null){ $viewParams['layout'] = '@ChillPerson/Person/layout.html.twig'; + } else if ($viewParams['accompanyingCourse'] !== null){ + $viewParams['layout'] = '@ChillPerson/AccompanyingCourse/layout.html.twig'; } else { $viewParams['layout'] = '@ChillMain/layout.html.twig'; } @@ -598,7 +665,7 @@ class SingleTaskController extends AbstractController 'add_type' => true ]); - $form->handleRequest($request); + $form->handleRequest($this->request); if (isset($person)) { $event = new PrivacyEvent($person, array( @@ -609,14 +676,14 @@ class SingleTaskController extends AbstractController } return $this->render('ChillTaskBundle:SingleTask:index.html.twig', - \array_merge($viewParams, [ 'form' => $form->createView() ])); + array_merge($viewParams, [ 'form' => $form->createView() ])); } - protected function getPersonParam(Request $request, EntityManagerInterface $em) + protected function getPersonParam(EntityManagerInterface $em) { $person = $em->getRepository(Person::class) - ->find($request->query->getInt('person_id')) + ->find($this->request->query->getInt('person_id')) ; if (NULL === $person) { @@ -629,10 +696,10 @@ class SingleTaskController extends AbstractController return $person; } - protected function getUserParam(Request $request, EntityManagerInterface $em) + protected function getUserParam(EntityManagerInterface $em) { $user = $em->getRepository(User::class) - ->find($request->query->getInt('user_id')) + ->find($this->request->query->getInt('user_id')) ; if (NULL === $user) { diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_list.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_list.html.twig index a5a867dcc..e80e45e8c 100644 --- a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_list.html.twig +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_list.html.twig @@ -1,244 +1,256 @@ {% macro date_status(title, tasks, count, paginator, status, isSingleStatus, person, user) %} - {% if tasks|length > 0 %} -

{{ title|trans }}

+ {% if tasks|length > 0 %} +

{{ title|trans }}

- - - {% for task in tasks %} - - + + {% endfor %} + +
-
- {{ task.title }} -
+ + + {% for task in tasks %} + + - + - - {% endfor %} - -
+
+ {{ task.title }} +
- {% if person is null %} -
- {{ 'For person'|trans }} : {{ task.person}} -
- {% endif %} + {% if person is null %} +
+ {{ 'For person'|trans }} : + + {{ task.person}} + +
+ {% endif %} -
- {{ task_workflow_metadata(task, 'definition.name')|trans }} -
+
+ {{ task_workflow_metadata(task, 'definition.name')|trans }} +
-
- {% for place in workflow_marked_places(task) %} - {{ place|trans }} - {% endfor %} - {% if task.assignee is not null %} -
{{ 'By'|trans }} : {{ task.assignee.username }}
- {% endif %} -
+
+ {% for place in workflow_marked_places(task) %} + {{ place|trans }} + {% endfor %} + {% if task.assignee is not null %} +
+ {{ 'By'|trans }} : + {{ task.assignee.username }}
+ {% endif %} +
- {% if task.startDate is not null or task.warningDate is not null or task.endDate is not null %} -
-
    - {% if task.startDate is not null %} -
  • - {{ task.startDate|format_date('medium') }} -
  • - {% endif %} - {% if task.warningDate is not null %} -
  • - {{ task.warningDate|format_date('medium') }} -
  • - {% endif %} - {% if task.endDate is not null %} -
  • - {{ task.endDate|format_date('medium') }} -
  • - {% endif %} -
-
- {% endif %} + {% if task.startDate is not null or task.warningDate is not null or task.endDate is not null %} +
+
    + {% if task.startDate is not null %} +
  • + + {{ task.startDate|format_date('medium') }} +
  • + {% endif %} + {% if task.warningDate is not null %} +
  • + + {{ task.warningDate|format_date('medium') }} +
  • + {% endif %} + {% if task.endDate is not null %} +
  • + + {{ task.endDate|format_date('medium') }} +
  • + {% endif %} +
+
+ {% endif %} -
- + -
+ {% if is_granted('CHILL_TASK_TASK_DELETE', task) %} +
  • + +
  • + {% endif %} + +
    - {% if isSingleStatus %} - {% if tasks|length < paginator.getTotalItems %} - {{ chill_pagination(paginator) }} - {% endif %} + {% if isSingleStatus %} + {% if tasks|length < paginator.getTotalItems %} + {{ chill_pagination(paginator) }} + {% endif %} - - - {% else %} - + {% endif %} - {% endif %} + {% endif %} {% endmacro %} {% import _self as helper %} -

    {{ app.request.query.get('title', null)|escape('html')|default('Task list'|trans) }}

    +

    {{ app.request.query.get('title', null)|escape('html')|default('Task list'|trans) }}

    - {% if false == app.request.query.boolean('hide_form', false) %} -

    {{ 'Filter the tasks'|trans }}

    - {{ form_start(form) }} - {{ form_row(form.user_id) }} +{% if false == app.request.query.boolean('hide_form', false) %} +

    {{ 'Filter the tasks'|trans }}

    + {{ form_start(form) }} + {{ form_row(form.user_id) }} - {% if form.status is defined %} - {{ form_row(form.status) }} - {% endif %} + {% if form.status is defined %} + {{ form_row(form.status) }} + {% endif %} - {% if form.types is defined %} - {{ form_row(form.types) }} - {% endif %} + {% if form.types is defined %} + {{ form_row(form.types) }} + {% endif %} - {% if form.person_id is defined %} - {{ form_row(form.person_id) }} - {% endif %} + {% if form.person_id is defined %} + {{ form_row(form.person_id) }} + {% endif %} - {% if form.center_id is defined %} - {{ form_row(form.center_id) }} - {% endif %} + {% if form.center_id is defined %} + {{ form_row(form.center_id) }} + {% endif %} - + - {{ form_end(form)}} - {% endif %} + {{ form_end(form)}} +{% endif %} - {% if tasks_count == 0 %} -

    {{ "There is no tasks."|trans }}

    - {% if person is not null and is_granted('CHILL_TASK_TASK_CREATE', person) %} - - {% endif %} - {% else %} +{% if tasks_count == 0 %} +

    {{ "There is no tasks."|trans }}

    + {% if person is not null and is_granted('CHILL_TASK_TASK_CREATE', person) %} + + {% endif %} +{% else %} - {% if false == app.request.query.boolean('hide_form', false) %} -

    {{ 'Tasks'|trans }}

    - {% endif %} + {% if false == app.request.query.boolean('hide_form', false) %} +

    {{ 'Tasks'|trans }}

    + {% endif %} - {% if person is not null and is_granted('CHILL_TASK_TASK_CREATE', person) %} - - {% endif %} + {% if person is not null and is_granted('CHILL_TASK_TASK_CREATE', person) %} + + {% endif %} - {% if single_task_ended_tasks is defined %} - {{ helper.date_status('Tasks with expired deadline', single_task_ended_tasks, single_task_ended_count, single_task_ended_paginator, 'ended', isSingleStatus, person) }} - {% endif %} + {% if single_task_ended_tasks is defined %} + {{ helper.date_status('Tasks with expired deadline', single_task_ended_tasks, single_task_ended_count, single_task_ended_paginator, 'ended', isSingleStatus, person) }} + {% endif %} - {% if single_task_warning_tasks is defined %} - {{ helper.date_status('Tasks with warning deadline reached', single_task_warning_tasks, single_task_warning_count, single_task_warning_paginator, 'warning', isSingleStatus, person) }} - {% endif %} + {% if single_task_warning_tasks is defined %} + {{ helper.date_status('Tasks with warning deadline reached', single_task_warning_tasks, single_task_warning_count, single_task_warning_paginator, 'warning', isSingleStatus, person) }} + {% endif %} - {% if single_task_current_tasks is defined %} - {{ helper.date_status('Current tasks', single_task_current_tasks, single_task_current_count, single_task_current_paginator, 'current', isSingleStatus, person) }} - {% endif %} + {% if single_task_current_tasks is defined %} + {{ helper.date_status('Current tasks', single_task_current_tasks, single_task_current_count, single_task_current_paginator, 'current', isSingleStatus, person) }} + {% endif %} - {% if single_task_not_started_tasks is defined %} - {{ helper.date_status('Tasks not started', single_task_not_started_tasks, single_task_not_started_count, single_task_not_started_paginator, 'not_started', isSingleStatus, person) }} - {% endif %} + {% if single_task_not_started_tasks is defined %} + {{ helper.date_status('Tasks not started', single_task_not_started_tasks, single_task_not_started_count, single_task_not_started_paginator, 'not_started', isSingleStatus, person) }} + {% endif %} - {% if single_task_closed_tasks is defined %} - {{ helper.date_status('Closed tasks', single_task_closed_tasks, single_task_closed_count, single_task_closed_paginator, 'closed', isSingleStatus, person) }} - {% endif %} + {% if single_task_closed_tasks is defined %} + {{ helper.date_status('Closed tasks', single_task_closed_tasks, single_task_closed_count, single_task_closed_paginator, 'closed', isSingleStatus, person) }} + {% endif %} - {% if isSingleStatus == false %} - - {% endif %} + {% if isSingleStatus == false %} + + {% endif %} {% endif %} diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/index.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/index.html.twig index 2a33fc10c..1932d7525 100644 --- a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/index.html.twig +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/index.html.twig @@ -15,30 +15,30 @@ * along with this program. If not, see . #} -{% extends '@ChillPerson/Person/layout.html.twig' %} +{% extends layout %} {% set activeRouteKey = 'chill_task_single_task_new' %} -{% block title %}{{ 'Task list'|trans }}{% endblock %} +{% block title %} + {{ 'Task list'|trans }} +{% endblock %} -{% macro thead() %} -{% endmacro %} +{% macro thead() %}{% endmacro %} -{% macro row(task) %} -{% endmacro %} +{% macro row(task) %}{% endmacro %} {% block filtertasks %} -{% if person is not null %} - {% block personcontent %} -
    - {% include 'ChillTaskBundle:SingleTask:_list.html.twig' %} -
    - {% endblock %} -{% else %} - {% block content %} -
    - {% include 'ChillTaskBundle:SingleTask:_list.html.twig' %} -
    - {% endblock %} -{% endif %} + {% if person is not null %} + {% block personcontent %} +
    + {% include 'ChillTaskBundle:SingleTask:_list.html.twig' %} +
    + {% endblock %} + {% else %} + {% block content %} +
    + {% include 'ChillTaskBundle:SingleTask:_list.html.twig' %} +
    + {% endblock %} + {% endif %} {% endblock %} diff --git a/src/Bundle/ChillTaskBundle/config/services/controller.yaml b/src/Bundle/ChillTaskBundle/config/services/controller.yaml index 533c57f47..cfe083e07 100644 --- a/src/Bundle/ChillTaskBundle/config/services/controller.yaml +++ b/src/Bundle/ChillTaskBundle/config/services/controller.yaml @@ -1,11 +1,12 @@ services: - Chill\TaskBundle\Controller\: - resource: '../../Controller' - tags: ['controller.service_arguments'] + Chill\TaskBundle\Controller\: + resource: "../../Controller" + tags: ["controller.service_arguments"] - Chill\TaskBundle\Controller\SingleTaskController: - arguments: - $eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface' - $timelineBuilder: '@chill_main.timeline_builder' - $logger: '@chill.main.logger' - tags: ['controller.service_arguments'] + Chill\TaskBundle\Controller\SingleTaskController: + arguments: + $eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface' + $timelineBuilder: "@chill_main.timeline_builder" + $logger: "@chill.main.logger" + $requestStack: '@Symfony\Component\HttpFoundation\RequestStack' + tags: ["controller.service_arguments"]