Skip to content

Commit

Permalink
[Consultation] improve check of target
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano committed Oct 16, 2024
1 parent 4084ea5 commit 4834b33
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 14 deletions.
18 changes: 13 additions & 5 deletions features/api/designations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ Feature:
"description": "lorem ipsum...",
"target": [],
"fully_editable": true,
"created_at": "@string@.isDateTime()",
"questions": [],
"election_entity_identifier": "8c4b48ec-9290-47ae-a5db-d1cf2723e8b3",
"uuid": "@uuid@"
"uuid": "@uuid@",
"is_canceled": false
}
"""

Expand All @@ -125,7 +127,9 @@ Feature:
"questions": [],
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"election_entity_identifier": "5e00c264-1d4b-43b8-862e-29edc38389b3",
"uuid": "7fb0693e-1dad-44c6-984b-19e99603ea2c"
"uuid": "7fb0693e-1dad-44c6-984b-19e99603ea2c",
"is_canceled": false,
"created_at": "@string@.isDateTime()"
}
"""

Expand Down Expand Up @@ -162,7 +166,9 @@ Feature:
"questions": [],
"description": "lorem ipsum...",
"election_entity_identifier": "8c4b48ec-9290-47ae-a5db-d1cf2723e8b3",
"uuid": "6c7ca0c7-d656-47c3-a345-170fb43ffd1a"
"uuid": "6c7ca0c7-d656-47c3-a345-170fb43ffd1a",
"is_canceled": false,
"created_at": "@string@.isDateTime()"
}
"""

Expand Down Expand Up @@ -313,7 +319,7 @@ Feature:
Scenario Outline: As a grand user with local scope, I can cancel an election
Given I am logged with "<user>" via OAuth client "JeMengage Web" with scope "jemengage_admin"
When I send a "PUT" request to "/api/v3/designations/7fb0693e-1dad-44c6-984b-19e99603ea2c/cancel?scope=<scope>"
Then the response status code should be 204
Then the response status code should be 409
When I send a "GET" request to "/api/v3/designations/7fb0693e-1dad-44c6-984b-19e99603ea2c?scope=<scope>"
Then the response status code should be 200
And the response should be in JSON
Expand All @@ -330,7 +336,9 @@ Feature:
"questions": [],
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"election_entity_identifier": "5e00c264-1d4b-43b8-862e-29edc38389b3",
"uuid": "7fb0693e-1dad-44c6-984b-19e99603ea2c"
"uuid": "7fb0693e-1dad-44c6-984b-19e99603ea2c",
"is_canceled": false,
"created_at": "@string@.isDateTime()"
}
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public function __invoke(
EntityManagerInterface $entityManager,
ElectionRepository $electionRepository,
): Response {
if (!$designation->isFullyEditable()) {
return $this->json([
'status' => 'error',
'message' => 'Consultation is not editable',
], Response::HTTP_CONFLICT);
}

foreach ($electionRepository->findAllForDesignation($designation) as $election) {
$election->cancel(ElectionCancelReasonEnum::Manual);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/EntityTimestampableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait EntityTimestampableTrait
* @var \DateTimeInterface
*/
#[Gedmo\Timestampable(on: 'create')]
#[Groups(['jecoute_news_read', 'jecoute_news_read_dc', 'email_template_read', 'email_template_list_read', 'riposte_list_read', 'riposte_read', 'phoning_campaign_read', 'message_read_list', 'pap_building_history', 'pap_campaign_history_read_list', 'pap_campaign_replies_list', 'event_read', 'event_list_read', 'survey_list_dc', 'committee:list', 'document_read', 'national_event_inscription:webhook', 'procuration_request_read', 'procuration_request_list', 'procuration_proxy_list', 'procuration_matched_proxy', 'action_read', 'action_read_list', 'adherent_elect_read', 'tax_receipt:list', 'designation_list'])]
#[Groups(['jecoute_news_read', 'jecoute_news_read_dc', 'email_template_read', 'email_template_list_read', 'riposte_list_read', 'riposte_read', 'phoning_campaign_read', 'message_read_list', 'pap_building_history', 'pap_campaign_history_read_list', 'pap_campaign_replies_list', 'event_read', 'event_list_read', 'survey_list_dc', 'committee:list', 'document_read', 'national_event_inscription:webhook', 'procuration_request_read', 'procuration_request_list', 'procuration_proxy_list', 'procuration_matched_proxy', 'action_read', 'action_read_list', 'adherent_elect_read', 'tax_receipt:list', 'designation_list', 'designation_read'])]
#[ORM\Column(type: 'datetime')]
protected $createdAt;

Expand Down
8 changes: 8 additions & 0 deletions src/Entity/VotingPlatform/Designation/Designation.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ class Designation implements EntityAdministratorBlameableInterface, EntityAdhere
#[ORM\Column(type: 'uuid', nullable: true)]
private ?UuidInterface $electionEntityIdentifier = null;

#[Groups(['designation_read', 'designation_list'])]
#[ORM\Column(type: 'boolean', options: ['default' => false])]
private bool $isCanceled = false;

Expand Down Expand Up @@ -878,4 +879,11 @@ public function isLimitedResultsView(): bool
DesignationTypeEnum::COMMITTEE_SUPERVISOR,
], true);
}

public function getTargetYear(): ?int
{
$year = $this->target ? substr($this->target[0], -4) : null;

return $year > 2022 ? $year : date('Y') - 1;
}
}
10 changes: 9 additions & 1 deletion src/Security/Voter/VotingPlatformAbleToVoteVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Security\Voter;

use App\Adherent\Tag\TagEnum;
use App\Entity\Adherent;
use App\Entity\Geo\Zone;
use App\Entity\VotingPlatform\Election;
Expand Down Expand Up @@ -40,7 +41,14 @@ protected function doVoteOnAttribute(string $attribute, Adherent $adherent, $sub

if ($designation->isConsultationType()) {
if ($designation->target) {
if (!array_sum(array_map([$adherent, 'hasTag'], $designation->target))) {
$foundTargetTag = false;
foreach (range($designation->getTargetYear(), date('Y')) as $year) {
if ($adherent->hasTag(TagEnum::getAdherentYearTag($year))) {
$foundTargetTag = true;
break;
}
}
if (!$foundTargetTag) {
return false;
}
} elseif (!$adherent->hasActiveMembership()) {
Expand Down
5 changes: 2 additions & 3 deletions templates/voting_platform/_layout_consultation.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@

{% block vote_finish_action_block %}
<div class="b__nudge--bottom-large b__nudge--top-large">
<a href="{{ path('app_renaissance_adherent_space') }}"
class="btn btn--blue">
Retour à mon espace
<a href="{{ path('app_sas_election_index', {uuid: designation.uuid}) }}" class="btn btn--blue">
Retour
</a>
</div>
{% endblock %}
Expand Down
32 changes: 28 additions & 4 deletions templates/voting_platform/finish.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@
</svg>
</div>
</div>

<h1 class="text--larger b__nudge--bottom-large">
{% if designation.isExecutiveOfficeType() or designation.isLocalElectionTypes() or designation.isCommitteeSupervisorType() %}
Félicitations, votre bulletin est dans l'urne !
{% elseif designation.isPollType() %}
Félicitations, votre vote est bien enregistré !
{% elseif designation.isConsultationType() %}
Félicitations, votre participation a été enregistrée !
{% else %}
Félicitations, vos bulletins sont dans l'urne !
{% endif %}
Expand All @@ -51,6 +50,31 @@

{% block voting_platform_content %}
<div class="l__wrapper--600 text--center">
<p class="text--body text--dark">
{% if designation.isExecutiveOfficeType() or designation.isPollType() or designation.isCommitteeSupervisorType() %}
Votre bulletin a été anonymisé.<br/><br/>
Le numéro ci-dessous, connu de vous seul, est l'unique moyen de tracer votre
bulletin de votre choix au dépouillement. Retrouvez-le dans le détail des résultats.
{% elseif designation.isLocalElectionTypes() %}
Votre bulletin a été anonymisé.<br/><br/>
Le numéro ci-dessous, connu de vous seul, est l'unique moyen de tracer votre bulletin.
{% else %}
Vos bulletins ont été anonymisés.<br/><br/>
Le numéro ci-dessous, connu de vous seul, est l'unique moyen de tracer vos
bulletins de votre choix au dépouillement. Retrouvez-le dans le détail des résultats.
{% endif %}
</p>

<div class="b__nudge--bottom-large b__nudge--top-large">
<div class="text--on-white text--body inline-block space--20">{{ voter_key }}</div>
</div>

<p class="text--body text--smallest text--gray">
Attention. Une fois cette page fermée, vous ne pourrez retrouver le numéro anonyme de vos bulletins que dans le mail
de confirmation que vous venez de recevoir. Aucun lien entre vous et ce numéro n'étant enregistré, nous ne serons pas
en mesure de vous le redonner.
</p>

{{ block('vote_finish_action_block') }}
</div>
{% endblock %}
Expand All @@ -59,8 +83,8 @@
{{ parent() }}

<script type="text/javascript">
if (window.Kernel !== undefined) {
Kernel.onLoad(function () { addClass(dom('.envelope'), 'active'); });
if (window.Bootstrap !== undefined) {
Bootstrap.onLoad(function () { addClass(dom('.envelope'), 'active'); });
}
</script>
{% endblock %}

0 comments on commit 4834b33

Please sign in to comment.