Merge remote-tracking branch 'origin/master'

This commit is contained in:
Julien Fastré 2018-04-25 12:12:08 +02:00
commit b7dd309600
8 changed files with 441 additions and 42 deletions

View File

@ -16,75 +16,270 @@ use Chill\TaskBundle\Security\Authorization\TaskVoter;
use Symfony\Component\Security\Core\Role\Role;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\TaskBundle\Repository\SingleTaskRepository;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Chill\TaskBundle\Repository\SingleTaskRepository;
use Chill\MainBundle\Pagination\PaginatorFactory;
class SingleTaskController extends Controller
{
/**
* @Route("/{_locale}/task/single-task/new")
* @Route(
* "/{_locale}/task/single-task/new",
* name="chill_task_single_task_new"
* )
*/
public function newAction(Request $request)
{
$personId = $request->query->getInt('person_id', null);
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");
}
$task = (new SingleTask())
->setPerson($person)
->setAssignee($this->getUser())
->setType('task_default')
;
$this->denyAccessUnlessGranted(TaskVoter::CREATE, $task, 'You are not '
. 'allowed to create this task');
$form = $this->createCreateForm($task);
// $this->denyAccessUnlessGranted(TaskVoter::CREATE, $task, 'You are not '
// . 'allowed to create this task');
$form = $this->setCreateForm($task, new Role(TaskVoter::CREATE));
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($task);
$em->flush();
$this->addFlash('success', "The task is created");
$em->flush();
return $this->redirectToRoute('chill_task_task_list', [
'personId' => $task->getPerson()->getId()
]);
} else {
$this->addFlash('error', "This form contains errors");
}
}
return $this->render('ChillTaskBundle:SingleTask:new.html.twig', array(
'form' => $form->createView(),
'task' => $task
));
}
/**
*
* @Route(
* "/{_locale}/task/single-task/{id}/show",
* name="chill_task_single_task_show"
* )
*/
public function showAction(Request $request, $id)
{
/* @var $taskRepository SingleTaskRepository */
$taskRepository = $this->get('chill_task.single_task_repository');
$task = $taskRepository->find($id);
if (!is_null($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");
}
}
// $this->denyAccessUnlessGranted(TaskVoter::SEE, $task, 'You are not '
// . 'allowed to view this task');
if (!$task) {
throw $this->createNotFoundException('Unable to find Task entity.');
}
return $this->render('ChillTaskBundle:SingleTask:show.html.twig', array(
'task' => $task,
));
}
/**
* @Route(
* "/{_locale}/task/single-task/{id}/edit",
* name="chill_task_single_task_edit"
* )
*/
public function editAction(Request $request, $id)
{
/* @var $taskRepository SingleTaskRepository */
$taskRepository = $this->get('chill_task.single_task_repository');
$task = $taskRepository->find($id);
if (!is_null($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");
}
}
// $this->denyAccessUnlessGranted(TaskVoter::UPDATE, $task, 'You are not '
// . 'allowed to edit this task');
if (!$task) {
throw $this->createNotFoundException('Unable to find Task entity.');
}
$form = $this->setCreateForm($task, new Role(TaskVoter::UPDATE));
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($task);
$em->flush();
$this->addFlash('success', "Success : task updated!");
return $this->redirectToRoute('chill_task_task_list', [
'personId' => $task->getPerson()->getId()
]);
} else {
$this->addFlash('error', "This form contains errors");
}
}
return $this->render('ChillTaskBundle:SingleTask:edit.html.twig', array(
'task' => $task,
'form' => $form->createView()
));
}
/**
* @Route(
* "/{_locale}/task/single-task/{id}/delete",
* name="chill_task_single_task_delete"
* )
*/
public function deleteAction(Request $request, $id)
{
/* @var $taskRepository SingleTaskRepository */
$taskRepository = $this->get('chill_task.single_task_repository');
$task = $taskRepository->find($id);
if (!is_null($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");
}
}
// $this->denyAccessUnlessGranted(TaskVoter::DELETE, $task, 'You are not '
// . 'allowed to delete this task');
if (!$task) {
throw $this->createNotFoundException('Unable to find Task entity.');
}
$form = $this->createDeleteForm($id);
if ($request->getMethod() === Request::METHOD_DELETE) {
$form->handleRequest($request);
if ($form->isValid()) {
$logger = $this->get('chill.main.logger');
$logger->notice("A task has been removed", array(
'by_user' => $this->getUser()->getUsername(),
'task_id' => $task->getId(),
'description' => $task->getDescription(),
'assignee' => $task->getAssignee(),
'scope_id' => $task->getScope()->getId(),
//'start_date' => $task->getStartDate()->format('Y-m-d'),
//'end_date' => $task->getEndDate()->format('Y-m-d'),
//'warning_interval' => $task->getWarningInterval()->format('Y-m-d')
));
$em = $this->getDoctrine()->getManager();
$em->remove($task);
$em->flush();
$this->addFlash('success', $this->get('translator')
->trans("The task has been successfully removed."));
return $this->redirect($this->generateUrl(
'chill_task_task_list', array(
'personId' => $personId
)));
}
}
return $this->render('ChillTaskBundle:SingleTask:confirm_delete.html.twig', array(
'task' => $task,
'delete_form' => $form->createView()
));
}
/**
*
* @param SingleTask $task
* @param Role $role
* @return \Symfony\Component\Form\FormInterface
*/
protected function createCreateForm(SingleTask $task)
protected function setCreateForm(SingleTask $task, Role $role)
{
$form = $this->createForm(SingleTaskType::class, $task, [
'center' => $task->getCenter(),
'role' => new Role(TaskVoter::CREATE)
'role' => $role
]);
$form->add('submit', SubmitType::class);
return $form;
}
@ -175,4 +370,23 @@ class SingleTaskController extends Controller
return $user;
}
/**
* Creates a form to delete a Task entity by id.
*
* @param mixed $id The entity id
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm($id)
{
return $this->createFormBuilder()
->setAction($this->generateUrl(
'chill_task_single_task_delete',
array('id' => $id)))
->setMethod('DELETE')
->add('submit', SubmitType::class, array('label' => 'Delete'))
->getForm()
;
}
}

View File

@ -51,7 +51,7 @@ class ChillTaskExtension extends Extension implements PrependExtensionInterface
));
}
public function prependAuthorization(ContainerBuilder $container)
protected function prependAuthorization(ContainerBuilder $container)
{
$container->prependExtensionConfig('security', array(
'role_hierarchy' => array(

View File

@ -1,4 +1,4 @@
services:
Chill\TaskBundle\Controller\:
resource: ../../../Controller
resource: '../../../Controller'
tags: ['controller.service_arguments']

View File

@ -0,0 +1,19 @@
{% extends "ChillPersonBundle::layout.html.twig" %}
{% set activeRouteKey = 'chill_task_task_list' %}
{% set person = task.person %}
{% block title 'Remove task'|trans %}
{% block personcontent %}
{{ include('ChillMainBundle:Util:confirmation_template.html.twig',
{
'title' : 'Remove task'|trans,
'confirm_question' : 'Are you sure you want to remove the task about "%name%" ?'|trans({ '%name%' : person.firstname ~ ' ' ~ person.lastname } ),
'cancel_route' : 'chill_task_task_list',
'cancel_parameters' : { 'personId' : task.person.id, 'id' : task.id },
'form' : delete_form
} ) }}
{% endblock %}

View File

@ -0,0 +1,51 @@
{#
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
{% extends "ChillPersonBundle::layout.html.twig" %}
{% set activeRouteKey = 'chill_task_single_task_edit' %}
{% set person = task.person %}
{% block title %}{{ 'Edit task'|trans }}{% endblock %}
{% block personcontent %}
<h1 class="chill-red">{{ 'Edit task'|trans }}</h1>
{{ form_start(form) }}
{{ form_row(form.title) }}
{{ form_row(form.description) }}
{{ form_row(form.assignee) }}
{{ form_row(form.circle) }}
{{ form_row(form.startDate) }}
{{ form_row(form.endDate) }}
{{ form_row(form.warningInterval) }}
{{ form_widget(form) }}
<ul class="record_actions sticky-form-buttons">
<li class="cancel">
<a href="{{ path('chill_task_single_task_show', { 'id': task.id } ) }}" class="sc-button bt-cancel">
{{ 'Cancel'|trans }}
</a>
</li>
<li>
<button class="sc-button bt-update" type="submit">{{ 'Save task'|trans }}</button>
</li>
</ul>
{{ form_end(form) }}
{% endblock %}

View File

@ -1,16 +1,16 @@
{#
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
@ -22,8 +22,24 @@
{% block title %}{{ 'New task'|trans }}{% endblock %}
{% block personcontent %}
<h1>{{ 'New task'|trans }}</h1>
<h1 class="chill-red">{{ 'New task'|trans }}</h1>
{{ form(form) }}
{{ form_start(form) }}
{{ form_row(form.title) }}
{{ form_row(form.description) }}
{{ form_row(form.assignee) }}
{{ form_row(form.circle) }}
{{ form_row(form.startDate) }}
{{ form_row(form.endDate) }}
{{ form_row(form.warningInterval) }}
<div class="grid-12 centered sticky-form-buttons">
<!-- {{ form_row(form.submit, { 'label': 'Add a new task'|trans, 'attr': {'class': 'fa fa-save sc-button green margin-10'} }) }} -->
<button class="sc-button green margin-10" type="submit"><i class="fa fa-save"></i> {{ 'Add a new task'|trans }}</button>
</div>
{{ form_end(form) }}
{% endblock %}

View File

@ -0,0 +1,75 @@
{#
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
{% extends "ChillPersonBundle::layout.html.twig" %}
{% set activeRouteKey = 'chill_task_single_task_show' %}
{% set person = task.person %}
{% block title %}{{ 'Task'|trans }}{% endblock %}
{% block personcontent %}
<h1 class="chill-red">{{ 'Task'|trans }}</h1>
<dl class="chill_view_data">
<dt class="inline">{{ 'Title'|trans }}</dt>
<dd>{{ task.title }}</dd>
<dt class="inline">{{ 'Description'|trans }}</dt>
<dd>{{ task.description }}</dd>
<dt class="inline">{{ 'Assignee'|trans }}</dt>
<dd>{{ task.assignee }}</dd>
<dt class="inline">{{ 'Scope'|trans }}</dt>
<dd><span class="scope">{{ task.scope.name|localize_translatable_string }}</span></dd>
<dt class="inline">{{ 'Start date'|trans }}</dt>
<dd>{{ task.startDate|localizeddate('long', 'none') }}</dd>
<dt class="inline">{{ 'End date'|trans }}</dt>
<dd>{{ task.endDate|localizeddate('long', 'none') }}</dd>
<dt class="inline">{{ 'Warning interval'|trans }}</dt>
<dd>{{ task.warningInterval|localizeddate('long', 'none') }}</dd>
</dl>
<ul class="record_actions">
<li class="cancel">
<a class="sc-button bt-cancel" href="{{ path('chill_task_task_list', { 'personId': person.id } ) }}">
{{ 'Back to the list'|trans }}
</a>
</li>
{% if not is_granted('CHILL_TASK_TASK_UPDATE', task) %}
<li>
<a class="sc-button bt-update" href="{{ path('chill_task_single_task_edit', { 'id': task.id }) }}">
{{ 'Edit the activity'|trans }}
</a>
</li>
{% endif %}
{% if not is_granted('CHILL_TASK_TASK_CREATE', task) %}
<li>
<a href="{{ path('chill_task_single_task_delete', { 'id': task.id } ) }}" class="sc-button bt-delete">
{{ 'Delete'|trans }}
</a>
</li>
{% endif %}
</ul>
{% endblock %}

View File

@ -1,16 +1,16 @@
{#
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
@ -32,12 +32,12 @@
{% if tasks|length > 0 %}
<h2>{{ title|trans }}</h2>
<table>
<table class="records_list">
<thead>
<tr>
<th>{{ 'Title'|trans }}</th>
<th>{{ 'Task type'|trans }}</th>
<th>{{ 'Task status'|trans }}</th>
<th class="chill-red">{{ 'Title'|trans }}</th>
<th class="chill-green">{{ 'Task type'|trans }}</th>
<th class="chill-orange">{{ 'Task status'|trans }}</th>
<th>{{ 'Task start date'|trans }}</th>
<th>{{ 'Task warning date'|trans }}</th>
<th>{{ 'Task end date'|trans }}</th>
@ -52,6 +52,23 @@
<td>{% if task.startDate is not null %}{{ task.startDate|localizeddate('medium', 'none') }}{% endif %}</td>
<td>{% if task.warningDate is not null %}{{ task.warningDate|localizeddate('medium', 'none') }}{% endif %}</td>
<td>{% if task.endDate is not null %}{{ task.endDate|localizeddate('medium', 'none') }}{% endif %}</td>
<td>
<ul class="record_actions">
<li>
<a href="{{ path('chill_task_single_task_show', { 'id': task.id }) }}" class="sc-button bt-show "></a>
</li>
{% if not is_granted('CHILL_TASK_TASK_UPDATE', task) %}
<li>
<a href="{{ path('chill_task_single_task_edit', { 'id': task.id }) }}" class="sc-button bt-update "></a>
</li>
{% endif %}
{% if not is_granted('CHILL_TASK_TASK_CREATE', task) %}
<li>
<a href="{{ path('chill_task_single_task_delete', { 'id': task.id } ) }}" class="sc-button bt-delete "></a>
</li>
{% endif %}
</ul>
</td>
</tr>
{% endfor %}
</tbody>
@ -60,7 +77,7 @@
{% if tasks|length > paginator.getTotalItems %}
{{ chill_pagination(paginator) }}
{% endif %}
{% endif %}
{% endmacro %}
@ -70,22 +87,29 @@
{% block personcontent %}
<h1>{{ 'Task list'|trans }}</h1>
{% 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) }}
{% 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) }}
{% 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) }}
{% 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) }}
{% endif %}
<ul class="record_actions">
<li>
<a href="{{ path('chill_task_single_task_new', {'person_id': person.id}) }}" class="sc-button bt-create">
{{ 'Add a new task' | trans }}
</a>
</li>
</ul>
{% endblock %}