fix return path in tasks

This commit is contained in:
2021-10-28 00:50:18 +02:00
parent 97dbc4bc16
commit e63d645f8a
8 changed files with 75 additions and 168 deletions

View File

@@ -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,