Skip to content

Commit

Permalink
Événements : améliorations supplémentaires sur les procurations (elef…
Browse files Browse the repository at this point in the history
…an-grenoble#1028)

* Event: if past, then new proxy not allowed

* Proxy: only allow delete in edit page

* Improve event proxy delete urls
  • Loading branch information
raphodn authored and OursDesCavernes committed Jan 20, 2024
1 parent 1cc512f commit 1f797d3
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 95 deletions.
110 changes: 62 additions & 48 deletions app/Resources/views/admin/event/_partial/card_action.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,82 @@
{% set from_admin = from_admin ?? false %}

<div class="card-action">
{% if not only_action %}
<div class="right">
<a href="{{ path("event_detail", {'id': event.id}) }}" class="{% if not from_admin %}btn blue{% endif %}" {% if from_admin %}target="_blank"{% endif %}>
<i class="material-icons left">visibility</i>Voir
</a>
</div>
{% endif %}
{% if not is_granted("IS_AUTHENTICATED_REMEMBERED") %}
<span>Connexion requise</span>
{% elseif event.needProxy %}
{% if from_admin %}
{% elseif from_admin %}
{% if event.needProxy %}
<div class="left">
<a href="{{ path("admin_event_proxies_list", {'id': event.id}) }}"><i class="material-icons left">list</i>Procurations</a>
<a href="{{ path("admin_event_proxies_list", {'id': event.id}) }}">
<i class="material-icons left">list</i>Procurations
</a>
</div>
<div class="left">
<a href="{{ path("admin_event_signatures", {'id': event.id}) }}"><i class="material-icons left">print</i>Emargement</a>
<a href="{{ path("admin_event_signatures", {'id': event.id}) }}">
<i class="material-icons left">print</i>Emargement
</a>
</div>
{% endif %}
<div class="right">
<a href="{{ path("admin_event_edit", {'id': event.id}) }}">
<i class="material-icons left">edit</i>Editer
</a>
</div>
{% elseif event.needProxy %}{# member side #}
{% if not app.user.beneficiary or not app.user.beneficiary.membership or not app.user.beneficiary.membership.lastRegistration %}
<span>Oups, nous n'avons enregistré aucune adhésion pour ton compte. Tu ne pourras pas voter pour cet événement.</span>
{% else %}
{% if not app.user.beneficiary or not app.user.beneficiary.membership or not app.user.beneficiary.membership.lastRegistration %}
<span>Oups, nous n'avons enregistré aucune adhésion pour ton compte. Tu ne pourras pas voter pour cet événement.</span>
{% set member = app.user.beneficiary.membership %}
{% set proxy_given = event | givenProxy %}
{% set proxy_received = event | receivedProxies %}

{% if (registration_duration is not null) %}
{% set minDateOfLastRegistration = event.maxDateOfLastRegistration | date_modify('-' ~ registration_duration) %}
{% else %}
{% set member = app.user.beneficiary.membership %}
{% set proxy_given = event | givenProxy %}
{% set proxy_received = event | receivedProxies %}
{% set minDateOfLastRegistration = null %}
{% endif %}

{% if (registration_duration is not null) %}
{% set minDateOfLastRegistration = event.maxDateOfLastRegistration | date_modify('-' ~ registration_duration) %}
{% else %}
{% set minDateOfLastRegistration = null %}
{% if (minDateOfLastRegistration is not null and member.lastRegistration.date < minDateOfLastRegistration) %}
<b>Oups</b>, seuls les membres qui ont adhéré ou ré-adhéré <b>après le {{ minDateOfLastRegistration | date_short }}</b> peuvent voter à cet événement.
<br />
Pense à mettre à jour ton adhésion pour participer ! :)
{% elseif (member.getShiftTimeCount(event.maxDateOfLastRegistration) < time_after_which_members_are_late_with_shifts * 60) %}
<b>Oups</b>, seuls les membres avec un compteur de créneaux supérieur à <b>{{ time_after_which_members_are_late_with_shifts }} à la date du {{ event.maxDateOfLastRegistration | date_short }}</b> peuvent voter à cet événement.
<br />
Pense à rattraper tes créneaux pour la prochaine fois ! :)
{% else %}{# member allowed to vote #}
{% if proxy_given is not null %}
{% if proxy_given.owner is null %}
<span>Procuration donnée au premier membre volontaire</span>
{% else %}
<span>Procuration donnée à <b>{{ proxy_given.owner.membership.memberNumberWithBeneficiaryListString }}</b></span>
{% endif %}
{% endif %}
{% if (minDateOfLastRegistration is not null and member.lastRegistration.date < minDateOfLastRegistration) %}
<b>Oups</b>, seuls les membres qui ont adhéré ou ré-adhéré <b>après le {{ minDateOfLastRegistration | date_short }}</b> peuvent voter à cet événement.
<br />
Pense à mettre à jour ton adhésion pour participer ! :)
{% elseif (member.getShiftTimeCount(event.maxDateOfLastRegistration) < time_after_which_members_are_late_with_shifts * 60) %}
<b>Oups</b>, seuls les membres avec un compteur de créneaux supérieur à <b>{{ time_after_which_members_are_late_with_shifts }} à la date du {{ event.maxDateOfLastRegistration | date_short }}</b> peuvent voter à cet événement.
<br />
Pense à rattraper tes créneaux pour la prochaine fois ! :)
{% else %}
{% if proxy_given is not null %}
{% if proxy_given.owner is null %}
<span>Procuration donnée au premier membre volontaire</span>
{% else %}
<span>Procuration donnée à &nbsp;<b>{{ proxy_given.owner.membership.memberNumberWithBeneficiaryListString }}</b></span>
{% endif %}
{% for proxy_received_item in proxy_received %}
{% if proxy_received_item.giver %}
<div>Procuration portée par <b>{{ proxy_received_item.owner.membership.memberNumberWithBeneficiaryListString }}</b> de la part de&nbsp;<b>{{ proxy_received_item.giver.memberNumberWithBeneficiaryListString }}</b></div>
{% else %}
<div>
<b>{{ proxy_received_item.owner.membership.memberNumberWithBeneficiaryListString }}</b> accepte une procuration.
<a href="{{ path("event_proxy_lite_delete",{'id':event.id,'proxy':proxy_received_item.id}) }}" class="red-text" onclick="return confirm('Etes-vous sûr ?!');">X</a>
</div>
{% endif %}
{% for proxy_received_item in proxy_received %}
{% if proxy_received_item.giver %}
<div>Procuration portée par <b>{{ proxy_received_item.owner.membership.memberNumberWithBeneficiaryListString }}</b> de la part de&nbsp;<b>{{ proxy_received_item.giver.memberNumberWithBeneficiaryListString }}</b></div>
{% else %}
<div><b>{{ proxy_received_item.owner.membership.memberNumberWithBeneficiaryListString }}</b> accepte une procuration. <a href="{{ path("event_proxy_lite_remove",{'event':event.id,'proxy':proxy_received_item.id}) }}" class="red-text">X</a></div>
{% endif %}
{% endfor %}
{% if (proxy_given is null) and (proxy_received|length == 0) %}
<a href="{{ path("event_proxy_give",{'id':event.id}) }}" class="btn purple hide-on-small-only" title="Je ne peux pas venir ? je fais une procuration">
{% endfor %}
{% if (proxy_given is null) and (proxy_received|length == 0) %}
{% if event.isPast %}
<button class="btn" disabled>Événement passé</button>
{% else %}
<a href="{{ path("event_proxy_give",{'id':event.id}) }}" class="btn purple" title="Je ne peux pas venir ? je fais une procuration">
Je ne peux pas venir ? je fais une procuration
</a>
{% if event.anonymousProxy %}
<a href="{{ path("event_proxy_take",{'id':event.id}) }}" class="btn green hide-on-small-only" title="Je viens, j'accepte une procuration">
<a href="{{ path("event_proxy_take",{'id':event.id}) }}" class="btn green" title="Je viens, j'accepte une procuration">
Je viens, j'accepte une procuration
</a>
{% endif %}
Expand All @@ -62,14 +86,4 @@
{% endif %}
{% endif %}
{% endif %}
{% if from_admin %}
<div class="right">
<a href="{{ path("admin_event_edit", {'id': event.id}) }}"><i class="material-icons left">edit</i>Editer</a>
</div>
{% endif %}
{% if not only_action %}
<div class="right">
<a href="{{ path("event_detail", {'id': event.id}) }}" class="{% if not from_admin %}btn blue{% endif %}" {% if from_admin %}target="_blank"{% endif %}><i class="material-icons left">visibility</i>Voir</a>
</div>
{% endif %}
</div>
4 changes: 4 additions & 0 deletions app/Resources/views/admin/event/proxy/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
<a href="{{ path('homepage') }}"><i class="material-icons">home</i></a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin') }}"><i class="material-icons">build</i>&nbsp;Administration</a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin_event_index') }}"><i class="material-icons">event</i>&nbsp;Événements</a><i class="material-icons">chevron_right</i>
<i class="material-icons">event</i>&nbsp;{{ event.title }}<i class="material-icons">chevron_right</i>
<a href="{{ path('admin_event_proxies_list', {'id': event.id}) }}"><i class="material-icons">list</i>&nbsp;Liste des procurations</a><i class="material-icons">chevron_right</i>
<i class="material-icons">edit</i>&nbsp;Editer une procuration
{% endblock %}

{% block content %}
<h4>Editer une procuration</h4>

{% include "admin/event/_partial/card.html.twig" with { event: event, only_header: true } %}

{{ form_start(form) }}
{{ form_widget(form) }}
<div>
Expand Down
8 changes: 1 addition & 7 deletions app/Resources/views/admin/event/proxy/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,7 @@
</td>
{% if is_granted("ROLE_SUPER_ADMIN") %}
<td>
<a href="{{ path("admin_proxy_edit",{'id':proxy.id}) }}"><i class="material-icons">edit</i>Editer</a>
{{ form_start(delete_forms[proxy.id]) }}
{{ form_widget(delete_forms[proxy.id]) }}
<div>
<button type="submit" class="btn btn-small waves-effect waves-light red">Supprimer</button>
</div>
{{ form_end(delete_forms[proxy.id]) }}
<a href="{{ path("admin_event_proxy_edit",{'id':proxy.event.id, 'proxy':proxy.id}) }}"><i class="material-icons">edit</i>Editer</a>
</td>
{% endif %}
</tr>
Expand Down
66 changes: 28 additions & 38 deletions src/AppBundle/Controller/AdminEventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,9 @@ public function listProxiesAction()

$proxies = $em->getRepository('AppBundle:Proxy')->findAll();

$delete_forms = array();
foreach ($proxies as $proxy){
$delete_forms[$proxy->getId()] = $this->getProxyDeleteForm($proxy)->createView();
}

return $this->render('admin/event/proxy/list.html.twig', array(
'proxies' => $proxies,
'delete_forms' => $delete_forms,
'event' => null,
));
}
Expand All @@ -257,49 +252,19 @@ public function listEventProxiesAction(Event $event, Request $request)
{
$proxies = $event->getProxies();

$delete_forms = array();
foreach ($proxies as $proxy) {
$delete_forms[$proxy->getId()] = $this->getProxyDeleteForm($proxy)->createView();
}

return $this->render('admin/event/proxy/list.html.twig', array(
'proxies' => $proxies,
'delete_forms' => $delete_forms,
'event' => $event,
));
}

/**
* Proxy delete
*
* @Route("/proxies/{id}", name="admin_proxy_delete", methods={"DELETE"})
* @Security("has_role('ROLE_SUPER_ADMIN')")
*/
public function deleteProxyAction(Request $request, Proxy $proxy)
{
$session = new Session();
$em = $this->getDoctrine()->getManager();

$form = $this->getProxyDeleteForm($proxy);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$em->remove($proxy);
$em->flush();

$session->getFlashBag()->add('success', 'La procuration a bien été supprimée !');
}

return $this->redirectToRoute('event_proxies_list', array('id'=>$proxy->getEvent()->getId()));
}

/**
* Proxy edit
*
* @Route("/proxies/{id}", name="admin_proxy_edit", methods={"GET","POST"})
* @Route("/{id}/proxies/{proxy}", name="admin_event_proxy_edit", methods={"GET","POST"})
* @Security("has_role('ROLE_SUPER_ADMIN')")
*/
public function editProxyAction(Request $request, Proxy $proxy, \Swift_Mailer $mailer)
public function editEventProxyAction(Event $event, Proxy $proxy, Request $request, \Swift_Mailer $mailer)
{
$session = new Session();
$em = $this->getDoctrine()->getManager();
Expand Down Expand Up @@ -370,11 +335,36 @@ public function editProxyAction(Request $request, Proxy $proxy, \Swift_Mailer $m
}

return $this->render('admin/event/proxy/edit.html.twig', array(
'event' => $event,
'form' => $form->createView(),
'delete_form' => $this->getProxyDeleteForm($proxy)->createView(),
));
}

/**
* Proxy delete
*
* @Route("/{id}/proxies/{proxy}", name="admin_event_proxy_delete", methods={"DELETE"})
* @Security("has_role('ROLE_SUPER_ADMIN')")
*/
public function deleteEventProxyAction(Event $event, Proxy $proxy, Request $request)
{
$session = new Session();
$em = $this->getDoctrine()->getManager();

$form = $this->getProxyDeleteForm($proxy);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$em->remove($proxy);
$em->flush();

$session->getFlashBag()->add('success', 'La procuration a bien été supprimée !');
}

return $this->redirectToRoute('admin_event_proxies_list', array('id' => $proxy->getEvent()->getId()));
}


/**
* Generate a printable list Signatures list.
Expand Down Expand Up @@ -492,7 +482,7 @@ protected function getDeleteForm(Event $event)
protected function getProxyDeleteForm(Proxy $proxy)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('admin_proxy_delete', array('id' => $proxy->getId())))
->setAction($this->generateUrl('admin_event_proxy_delete', array('id' => $proxy->getEvent()->getId(), 'proxy' => $proxy->getId())))
->setMethod('DELETE')
->getForm();
}
Expand Down
10 changes: 8 additions & 2 deletions src/AppBundle/Controller/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ public function giveProxyAction(Event $event, Request $request, \Swift_Mailer $m
return $this->redirectToRoute('homepage');
}

// check if event is past
if ($event->getIsPast()) {
$session->getFlashBag()->add('error', 'Événement passé');
return $this->redirectToRoute('homepage');
}

// default proxy form
$form = $this->createFormBuilder()
->setAction($this->generateUrl('event_proxy_give', array('id' => $event->getId())))
Expand Down Expand Up @@ -342,10 +348,10 @@ function($b) use ($min_time_count) { return $b->getMembership()->getShiftTimeCou
/**
* Proxy remove
*
* @Route("/{event}/proxy/remove/{proxy}", name="event_proxy_lite_remove", methods={"GET"})
* @Route("/{id}/proxy/{proxy}/remove", name="event_proxy_lite_delete", methods={"GET"})
* @Security("has_role('ROLE_USER')")
*/
public function removeProxyLiteAction(Event $event, Proxy $proxy, Request $request)
public function deleteProxyLiteAction(Event $event, Proxy $proxy, Request $request)
{
$session = new Session();
$em = $this->getDoctrine()->getManager();
Expand Down
9 changes: 9 additions & 0 deletions src/AppBundle/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ public function getIsOngoing()
return ($this->date < $now) && $this->end && ($this->end > $now);
}

/**
* @return boolean
*/
public function getIsPast()
{
$now = new \DateTime('now');
return ($this->date < $now && !$this->end) || ($this->date < $now && $this->end < $now);
}

/**
* Set description
*
Expand Down

0 comments on commit 1f797d3

Please sign in to comment.