diff --git a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php index 359dc8909..b11601589 100644 --- a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php +++ b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php @@ -160,13 +160,17 @@ final class SingleTaskController extends AbstractController $this->addFlash('success', $this->translator->trans("The task is created")); + if ($request->query->has('returnPath')) { + return $this->redirect($request->query->get('returnPath')); + } + if ($entityType === 'person') { return $this->redirectToRoute('chill_task_singletask_list', [ 'person_id' => $task->getPerson()->getId() ]); } elseif ($entityType === 'course') { - return $this->redirectToRoute('chill_task_singletask_courselist', [ - 'course_id' => $task->getCourse()->getId() + return $this->redirectToRoute('chill_task_singletask_by-course_list', [ + 'id' => $task->getCourse()->getId() ]); } } else { @@ -179,13 +183,13 @@ final class SingleTaskController extends AbstractController return $this->render('@ChillTask/SingleTask/Person/new.html.twig', array( 'form' => $form->createView(), 'task' => $task, - 'person' => $person, + 'person' => $task->getPerson(), )); case 'course': return $this->render('@ChillTask/SingleTask/AccompanyingCourse/new.html.twig', array( 'form' => $form->createView(), 'task' => $task, - 'accompanyingCourse' => $course, + 'accompanyingCourse' => $task->getCourse(), )); default: throw new \LogicException("entity context not supported"); @@ -198,68 +202,23 @@ final class SingleTaskController extends AbstractController * name="chill_task_single_task_show" * ) */ - public function showAction($id, Request $request) + public function showAction(SingleTask $task, Request $request) { + $this->denyAccessUnlessGranted(TaskVoter::SHOW, $task); - $em = $this->getDoctrine()->getManager(); - $task = $em->getRepository(SingleTask::class)->find($id); - - if (!$task) { - throw $this->createNotFoundException('Unable to find Task entity.'); - } - - if ($task->getPerson() !== null) { - - $personId = $task->getPerson()->getId(); - - if ($personId === null) { - return new Response("You must provide a person_id", Response::HTTP_BAD_REQUEST); - } - - $person = $this->getDoctrine()->getManager() - ->getRepository(Person::class) - ->find($personId); - - if ($person === null) { - throw $this->createNotFoundException("Invalid person id"); - } - + if ($person = $task->getContext() instanceof Person) { $event = new PrivacyEvent($person, array( - 'element_class' => SingleTask::class, - 'element_id' => $task->getId(), - 'action' => 'show' + 'element_class' => SingleTask::class, + 'element_id' => $task->getId(), + 'action' => 'show' )); $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); - } - 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)); - - if($task->getContext() instanceof Person){ + if ($task->getContext() instanceof Person) { return $this->render('@ChillTask/SingleTask/Person/show.html.twig', array( 'task' => $task, 'timeline' => $timeline @@ -281,52 +240,16 @@ final class SingleTaskController extends AbstractController * ) */ public function editAction( - $id, + SingleTask $task, Request $request ) { - $em = $this->getDoctrine()->getManager(); - $task = $em->getRepository(SingleTask::class)->find($id); - - if ($task->getContext() instanceof Person) { - $personId = $task->getPerson()->getId(); - if ($personId === null) { - return new Response("You must provide a person_id", Response::HTTP_BAD_REQUEST); - } - - $person = $this->getDoctrine()->getManager() - ->getRepository(Person::class) - ->find($personId); - - if ($person === null) { - throw $this->createNotFoundException("Invalid person id"); - } - } else { - $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 accompanying period id"); - } - } - $this->denyAccessUnlessGranted(TaskVoter::UPDATE, $task, 'You are not ' . 'allowed to edit this task'); - if (!$task) { - throw $this->createNotFoundException('Unable to find Task entity.'); - } - $event = (new UIEvent('single-task', $task)) ->setForm($this->setCreateForm($task, new Role(TaskVoter::UPDATE))) ; - $this->eventDispatcher->dispatch(UIEvent::EDIT_FORM, $event); $form = $event->getForm(); @@ -343,7 +266,7 @@ final class SingleTaskController extends AbstractController $this->addFlash('success', $this->translator ->trans("The task has been updated")); - if($task->getContext() instanceof Person){ + if ($person = $task->getContext() instanceof Person) { $event = new PrivacyEvent($person, array( 'element_class' => SingleTask::class, 'element_id' => $task->getId(), @@ -351,14 +274,20 @@ final class SingleTaskController extends AbstractController )); $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); + if ($request->query->has('returnPath')) { + return $this->redirect($request->query->get('returnPath')); + } + return $this->redirectToRoute( 'chill_task_singletask_list', - $request->query->get('list_params', []) ); } else { + if ($request->query->has('returnPath')) { + return $this->redirect($request->query->get('returnPath')); + } + return $this->redirectToRoute( - 'chill_task_singletask_courselist', - $request->query->get('list_params', []) + 'chill_task_singletask_by-course_list', ['id' => $task->getCourse()->getId()] ); } } else { @@ -372,7 +301,7 @@ final class SingleTaskController extends AbstractController return $event->getResponse(); } - if($task->getContext() instanceof Person){ + if ($person = $task->getContext() instanceof Person) { $event = new PrivacyEvent($person, array( 'element_class' => SingleTask::class, 'element_id' => $task->getId(), @@ -388,7 +317,7 @@ final class SingleTaskController extends AbstractController return $this->render('@ChillTask/SingleTask/AccompanyingCourse/edit.html.twig', array( 'task' => $task, 'form' => $form->createView(), - 'accompanyingCourse' => $course + 'accompanyingCourse' => $task->getCourse() )); } @@ -478,10 +407,9 @@ final class SingleTaskController extends AbstractController ]))); } else { return $this->redirect($this->generateUrl( - 'chill_task_singletask_courselist', - $request->query->get('list_params', [ - 'course_id' => $course->getId() - ]))); + 'chill_task_singletask_by-course_list', + ['id' => $course->getId()] + )); } } } @@ -510,7 +438,6 @@ final class SingleTaskController extends AbstractController protected function setCreateForm(SingleTask $task, Role $role) { $form = $this->createForm(SingleTaskType::class, $task, [ - 'center' => $this->centerResolverDispatcher->resolveCenter($task), 'role' => $role, ]); @@ -817,39 +744,24 @@ final class SingleTaskController extends AbstractController /** * @Route( - * "/{_locale}/task/single-task/courselist", - * name="chill_task_singletask_courselist") + * "/{_locale}/task/single-task/by-course/{id}", + * name="chill_task_singletask_by-course_list") */ public function listCourseTasks( - AccompanyingPeriodRepository $courseRepository, + AccompanyingPeriod $course, SingleTaskRepository $taskRepository, FormFactoryInterface $formFactory, Request $request ): Response { - if (!empty($request->query->get('course_id', NULL))) { - - $courseId = $request->query->getInt('course_id', 0); - $course = $courseRepository->find($courseId); - - if ($course === null) { - throw $this->createNotFoundException("This accompanying course ' $courseId ' does not exist."); - } - - } - $em = $this->getDoctrine()->getManager(); - if($course === NULL) { - throw $this->createNotFoundException('Accompanying course not found'); - } - $tasks = $taskRepository - ->findBy( - array('course' => $course) - ); + ->findBy( + array('course' => $course) + ); $form = $formFactory->createNamed(null, SingleTaskListType::class, null, [ 'accompanyingCourse' => $course, diff --git a/src/Bundle/ChillTaskBundle/Entity/AbstractTask.php b/src/Bundle/ChillTaskBundle/Entity/AbstractTask.php index b3f0c6a9f..d34a0b05f 100644 --- a/src/Bundle/ChillTaskBundle/Entity/AbstractTask.php +++ b/src/Bundle/ChillTaskBundle/Entity/AbstractTask.php @@ -253,11 +253,6 @@ abstract class AbstractTask implements HasScopeInterface, HasCenterInterface public function getContext() { - // if ($this->getCourse() instanceof AccompanyingPeriod){ - // return $this->getCourse(); - // } else { - // return $this->getPerson(); - // } return $this->getPerson() ?? $this->getCourse(); } diff --git a/src/Bundle/ChillTaskBundle/Form/SingleTaskType.php b/src/Bundle/ChillTaskBundle/Form/SingleTaskType.php index 7fbc84800..a3dd1777f 100644 --- a/src/Bundle/ChillTaskBundle/Form/SingleTaskType.php +++ b/src/Bundle/ChillTaskBundle/Form/SingleTaskType.php @@ -19,6 +19,7 @@ namespace Chill\TaskBundle\Form; use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher; use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher; +use Chill\TaskBundle\Security\Authorization\TaskVoter; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; @@ -60,7 +61,7 @@ class SingleTaskType extends AbstractType ->add('assignee', UserPickerType::class, [ 'required' => false, 'center' => $center, - 'role' => $options['role'], + 'role' => TaskVoter::SHOW, 'placeholder' => 'Not assigned' ]) ->add('startDate', ChillDateType::class, [ @@ -87,8 +88,6 @@ class SingleTaskType extends AbstractType public function configureOptions(OptionsResolver $resolver) { $resolver - ->setRequired('center') - ->setAllowedTypes('center', [ Center::class, 'array', 'null' ]) ->setRequired('role') ->setAllowedTypes('role', [ Role::class, 'string' ]) ; diff --git a/src/Bundle/ChillTaskBundle/Menu/MenuBuilder.php b/src/Bundle/ChillTaskBundle/Menu/MenuBuilder.php index 89f511d2a..53751de91 100644 --- a/src/Bundle/ChillTaskBundle/Menu/MenuBuilder.php +++ b/src/Bundle/ChillTaskBundle/Menu/MenuBuilder.php @@ -24,7 +24,7 @@ use Chill\TaskBundle\Security\Authorization\TaskVoter; use Symfony\Component\Translation\TranslatorInterface; /** - * + * * * @author Julien Fastré */ @@ -35,13 +35,13 @@ class MenuBuilder implements LocalMenuBuilderInterface * @var TranslatorInterface */ protected $translator; - + /** * * @var AuthorizationCheckerInterface */ protected $authorizationChecker; - + public function __construct( AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator) @@ -50,7 +50,7 @@ class MenuBuilder implements LocalMenuBuilderInterface $this->authorizationChecker = $authorizationChecker; } - + public function buildMenu($menuId, MenuItem $menu, array $parameters) { switch($menuId) { @@ -69,15 +69,15 @@ class MenuBuilder implements LocalMenuBuilderInterface } public function buildPersonMenu($menu, $parameters){ - + //var $person \Chill\PersonBundle\Entity\Person */ $person = $parameters['person'] ?? null; - + if ($this->authorizationChecker->isGranted(TaskVoter::SHOW, $person)) { $menu->addChild( $this->translator->trans('Tasks'), [ 'route' => 'chill_task_singletask_list', - 'routeParameters' => + 'routeParameters' => [ 'person_id' => $person->getId() ] ]) ->setExtra('order', 400); @@ -85,18 +85,18 @@ class MenuBuilder implements LocalMenuBuilderInterface } public function buildAccompanyingCourseMenu($menu, $parameters){ - + $course = $parameters['accompanyingCourse']; - - // if ($this->authorizationChecker->isGranted(TaskVoter::SHOW, $course)) { + + if ($this->authorizationChecker->isGranted(TaskVoter::SHOW, $course)) { $menu->addChild( $this->translator->trans('Tasks'), [ - 'route' => 'chill_task_singletask_courselist', - 'routeParameters' => - [ 'course_id' => $course->getId() ] + 'route' => 'chill_task_singletask_by-course_list', + 'routeParameters' => + [ 'id' => $course->getId() ] ]) ->setExtra('order', 400); - // } + } } diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/AccompanyingCourse/confirm_delete.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/AccompanyingCourse/confirm_delete.html.twig index 01b7aa499..02a0aa31d 100644 --- a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/AccompanyingCourse/confirm_delete.html.twig +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/AccompanyingCourse/confirm_delete.html.twig @@ -3,7 +3,7 @@ {% set activeRouteKey = 'chill_task_task_list' %} {% set course = task.course %} -{% block title 'Remove task'|trans %} +{% block title 'Remove task'|trans %} {% block content %} @@ -11,8 +11,8 @@ { 'title' : 'Remove task'|trans, 'confirm_question' : 'Are you sure you want to remove the task "%title%" ?'|trans({ '%title%' : task.title } ), - 'cancel_route' : 'chill_task_singletask_courselist', - 'cancel_parameters' : app.request.query.get('list_params', { } ), + 'cancel_route' : 'chill_task_singletask_by-course_list', + 'cancel_parameters' : {'id' : task.course.id }, 'form' : delete_form, } ) }} diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index.html.twig index 5b06fabed..c7c622692 100644 --- a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index.html.twig +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index.html.twig @@ -120,20 +120,20 @@ {% endif %}
  • - +
  • - {# {% if is_granted('CHILL_TASK_TASK_UPDATE', task) %} #} + {% if is_granted('CHILL_TASK_TASK_UPDATE', task) %}
  • - +
  • - {# {% endif %} #} + {% endif %} - {# {% if is_granted('CHILL_TASK_TASK_DELETE', task) %} #} + {% if is_granted('CHILL_TASK_TASK_DELETE', task) %}
  • - +
  • - {# {% endif %} #} + {% endif %} diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_new.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_new.html.twig index 37f8b431c..9d324ea85 100644 --- a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_new.html.twig +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_new.html.twig @@ -18,7 +18,7 @@