add a button 'new task' in page head and improve voter

This commit is contained in:
Julien Fastré 2018-07-05 15:33:35 +02:00
parent 9852430b13
commit 066efdc042
3 changed files with 43 additions and 27 deletions

View File

@ -8,7 +8,7 @@ Scope: Cercle
'Start date': 'Date de début'
'End date': "Date d'échéance"
'Warning date': "Date d'avertissement"
'Warning interval': "Délai d'avertissement de la date d'échéance"
'Warning interval': "Délai d'avertissement avant la date d'échéance"
'Unknown dates': 'Dates non spécifiées'
'N': ''
'Unit': ''

View File

@ -1,6 +1,6 @@
{% macro date_status(title, tasks, count, paginator, status, isSingleStatus, person, user) %}
{% if tasks|length > 0 %}
<h2>{{ title|trans }}</h2>
<h3>{{ title|trans }}</h3>
<table class="records_list">
<thead>
@ -141,10 +141,10 @@
{% import _self as helper %}
<h1>{{ 'Task list'|trans }}</h1>
<h1>{{ app.request.title|default('Task list')|trans }}</h1>
{% if false == app.request.query.boolean('hide_form', false) %}
<h3>{{ 'Filter the tasks'|trans }}</h3>
<h2>{{ 'Filter the tasks'|trans }}</h2>
{{ form_start(form) }}
{{ form_row(form.user_id) }}
@ -168,18 +168,32 @@
{% if tasks_count == 0 %}
<p class="chill-no-data-statement">{{ "There is no tasks."|trans }}</p>
{% if person is not null %}
<a href="{{ path('chill_task_single_task_new', {'person_id': person.id}) }}" class="sc-button bt-create">
{{ 'Add a new task' | trans }}
</a>
{% 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="sc-button bt-create">
{{ 'Add a new task' | trans }}
</a>
{% endif %}
</li>
</ul>
{% endif %}
<!-- Pour l'instant, il n'est pas encore possible d'ajouter une tache sans personne liée -->
<!-- {% if person is null %}
<a href="{{ path('chill_task_single_task_new') }}" class="sc-button bt-create">
{{ 'Add a new task' | trans }}
</a>
{% endif %} -->
{% else %}
<h2>{{ 'Tasks'|trans }}</h2>
{% 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="sc-button bt-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) }}
@ -204,17 +218,11 @@
{% if isSingleStatus == false %}
<ul class="record_actions">
<li>
{% if person is not null %}
{% 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="sc-button bt-create">
{{ 'Add a new task' | trans }}
</a>
{% endif %}
<!-- Pour l'instant, il n'est pas encore possible d'ajouter une tache sans personne liée -->
<!-- {% if person is null %}
<a href="{{ path('chill_task_single_task_new') }}" class="sc-button bt-create">
{{ 'Add a new task' | trans }}
</a>
{% endif %} -->
</li>
</ul>
{% endif %}

View File

@ -27,6 +27,7 @@ use Psr\Log\LoggerInterface;
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\Person;
/**
*
@ -77,8 +78,9 @@ class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterf
public function supports($attribute, $subject)
{
return $subject instanceof AbstractTask
&& in_array($attribute, self::ROLES);
return ($subject instanceof AbstractTask && in_array($attribute, self::ROLES))
||
($subject instanceof Person && $attribute === self::CREATE);
}
/**
@ -96,12 +98,18 @@ class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterf
return false;
}
if ($subject->getPerson() === null) {
throw new \LogicException("You should associate a person with task "
. "in order to check autorizations");
if ($subject instanceof AbstractTask) {
if ($subject->getPerson() === null) {
throw new \LogicException("You should associate a person with task "
. "in order to check autorizations");
}
$person = $subject->getPerson();
} else {
$person = $subject;
}
if (!$this->accessDecisionManager->decide($token, [PersonVoter::SEE], $subject->getPerson())) {
if (!$this->accessDecisionManager->decide($token, [PersonVoter::SEE], $person)) {
return false;
}