activity: set ACL (issue 292)

https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/292
This commit is contained in:
Mathieu Jaumotte 2021-12-08 10:41:15 +01:00
parent 1efdade382
commit 97165c8389
3 changed files with 160 additions and 114 deletions

View File

@ -15,16 +15,13 @@
<div class="wrap-list"> <div class="wrap-list">
<div class="wl-row"> <div class="wl-row">
<div class="wl-col title"> <div class="wl-col title">
{% if activity.date %} {% if activity.date %}
<p class="date-label"> <p class="date-label">
{{ activity.date|format_date('short') }} {{ activity.date|format_date('short') }}
</p> </p>
{% endif %} {% endif %}
</div> </div>
<div class="wl-col list"> <div class="wl-col list">
<h2 class="badge-title"> <h2 class="badge-title">
<span class="title_label"></span> <span class="title_label"></span>
<span class="title_action"> <span class="title_action">
@ -35,7 +32,6 @@
{% endif %} {% endif %}
</span> </span>
</h2> </h2>
</div> </div>
</div> </div>
</div> </div>
@ -131,8 +127,11 @@
</div> </div>
{% endif %} {% endif %}
{# SEULEMENT SI DÉTAILLÉ {# Only if ACL SEE_DETAILS AND/OR only on template SHOW ??
{% if activity.comment.comment is not empty %} durationTime
travelTime
comment
{% if activity.comment.comment is not empty and is_granted('CHILL_ACTIVITY_SEE_DETAILS', activity) %}
<div class="wl-row"> <div class="wl-row">
<div class="wl-col title"> <div class="wl-col title">
<h3>{{ 'Comment'|trans }}</h3> <h3>{{ 'Comment'|trans }}</h3>
@ -146,6 +145,8 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
documents
attendee
#} #}
</div> </div>
</div> </div>
@ -153,29 +154,49 @@
<div class="item-row separator"> <div class="item-row separator">
<ul class="record_actions"> <ul class="record_actions">
{% if context == 'person' and activity.accompanyingPeriod is not empty %} {% if context == 'person' and activity.accompanyingPeriod is not empty %}
{#
Disable person_id in following links, for redirect to accompanyingCourse context
#}
{% set person_id = null %}
{% set accompanying_course_id = activity.accompanyingPeriod.id %}
<li> <li>
<a class="btn btn-primary" <a href="{{ chill_path_add_return_path('chill_activity_activity_list',{
title="{{ 'See activity in accompanying course context'|trans }}" 'accompanying_period_id': accompanying_course_id
href="{{ chill_path_add_return_path( }) }}"
"chill_activity_activity_list", class="btn btn-primary"
{ 'accompanying_period_id': activity.accompanyingPeriod.id } title="{{ 'See activity in accompanying course context'|trans }}">
) }}"><i class="fa fa-random fa-fw"></i> <i class="fa fa-random fa-fw"></i>
{{ 'Period number %number%'|trans({'%number%': activity.accompanyingPeriod.id}) }} {{ 'Period number %number%'|trans({'%number%': accompanying_course_id}) }}
</a> </a>
</li> </li>
{% else %} {% endif %}
<li> <li>
<a href="{{ path('chill_activity_activity_show', { 'id': activity.id, 'person_id': person_id, 'accompanying_period_id': accompanying_course_id }) }}" <a href="{{ path('chill_activity_activity_show', {'id': activity.id,
class="btn btn-show" title="{{ 'Show'|trans }}"></a> 'person_id': person_id,
'accompanying_period_id': accompanying_course_id
}) }}"
class="btn btn-show"
title="{{ 'Show'|trans }}"></a>
</li> </li>
{% if no_action is not defined or no_action == false %} {% if no_action is not defined or no_action == false %}
{% if is_granted('CHILL_ACTIVITY_UPDATE', activity) %}
<li> <li>
<a href="{{ path('chill_activity_activity_edit', { 'id': activity.id, 'person_id': person_id, 'accompanying_period_id': accompanying_course_id }) }}" <a href="{{ path('chill_activity_activity_edit', {'id': activity.id,
class="btn btn-update" title="{{ 'Edit'|trans }}"></a> 'person_id': person_id,
'accompanying_period_id': accompanying_course_id
}) }}"
class="btn btn-update"
title="{{ 'Edit'|trans }}"></a>
</li> </li>
{% endif %}
{% if is_granted('CHILL_ACTIVITY_DELETE', activity) %}
<li> <li>
<a href="{{ path('chill_activity_activity_delete', { 'id': activity.id, 'person_id' : person_id, 'accompanying_period_id': accompanying_course_id } ) }}" <a href="{{ path('chill_activity_activity_delete', {'id': activity.id,
class="btn btn-delete" title="{{ 'Delete'|trans }}"></a> 'person_id': person_id,
'accompanying_period_id': accompanying_course_id
}) }}"
class="btn btn-delete"
title="{{ 'Delete'|trans }}"></a>
</li> </li>
{% endif %} {% endif %}
{% endif %} {% endif %}

View File

@ -1,26 +1,28 @@
{%- set t = entity.type -%} {%- set t = entity.type -%}
{%- import "@ChillDocStore/Macro/macro.html.twig" as m -%} {%- import "@ChillDocStore/Macro/macro.html.twig" as m -%}
<h1> <h2 class="chill-green-dark">
{{ "Activity"|trans }} {{ "Activity"|trans }}{{ ', le ' ~ entity.date|format_date('long') }}
{%- if t.emergencyVisible and entity.emergency -%} {%- if t.emergencyVisible and entity.emergency -%}
<span class="badge bg-secondary"> <span class="badge bg-danger rounded-pill fs-6 float-end">
{{- 'Emergency'|trans -}} {{- 'Emergency'|trans -}}
</span> </span>
{%- endif -%} {%- endif -%}
</h2>
<h1>
{{ entity.type.name | localize_translatable_string }}
</h1> </h1>
<dl class="chill_view_data"> <dl class="chill_view_data">
<dt class="inline">{{ 'by'|trans|capitalize }}</dt> <dt class="inline">{{ 'by'|trans|capitalize }}</dt>
<dd>{{ entity.user }}</dd> <dd>{{ entity.user }}</dd>
<dt class="inline">{{ 'Type'|trans }}</dt>
<dd>{{ entity.type.name | localize_translatable_string }}</dd>
{%- if entity.scope -%} {%- if entity.scope -%}
<dt class="inline">{{ 'Scope'|trans }}</dt> <dt class="inline">{{ 'Scope'|trans }}</dt>
<dd><span class="scope">{{ entity.scope.name|localize_translatable_string }}</span></dd> <dd>
<span class="scope">{{ entity.scope.name|localize_translatable_string }}</span>
</dd>
{% endif %} {% endif %}
{% if t.socialIssuesVisible %} {% if t.socialIssuesVisible %}
@ -38,7 +40,7 @@
<dt class="inline">{{ 'Social actions'|trans }}</dt> <dt class="inline">{{ 'Social actions'|trans }}</dt>
<dd> <dd>
{% if entity.socialActions|length == 0 %} {% if entity.socialActions|length == 0 %}
<p class="chill-no-data-statement">{{ 'No social actions associated'|trans }}</p> <span class="chill-no-data-statement">{{ 'No social actions associated'|trans }}</span>
{% else %} {% else %}
{% for sa in entity.socialActions %}{{ sa|chill_entity_render_box }}{% endfor %} {% for sa in entity.socialActions %}{{ sa|chill_entity_render_box }}{% endfor %}
{% endif %} {% endif %}
@ -47,18 +49,26 @@
{% if t.reasonsVisible %} {% if t.reasonsVisible %}
<dt class="inline">{{ 'Reasons'|trans }}</dt> <dt class="inline">{{ 'Reasons'|trans }}</dt>
<dd>
{%- if entity.reasons is empty -%} {%- if entity.reasons is empty -%}
<dd><span class="chill-no-data-statement">{{ 'No reason associated'|trans }}</span></dd> <span class="chill-no-data-statement">{{ 'No reason associated'|trans }}</span>
{%- else -%} {%- else -%}
<dd>{% for r in entity.reasons %}{{ r|chill_entity_render_box }} {% endfor %}</dd> {% for r in entity.reasons %}{{ r|chill_entity_render_box }}{% endfor %}
{%- endif -%} {%- endif -%}
</dd>
{% endif %} {% endif %}
</dl>
<h2 class="chill-red">{{ 'Concerned groups'|trans }}</h2> <h2 class="chill-green-dark">{{ 'Concerned groups'|trans }}</h2>
{% include 'ChillActivityBundle:Activity:concernedGroups.html.twig' with {'context': context, 'with_display': 'bloc', 'badge_person': 'true' } %}
<h2 class="chill-red">{{ 'Activity data'|trans }}</h2> {% include 'ChillActivityBundle:Activity:concernedGroups.html.twig' with {
'context': context,
'with_display': 'bloc',
'badge_person': 'true'
} %}
<h2 class="chill-green-dark">{{ 'Activity data'|trans }}</h2>
<dl>
<dt class="inline">{{ 'Date'|trans }}</dt> <dt class="inline">{{ 'Date'|trans }}</dt>
<dd>{{ entity.date|format_date('long') }}</dd> <dd>{{ entity.date|format_date('long') }}</dd>
@ -67,59 +77,77 @@
<dd> <dd>
{% if entity.location is not null %} {% if entity.location is not null %}
<p> <p>
<span>{{ entity.location.locationType.title|localize_translatable_string }}</span>
{{ entity.location.name }} {{ entity.location.name }}
<span> ({{ entity.location.locationType.title|localize_translatable_string }})</span>
</p> </p>
{{ entity.location.address|chill_entity_render_box }} <div class="ms-3">{{ entity.location.address|chill_entity_render_box }}</div>
{% else %} {% else %}
<span class="chill-no-data-statement">{{ 'No address given'|trans }}</span> <span class="chill-no-data-statement">{{ 'No address given'|trans }}</span>
{% endif %} {% endif %}
</dd> </dd>
{% endif %} {% endif %}
{% if t.durationTimeVisible %} {% if t.durationTimeVisible and is_granted('CHILL_ACTIVITY_SEE_DETAILS', entity) %}
<dt class="inline">{{ 'Duration Time'|trans }}</dt> <dt class="inline">{{ 'Duration Time'|trans }}</dt>
<dd>{% if entity.durationTime is not null %} <dd>
{% if entity.durationTime is not null %}
{{ entity.durationTime|date('H:i') }} {{ entity.durationTime|date('H:i') }}
{% else %} {% else %}
{{ 'None'|trans|capitalize }} <span class="chill-no-data-statement">{{ 'None'|trans|capitalize }}</span>
{% endif %} {% endif %}
</dd> </dd>
{% endif %} {% endif %}
{% if t.travelTimeVisible %} {% if t.travelTimeVisible and is_granted('CHILL_ACTIVITY_SEE_DETAILS', entity) %}
<dt class="inline">{{ 'Travel time'|trans }}</dt> <dt class="inline">{{ 'Travel time'|trans }}</dt>
<dd>{% if entity.travelTime is not null %} <dd>
{% if entity.travelTime is not null %}
{{ entity.travelTime|date('H:i') }} {{ entity.travelTime|date('H:i') }}
{% else %} {% else %}
{{ 'None'|trans|capitalize }} <span class="chill-no-data-statement">{{ 'None'|trans|capitalize }}</span>
{% endif %} {% endif %}
</dd> </dd>
{% endif %} {% endif %}
{% if t.commentVisible %} {% if t.commentVisible and is_granted('CHILL_ACTIVITY_SEE_DETAILS', entity) %}
<dt class="inline">{{ 'activity.comment'|trans }}</dt> <dt class="inline">{{ 'activity.comment'|trans }}</dt>
<dd>
{%- if entity.comment.empty -%} {%- if entity.comment.empty -%}
<dd><span class="chill-no-data-statement">{{ 'No comment associated'|trans }}</span></dd> <span class="chill-no-data-statement">{{ 'No comment associated'|trans }}</span>
{%- else -%} {%- else -%}
<dd>{{ entity.comment|chill_entity_render_box }}</dd> {{ entity.comment|chill_entity_render_box }}
{%- endif -%} {%- endif -%}
</dd>
{% endif %} {% endif %}
{% if t.documentsVisible and entity.documents|length > 0 %} {% if t.documentsVisible and is_granted('CHILL_ACTIVITY_SEE_DETAILS', entity) %}
<dt>{{ 'Documents'|trans }}</dt> <dt class="inline">{{ 'Documents'|trans }}</dt>
<dd> <dd>
{% if entity.documents|length > 0 %}
<ul> <ul>
{% for d in entity.documents %} {% for d in entity.documents %}
<li>{{ m.download_button(d) }}</li> <li>{{ m.download_button(d) }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
{% else %}
<span class="chill-no-data-statement">{{ 'Any document found'|trans }}</span>
{% endif %}
</dd> </dd>
{% endif %} {% endif %}
{% if t.attendeeVisible %} {% if t.attendeeVisible and is_granted('CHILL_ACTIVITY_SEE_DETAILS', entity) %}
<dt class="inline">{{ 'Attendee'|trans }}</dt> <dt class="inline">{{ 'Attendee'|trans }}</dt>
<dd>{% if entity.attendee is not null %}{% if entity.attendee %}{{ 'present'|trans|capitalize }} {% else %} {{ 'not present'|trans|capitalize }}{% endif %}{% else %}{{ 'None'|trans|capitalize }}{% endif %}</dd> <dd>
{% if entity.attendee is not null %}
{% if entity.attendee %}
{{ 'present'|trans|capitalize }}
{% else %}
{{ 'not present'|trans|capitalize }}
{% endif %}
{% else %}
<span class="chill-no-data-statement">{{ 'None'|trans|capitalize }}</span>
{% endif %}
</dd>
{% endif %} {% endif %}
</dl> </dl>
@ -140,23 +168,18 @@
{{ 'Back to the list'|trans }} {{ 'Back to the list'|trans }}
</a> </a>
</li> </li>
{% if is_granted('CHILL_ACTIVITY_UPDATE', entity) %}
<li> <li>
<a class="btn btn-update" href="{{ path('chill_activity_activity_edit', { 'id': entity.id, 'person_id': person_id, 'accompanying_period_id': accompanying_course_id }) }}"> <a class="btn btn-update" href="{{ path('chill_activity_activity_edit', { 'id': entity.id, 'person_id': person_id, 'accompanying_period_id': accompanying_course_id }) }}">
{{ 'Edit'|trans }} {{ 'Edit'|trans }}
</a> </a>
</li> </li>
{% endif %}
{# TODO
{% if is_granted('CHILL_ACTIVITY_DELETE', entity) %} {% if is_granted('CHILL_ACTIVITY_DELETE', entity) %}
#}
<li> <li>
<a href="{{ path('chill_activity_activity_delete', { 'id': entity.id, 'person_id' : person_id, 'accompanying_period_id': accompanying_course_id } ) }}" class="btn btn-delete"> <a href="{{ path('chill_activity_activity_delete', { 'id': entity.id, 'person_id' : person_id, 'accompanying_period_id': accompanying_course_id } ) }}" class="btn btn-delete">
{{ 'Delete'|trans }} {{ 'Delete'|trans }}
</a> </a>
</li> </li>
{#
{% endif %} {% endif %}
#}
</ul> </ul>

View File

@ -92,6 +92,8 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
public function getRoles(): array public function getRoles(): array
{ {
return [ return [
self::SEE,
self::SEE_DETAILS,
self::CREATE_PERSON, self::CREATE_PERSON,
self::CREATE_ACCOMPANYING_COURSE, self::CREATE_ACCOMPANYING_COURSE,
self::UPDATE, self::UPDATE,