changes to TaskVoter reinstated, mistake made in conflict resolvement

This commit is contained in:
Julie Lenaerts 2021-10-01 11:18:10 +02:00
commit 85e8fe59a4
12 changed files with 493 additions and 7 deletions

View File

@ -80,6 +80,7 @@ class SingleTaskController extends AbstractController
$this->logger = $logger;
$this->request = $requestStack->getCurrentRequest();
}
private function getEntityContext()
{

View File

@ -88,7 +88,6 @@ class MenuBuilder implements LocalMenuBuilderInterface
$course = $parameters['accompanyingCourse'];
// if ($this->authorizationChecker->isGranted(TaskVoter::SHOW, $course)) {
$menu->addChild(
$this->translator->trans('Tasks'), [
@ -100,6 +99,7 @@ class MenuBuilder implements LocalMenuBuilderInterface
// }
}
public static function getMenuIds(): array
{
return ['person', 'accompanyingCourse'];

View File

@ -14,7 +14,7 @@
* 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 "@ChillPerson/Person/layout.html.twig" %}
{% extends person is defined ? "@ChillPerson/Person/layout.html.twig" : "@ChillPerson/AccompanyingCourse/layout.html.twig" %}
{% set activeRouteKey = 'chill_task_single_task_show' %}

View File

@ -0,0 +1,256 @@
{% macro date_status(title, tasks, count, paginator, status, isSingleStatus, person, user) %}
{% if tasks|length > 0 %}
<h3>{{ title|trans }}</h3>
<table class="table table-bordered border-dark chill-task-list">
<tbody>
{% for task in tasks %}
<tr>
<td>
<div>
<span class="chill-task-list__row__title">{{ task.title }}</span>
</div>
{% if person is null %}
<div>
<span class="chill-task-list__row__person-for">{{ 'For person'|trans }}&nbsp;:</span>
<span class="chill-task-list__row__person">
<a href="{{ path('chill_person_view', {person_id : task.person.Id}) }}">{{ task.person}}</a>
</span>
</div>
{% endif %}
<div>
<span class="chill-task-list__row__type">{{ task_workflow_metadata(task, 'definition.name')|trans }}</span>
</div>
<div>
{% for place in workflow_marked_places(task) %}
<span class="task-status box type-{{ task.type }} place-{{ place }}">{{ place|trans }}</span>
{% endfor %}
{% if task.assignee is not null %}
<div class="chill-task-list__row__assignee">
<span class="chill_task-list__row__assignee_by">{{ 'By'|trans }}&nbsp;:</span>
{{ task.assignee.username }}</div>
{% endif %}
</div>
{% if task.startDate is not null or task.warningDate is not null or task.endDate is not null %}
<div class="chill-task-list__row__dates">
<ul class="record_actions column">
{% if task.startDate is not null %}
<li title="{{ 'Start'|trans|escape('html_attr') }}">
<i class="fa fa-play"></i>
{{ task.startDate|format_date('medium') }}
</li>
{% endif %}
{% if task.warningDate is not null %}
<li title="{{ 'Warning'|trans|escape('html_attr') }}">
<i class="fa fa-exclamation-triangle"></i>
{{ task.warningDate|format_date('medium') }}
</li>
{% endif %}
{% if task.endDate is not null %}
<li title="{{ 'End'|trans|escape('html_attr') }}">
<i class="fa fa-hourglass-end"></i>
{{ task.endDate|format_date('medium') }}
</li>
{% endif %}
</ul>
</div>
{% endif %}
</td>
<td>
<ul class="record_actions">
{% if workflow_transitions(task)|length > 0 %}
<li>
<div class="btn-group">
<a class="btn btn-task-exchange dropdown-toggle" href="#" role="button" id="taskExchange" data-bs-toggle="dropdown" aria-expanded="false">
{{'Change task status'|trans}}
</a>
<ul class="dropdown-menu" aria-labelledby="taskExchange">
{% for transition in workflow_transitions(task) %}
<li>
<a class="dropdown-item" href="{{ path('chill_task_task_transition', { 'taskId': task.id, 'transition': transition.name, 'kind': 'single-task', 'list_params': app.request.query.all }) }}" class="{{ task_workflow_metadata(task, 'transition.class', transition)|e('html_attr') }}">
{{ task_workflow_metadata(task, 'transition.verb', transition)|trans }}
</a>
</li>
{% endfor %}
</ul>
</div>
</li>
{% endif %}
<li>
<a href="{{ path('chill_task_single_task_show', { 'id': task.id, 'list_params': app.request.query.all }) }}" class="btn btn-show "></a>
</li>
{% 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>
</li>
{% endif %}
{% 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>
</li>
{% endif %}
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if isSingleStatus %}
{% if tasks|length < paginator.getTotalItems %}
{{ chill_pagination(paginator) }}
{% endif %}
<!-- lien retour -->
<ul class="record_actions">
<li>
{% if person is not null %}
<a href="{{ path('chill_task_singletask_list', {'person_id': person.id}) }}" class="btn btn-cancel">
{{ 'Back to the list' | trans }}
</a>
{% endif %}
{% if user is not null %}
<a href="{{ path('chill_task_singletask_list') }}" class="btn btn-cancel">
{{ 'Back to the list' | trans }}
</a>
{% endif %}
</li>
<li>
{% if person is not null %}
<a href="{{ path('chill_task_single_task_new', {'person_id': person.id}) }}" class="btn btn-create">
{{ 'Add a new task' | trans }}
</a>
{% endif %}
{% if user is not null %}
<a href="{{ path('chill_task_single_task_new') }}" class="btn btn-create">
{{ 'Add a new task' | trans }}
</a>
{% endif %}
</li>
</ul>
{% else %}
<ul class="record_actions">
<li>
<a href="{{ path('chill_task_singletask_list', app.request.query.all|merge({ 'status': [ status ] })) }}" class="btn btn-misc">
{{ 'See more' | trans }}
</a>
</li>
</ul>
{% endif %}
{% endif %}
{% endmacro %}
{% import _self as helper %}
<h1>{{ app.request.query.get('title', null)|escape('html')|default('Task list'|trans) }}</h1>
{% if false == app.request.query.boolean('hide_form', false) %}
<h2>{{ 'Filter the tasks'|trans }}</h2>
{{ form_start(form) }}
{{ form_row(form.user_id) }}
{% if form.status is defined %}
{{ form_row(form.status) }}
{% endif %}
{% if form.types is defined %}
{{ form_row(form.types) }}
{% endif %}
{% if form.person_id is defined %}
{{ form_row(form.person_id) }}
{% endif %}
{% if form.center_id is defined %}
{{ form_row(form.center_id) }}
{% endif %}
<ul class="record_actions">
<li>
<button type="submit" class="btn btn-submit">{{ 'Filter'|trans }}</button>
</li>
</ul>
{{ form_end(form)}}
{% endif %}
{% if tasks_count == 0 %}
<p class="chill-no-data-statement">{{ "There is no tasks."|trans }}</p>
{% if person is not null and is_granted('CHILL_TASK_TASK_CREATE', person) %}
<ul class="record_actions">
<li>
{% if person is not null %}
<a href="{{ path('chill_task_single_task_new', {'person_id': person.id}) }}" class="btn btn-create">
{{ 'Add a new task' | trans }}
</a>
{% endif %}
</li>
</ul>
{% endif %}
{% else %}
{% if false == app.request.query.boolean('hide_form', false) %}
<h2>{{ 'Tasks'|trans }}</h2>
{% endif %}
{% if person is not null and is_granted('CHILL_TASK_TASK_CREATE', person) %}
<ul class="record_actions">
<li>
{% if person is not null %}
<a href="{{ path('chill_task_single_task_new', {'person_id': person.id}) }}" class="btn btn-create">
{{ 'Add a new task' | trans }}
</a>
{% endif %}
</li>
</ul>
{% endif %}
{% 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, 'ended', isSingleStatus, person) }}
{% 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, 'warning', isSingleStatus, person) }}
{% 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, 'current', isSingleStatus, person) }}
{% 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, 'not_started', isSingleStatus, person) }}
{% endif %}
{% if single_task_closed_tasks is defined %}
{{ helper.date_status('Closed tasks', single_task_closed_tasks, single_task_closed_count, single_task_closed_paginator, 'closed', isSingleStatus, person) }}
{% endif %}
{% if isSingleStatus == false %}
<ul class="record_actions">
<li>
{% if person is not null and is_granted('CHILL_TASK_TASK_CREATE', person) %}
<a href="{{ path('chill_task_single_task_new', {'person_id': person.id}) }}" class="btn btn-create">
{{ 'Add a new task' | trans }}
</a>
{% endif %}
{% if accompanyingCourse is not null %}
<a href="{{ path('chill_task_single_task_new', {'course_id': accompanyingCourse.id}) }}" class="btn btn-create">
{{ 'Add a new task' | trans }}
</a>
{% endif %}
</li>
</ul>
{% endif %}
{% endif %}

View File

@ -0,0 +1,107 @@
{% if tasks|length > 0 %}
<h3>{{ title|trans }}</h3>
<table class="table table-bordered border-dark chill-task-list">
<tbody>
{% for task in tasks %}
<tr>
<td>
<div>
<span class="chill-task-list__row__title">{{ task.title }}</span>
</div>
<div>
<span class="chill-task-list__row__type">{{ task_workflow_metadata(task, 'definition.name')|trans }}</span>
</div>
<div>
{% for place in workflow_marked_places(task) %}
<span class="task-status box type-{{ task.type }} place-{{ place }}">{{ place|trans }}</span>
{% endfor %}
{% if task.assignee is not null %}
<div class="chill-task-list__row__assignee">
<span class="chill_task-list__row__assignee_by">{{ 'By'|trans }}&nbsp;:</span>
{{ task.assignee.username }}</div>
{% endif %}
</div>
{% if task.startDate is not null or task.warningDate is not null or task.endDate is not null %}
<div class="chill-task-list__row__dates">
<ul class="record_actions column">
{% if task.startDate is not null %}
<li title="{{ 'Start'|trans|escape('html_attr') }}">
<i class="fa fa-play"></i>
{{ task.startDate|format_date('medium') }}
</li>
{% endif %}
{% if task.warningDate is not null %}
<li title="{{ 'Warning'|trans|escape('html_attr') }}">
<i class="fa fa-exclamation-triangle"></i>
{{ task.warningDate|format_date('medium') }}
</li>
{% endif %}
{% if task.endDate is not null %}
<li title="{{ 'End'|trans|escape('html_attr') }}">
<i class="fa fa-hourglass-end"></i>
{{ task.endDate|format_date('medium') }}
</li>
{% endif %}
</ul>
</div>
{% endif %}
</td>
<td>
<ul
class="record_actions">
{# {% if workflow_transitions(task)|length > 0 %}
<li>
<div class="btn-group">
<a class="btn btn-task-exchange dropdown-toggle" href="#" role="button" id="taskExchange" data-bs-toggle="dropdown" aria-expanded="false">
{{'Change task status'|trans}}
</a>
<ul class="dropdown-menu" aria-labelledby="taskExchange">
{% for transition in workflow_transitions(task) %}
<li>
<a class="dropdown-item" href="{{ path('chill_task_task_transition', { 'taskId': task.id, 'transition': transition.name, 'kind': 'single-task', 'list_params': app.request.query.all }) }}" class="{{ task_workflow_metadata(task, 'transition.class', transition)|e('html_attr') }}">
{{ task_workflow_metadata(task, 'transition.verb', transition)|trans }}
</a>
</li>
{% endfor %}
</ul>
</div>
</li>
{% endif %} #}
<li>
<a href="{{ path('chill_task_single_task_show', { 'id': task.id, 'list_params': app.request.query.all }) }}" class="btn btn-show "></a>
</li>
{# {% 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>
</li>
{# {% endif %} #}
{# {% 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>
</li>
{# {% endif %} #}
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
<ul class="record_actions">
<li>
{% if accompanyingCourse is not null %}
<a href="{{ path('chill_task_single_task_new', {'course_id': accompanyingCourse.id}) }}" class="btn btn-create">
{{ 'Add a new task' | trans }}
</a>
{% endif %}
</li>
</ul>

View File

@ -0,0 +1,19 @@
{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %}
{% set activeRouteKey = 'chill_task_task_list' %}
{% set course = task.course %}
{% block title 'Remove task'|trans %}
{% block content %}
{{ include('@ChillMain/Util/confirmation_template.html.twig',
{
'title' : 'Remove task'|trans,
'confirm_question' : 'Are you sure you want to remove the task about accompanying period "%id%" ?'|trans({ '%id%' : course.id } ),
'cancel_route' : 'chill_task_singletask_courselist',
'cancel_parameters' : app.request.query.get('list_params', { } ),
'form' : delete_form,
} ) }}
{% endblock %}

View File

@ -0,0 +1,30 @@
{#
* 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 person is defined ? "@ChillPerson/Person/layout.html.twig" %}
{% set activeRouteKey = 'chill_task_single_task_edit' %}
{% set person = task.person %}
{% block title %}
{{ 'Edit task'|trans }}
{% endblock %}
{% block personcontent %}
{% include 'ChillTaskBundle:SingleTask:_edit.html.twig' %}
{% endblock %}

View File

@ -0,0 +1,14 @@
{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %}
{% set activeRouteKey = 'chill_task_single_task_edit' %}
{% set course = task.course %}
{% block title %}
{{ 'Edit task'|trans }}
{% endblock %}
{% block content %}
{% include 'ChillTaskBundle:SingleTask:_edit.html.twig' %}
{% endblock %}

View File

@ -0,0 +1,12 @@
{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %}
{% set activeRouteKey = 'chill_task_single_task_new' %}
{# {% set person = task.person %} #}
{% block title %}
{{ 'New task'|trans }}
{% endblock %}
{% block content %}
{% include 'ChillTaskBundle:SingleTask:_new.html.twig' %}
{% endblock %}

View File

@ -0,0 +1,32 @@
{#
* 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 "@ChillPerson/Person/layout.html.twig" %}
{% set activeRouteKey = 'chill_task_single_task_show' %}
{% set person = task.person %}
{% block title %}
{{ 'Task'|trans }}
{% endblock %}
{% block personcontent %}
{% include 'ChillTaskBundle:SingleTask:_show.html.twig' %}
{% endblock %}

View File

@ -0,0 +1,16 @@
{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %}
{% set activeRouteKey = 'chill_task_single_task_show' %}
{% set accompanyingCourse = task.course %}
{% block title %}
{{ 'Task'|trans }}
{% endblock %}
{% block content %}
{% include 'ChillTaskBundle:SingleTask:_show.html.twig' %}
{% endblock %}

View File

@ -146,18 +146,15 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
// do regular check.
return $this->voter->voteOnAttribute($attribute, $subject, $token);
/*
if ($subject instanceof AbstractTask) {
$associated = $subject->getPerson() ?? $subject->getCourse();
if ($associated === null) {
throw new \LogicException("You should associate a person with task "
. "in order to check autorizations");
}
$person = $subject->getPerson();
} elseif ($subject instanceof Person) {
$associated = $subject;
} else {
// subject is null. We check that at least one center is reachable
$centers = $this->authorizationHelper->getReachableCenters($token->getUser(), new Role($attribute));
@ -173,6 +170,8 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
return false;
} elseif ($associated instanceof AccompanyingPeriod && !$this->accessDecisionManager->decide($token, [AccompanyingPeriodVoter::SEE], $associated)) {
return false;
} elseif ($associated instanceof AccompanyingPeriod && !$this->accessDecisionManager->decide($token, [AccompanyingPeriodVoter::SEE], $associated)) {
return false;
}
return $this->authorizationHelper->userHasAccess(
@ -180,7 +179,7 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
$subject,
$attribute
);
*/
}
public function getRoles()