mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fix return path in tasks
This commit is contained in:
parent
97dbc4bc16
commit
e63d645f8a
@ -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,67 +202,22 @@ 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'
|
||||
));
|
||||
$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) {
|
||||
return $this->render('@ChillTask/SingleTask/Person/show.html.twig', array(
|
||||
'task' => $task,
|
||||
@ -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,35 +744,20 @@ 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)
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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' ])
|
||||
;
|
||||
|
@ -88,15 +88,15 @@ class MenuBuilder implements LocalMenuBuilderInterface
|
||||
|
||||
$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',
|
||||
'route' => 'chill_task_singletask_by-course_list',
|
||||
'routeParameters' =>
|
||||
[ 'course_id' => $course->getId() ]
|
||||
[ 'id' => $course->getId() ]
|
||||
])
|
||||
->setExtra('order', 400);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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,
|
||||
} ) }}
|
||||
|
||||
|
@ -120,20 +120,20 @@
|
||||
{% endif %}
|
||||
|
||||
<li>
|
||||
<a href="{{ path('chill_task_single_task_show', { 'id': task.id, 'list_params': app.request.query.all }) }}" class="btn btn-show "></a>
|
||||
<a href="{{ chill_path_add_return_path('chill_task_single_task_show', { 'id': task.id }) }}" class="btn btn-show "></a>
|
||||
</li>
|
||||
|
||||
{# {% if is_granted('CHILL_TASK_TASK_UPDATE', task) %} #}
|
||||
{% if is_granted('CHILL_TASK_TASK_UPDATE', task) %}
|
||||
<li>
|
||||
<a href="{{ path('chill_task_single_task_edit', { 'id': task.id, 'list_params': app.request.query.all }) }}" class="btn btn-update "></a>
|
||||
<a href="{{ chill_path_add_return_path('chill_task_single_task_edit', { 'id': task.id }) }}" class="btn btn-update "></a>
|
||||
</li>
|
||||
{# {% endif %} #}
|
||||
{% endif %}
|
||||
|
||||
{# {% if is_granted('CHILL_TASK_TASK_DELETE', task) %} #}
|
||||
{% if is_granted('CHILL_TASK_TASK_DELETE', task) %}
|
||||
<li>
|
||||
<a href="{{ path('chill_task_single_task_delete', { 'id': task.id, 'list_params': app.request.query.all } ) }}" class="btn btn-delete "></a>
|
||||
<a href="{{ chill_path_add_return_path('chill_task_single_task_delete', { 'id': task.id } ) }}" class="btn btn-delete "></a>
|
||||
</li>
|
||||
{# {% endif %} #}
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
<ul class="record_actions sticky-form-buttons">
|
||||
<li class="cancel">
|
||||
<a class="btn btn-cancel" href={% if task.person is not null %} "{{ path('chill_task_singletask_list', { 'person_id': task.person.id, 'list_params': app.request.query.get('list_params', {} )} ) }}" {% else %} "{{ chill_return_path_or('chill_task_singletask_courselist', {'course_id': task.course.id}) }}" {% endif %}>
|
||||
<a class="btn btn-cancel" href={% if task.person is not null %} "{{ path('chill_task_singletask_list', { 'person_id': task.person.id, 'list_params': app.request.query.get('list_params', {} )} ) }}" {% else %} "{{ chill_return_path_or('chill_task_singletask_by-course_list', {'id': task.course.id}) }}" {% endif %}>
|
||||
{{'Cancel'|trans}}
|
||||
</a>
|
||||
</li>
|
||||
|
@ -70,8 +70,8 @@
|
||||
|
||||
<ul class="record_actions sticky-form-buttons">
|
||||
<li class="cancel">
|
||||
<a class="btn btn-cancel" href={% if task.person is not null %} "{{ path('chill_task_singletask_list', { 'person_id': task.person.id, 'list_params': app.request.query.get('list_params', {} )} ) }}" {% else %} "{{ chill_return_path_or('chill_task_singletask_courselist', {'course_id': task.course.id}) }}" {% endif %}>
|
||||
{{'Back to the list'|trans}}
|
||||
<a class="btn btn-cancel" href={% if task.person is not null %} "{{ chill_return_path_or('chill_task_singletask_list', { 'person_id': task.person.id } ) }}" {% else %} "{{ chill_return_path_or('chill_task_singletask_by-course_list', {'id': task.course.id}) }}" {% endif %}>
|
||||
{{'Cancel'|trans}}
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -94,19 +94,20 @@
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if is_granted('CHILL_TASK_TASK_DELETE', task) %}
|
||||
<li>
|
||||
<a href="{{ chill_path_forward_return_path('chill_task_single_task_delete', { 'id': task.id } ) }}" class="btn btn-delete">
|
||||
{{ 'Delete'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if is_granted('CHILL_TASK_TASK_UPDATE', task) %}
|
||||
<li>
|
||||
<a class="btn btn-update" href="{{ path('chill_task_single_task_edit', { 'id': task.id, 'list_params': app.request.query.all['list_params'] }) }}">
|
||||
<a class="btn btn-update" href="{{ chill_path_forward_return_path('chill_task_single_task_edit', { 'id': task.id }) }}">
|
||||
{{ 'Edit the task'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if is_granted('CHILL_TASK_TASK_CREATE', task) %}
|
||||
<li>
|
||||
<a href="{{ path('chill_task_single_task_delete', { 'id': task.id, 'list_params': app.request.query.all['list_params'] } ) }}" class="btn btn-delete">
|
||||
{{ 'Delete'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul></div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user