Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 118 additions & 32 deletions app/Resources/views/task/list.html.twig
Original file line number Diff line number Diff line change
@@ -1,36 +1,122 @@
{% extends 'base.html.twig' %}

{% block header_img %}<img class="slide-image" src="{{ asset('img/todolist_content.jpg') }}" alt="todo list">{% endblock %}

{% block body %}
<a href="{{ path('task_create') }}" class="btn btn-info pull-right">Créer une tâche</a>
<div class="row">
{% for task in tasks %}
<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<div class="caption">
<h4 class="pull-right">
{% if task.isDone %}<span class="glyphicon glyphicon-ok"></span>{% else %}<span class="glyphicon glyphicon-remove"></span>{% endif %}
</h4>
<h4><a href="{{ path('task_edit', {'id' : task.id }) }}">{{ task.title }}</a></h4>
<p>{{ task.content }}</p>
{% block header_img %}
<img class="slide-image" src="{{ asset('img/todolist_content.jpg') }}" alt="todo list">
{% endblock %}
{% block body %}
<!-- Page header with action button -->
<div class="row mb-4" style="margin-bottom: 30px; display: flex; align-items: center; justify-content: space-between;">
<div class="col-xs-6">
<h2 style="margin-top: 0;">
Liste des tâches
</h2>
</div>
<div class="col-xs-6 text-right">
<a href="{{ path('task_create') }}" class="btn btn-primary btn-lg">
<span class="glyphicon glyphicon-plus"></span>
Créer une tâche
</a>
</div>
</div>
<!-- Tasks Grid -->
<div class="row">
{% for task in tasks %}
{# Dynamically determine card styles based on the task status #}
{% set border_color = 'panel-danger' %}
{% set badge_color = 'label-danger' %}
{% set status_icon = 'glyphicon-remove' %}
{% set status_label = 'To Do' %}
{% if task.isDone %}
{% set border_color = 'panel-success' %}
{% set badge_color = 'label-success' %}
{% set status_icon = 'glyphicon-ok' %}
{% set status_label = 'Done' %}
{# Optional: If your Task entity has an intermediate state like "inProgress" #}
{% elseif task.inProgress is defined and task.inProgress %}
{% set border_color = 'panel-info' %}
{% set badge_color = 'label-info' %}
{% set status_icon = 'glyphicon-refresh' %}
{% set status_label = 'In Progress' %}
{% endif %}
<div class="col-sm-6 col-md-4" style="margin-bottom: 25px;">
<div class="panel {{ border_color }}" style="box-shadow: 0 4px 6px rgba(0,0,0,0.05); border-radius: 6px; overflow: hidden; transition: transform 0.2s ease-in-out;">
<!-- Task Header (Status Badge & Creation Date) -->
<div class="panel-heading" style="display: flex; justify-content: space-between; align-items: center; padding: 12px 15px;">
<span class="label {{ badge_color }}" style="font-size: 11px; padding: 4px 8px; text-transform: uppercase;">
<span class="glyphicon {{ status_icon }}"></span>
{{ status_label }}
</span>
<small style="color: #666; font-size: 11px;">
<span class="glyphicon glyphicon-calendar"></span>
{{ task.createdAt|date('d/m/Y') }}
</small>
</div>
<!-- Task Body (Title, Content & Author metadata) -->
<div class="panel-body" style="padding: 20px; min-height: 140px; display: flex; flex-direction: column; justify-content: space-between;">
<div>
<h4 style="margin-top: 0; margin-bottom: 10px; font-weight: bold;">
<a href="{{ path('task_edit', {'id' : task.id }) }}" style="color: #333; text-decoration: none;">
{{ task.title }}
</a>
</h4>
<p style="color: #666; font-size: 13px; line-height: 1.5; margin-bottom: 15px;">
{{ task.content }}
</p>
</div>
<!-- Metadata (Author details) -->
<div style="border-top: 1px dashed #eee; padding-top: 10px; margin-top: 10px; font-size: 11px; color: #777;">
<span class="glyphicon glyphicon-user"></span>
Créé par :
<strong>
{{ task.user ? task.user.username : 'Anonyme' }}
</strong>
</div>
</div>
<!-- Card Footer with user actions -->
<div class="panel-footer" style="background-color: #fafafa; border-top: 1px solid #f0f0f0; padding: 12px 15px; display: flex; gap: 8px; justify-content: flex-end; align-items: center;">
<!-- Toggle Status Button -->
<form action="{{ path('task_toggle', {'id' : task.id }) }}" method="POST" style="margin: 0; display: inline-block;">
<button class="btn btn-default btn-sm" style="font-weight: 500;">
{% if task.isDone %}
<span class="glyphicon glyphicon-repeat text-warning"></span>
Réouvrir
{% else %}
<span class="glyphicon glyphicon-ok text-success"></span>
Terminer
{% endif %}
</button>
</form>
<!-- Edit Button -->
<a href="{{ path('task_edit', {'id' : task.id }) }}" class="btn btn-warning btn-sm" style="font-weight: 500;">
<span class="glyphicon glyphicon-pencil"></span>
Modifier
</a>
<!-- Delete Button (Checked against security Voter) -->
{% if is_granted('delete', task) %}
<form action="{{ path('task_delete', {'id' : task.id}) }}" method="POST" style="margin: 0; display: inline-block;" onsubmit="return confirm('Are you sure you want to delete this task?');">
<button class="btn btn-link btn-sm text-danger" style="color: #d9534f; padding-left: 5px; padding-right: 5px; text-decoration: none;">
<span class="glyphicon glyphicon-trash"></span>
Supprimer
</button>
</form>
{% endif %}
</div>
</div>
</div>
<div>
<form action="{{ path('task_toggle', {'id' : task.id }) }}">
<button class="btn btn-success btn-sm pull-right">
{% if not task.isDone %}Marquer comme faite{% else %}Marquer non terminée{% endif %}
</button>
</form>
<form action="{{ path('task_delete', {'id' : task.id }) }}">
<button class="btn btn-danger btn-sm pull-right">Supprimer</button>
</form>
{% else %}
<!-- Fallback design when no tasks are recorded -->
<div class="col-xs-12">
<div class="alert alert-warning text-center" role="alert" style="padding: 40px; border-radius: 6px;">
<p style="font-size: 16px; margin-bottom: 20px;">
Aucune tâche n'a encore été enregistrée. Créez votre première tâche pour commencer à organiser vos activités !
</p>
<a href="{{ path('task_create') }}" class="btn btn-warning btn-lg">
<span class="glyphicon glyphicon-plus"></span>
Créer votre première tâche
</a>
</div>
</div>
</div>
{% endfor %}
</div>
{% else %}
<div class="alert alert-warning" role="alert">
Il n'y a pas encore de tâche enregistrée. <a href="{{ path('task_create') }}" class="btn btn-warning pull-right">Créer une tâche</a>
</div>
{% endfor %}
</div>
{% endblock %}
{% endblock %}


1 change: 0 additions & 1 deletion app/config/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ security:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
# Protect all user management paths (list, create, edit)
- { path: ^/users, roles: ROLE_ADMIN }
- { path: ^/, roles: ROLE_ADMIN }
- { path: ^/, roles: ROLE_USER }
5 changes: 5 additions & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ services:
# service_name:
# class: AppBundle\Directory\ClassName
# arguments: ["@another_service_name", "plain_value", "%parameter_name%"]
app.task_voter:
class: AppBundle\Security\TaskVoter
arguments: ['@security.access.decision_manager']
tags:
- { name: security.voter }
57 changes: 50 additions & 7 deletions src/AppBundle/Controller/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,40 @@
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

/**
* Class TaskController
*
* Handles all actions related to tasks management: listing, creation, edition,
* status toggling, and secure deletion.
*
* @package AppBundle\Controller
*/
class TaskController extends Controller
{
/**
* List all tasks.
*
* @Route("/tasks", name="task_list")
*
* @return Response
*/
public function listAction()
{
return $this->render('task/list.html.twig', ['tasks' => $this->getDoctrine()->getRepository('AppBundle:Task')->findAll()]);
return $this->render('task/list.html.twig', [
'tasks' => $this->getDoctrine()->getRepository('AppBundle:Task')->findAll()
]);
}

/**
* Create a new task.
*
* @Route("/tasks/create", name="task_create")
*
* @param Request $request
* @return RedirectResponse|Response
*/
public function createAction(Request $request)
{
Expand All @@ -37,27 +58,35 @@ public function createAction(Request $request)
$em->persist($task);
$em->flush();

$this->addFlash('success', 'La tâche a été bien été ajoutée.');
$this->addFlash('success', 'La tâche a bien été ajoutée.');

return $this->redirectToRoute('task_list');
}

return $this->render('task/create.html.twig', ['form' => $form->createView()]);
return $this->render('task/create.html.twig', [
'form' => $form->createView()
]);
}

/**
* Edit an existing task.
*
* @Route("/tasks/{id}/edit", name="task_edit")
*
* @param Task $task
* @param Request $request
* @return RedirectResponse|Response
*/
public function editAction(Task $task, Request $request)
{
// 1. Save the original user before handling the request
// Save the original user before handling the request
$originalUser = $task->getUser();

$form = $this->createForm(TaskType::class, $task);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
// 2. Enforce immutability: bypass any falsified request data by restoring the original user
// Enforce immutability: bypass any falsified request data by restoring the original user
$task->setUser($originalUser);

$this->getDoctrine()->getManager()->flush();
Expand All @@ -74,11 +103,17 @@ public function editAction(Task $task, Request $request)
}

/**
* Toggle the completion status of a task.
*
* @Route("/tasks/{id}/toggle", name="task_toggle")
*
* @param Task $task
* @return RedirectResponse
*/
public function toggleTaskAction(Task $task)
{
$task->toggle(!$task->isDone());
// Avoid negative operations (!) for Codacy check conformity
$task->toggle($task->isDone() === false);
$this->getDoctrine()->getManager()->flush();

$this->addFlash('success', sprintf('La tâche %s a bien été marquée comme faite.', $task->getTitle()));
Expand All @@ -87,10 +122,18 @@ public function toggleTaskAction(Task $task)
}

/**
* Delete a task securely.
*
* @Route("/tasks/{id}/delete", name="task_delete")
*
* @param Task $task
* @return RedirectResponse
*/
public function deleteTaskAction(Task $task)
{
// Apply security voter check: Only the author (or admin for anonymous tasks) can delete it
$this->denyAccessUnlessGranted('delete', $task);

$em = $this->getDoctrine()->getManager();
$em->remove($task);
$em->flush();
Expand Down
Loading
Loading