Skip to content

Commit

Permalink
[VoteAg] allow to create Vote election (#10893)
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano authored Oct 21, 2024
1 parent 344c968 commit 15ed82f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/Entity/VotingPlatform/Designation/Designation.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Designation implements EntityAdministratorBlameableInterface, EntityAdhere
#[ORM\Column]
private $type;

#[Assert\Expression('!this.isConsultationType() or value', groups: ['api_designation_write', 'api_designation_write_limited'])]
#[Assert\Expression('!(this.isConsultationType() or this.isVoteType()) or value', groups: ['api_designation_write', 'api_designation_write_limited'])]
#[Groups(['designation_read', 'designation_write'])]
#[ORM\Column(type: 'smallint', nullable: true)]
public ?int $targetYear = null;
Expand Down Expand Up @@ -236,7 +236,7 @@ class Designation implements EntityAdministratorBlameableInterface, EntityAdhere
#[ORM\Column(type: 'boolean')]
private bool $isBlankVoteEnabled = true;

#[Assert\Expression('!(this.isLocalPollType() || this.isConsultationType()) or value', message: 'Vous devez préciser le questionnaire qui sera utilisé pour cette élection.', groups: ['Admin_creation', 'api_designation_write'])]
#[Assert\Expression('!(this.isLocalPollType() or this.isConsultationType() or this.isVoteType()) or value', message: 'Vous devez préciser le questionnaire qui sera utilisé pour cette élection.', groups: ['Admin_creation', 'api_designation_write'])]
#[Assert\Valid(groups: ['api_designation_write'])]
#[ORM\ManyToOne(targetEntity: Poll::class, cascade: ['persist'])]
public ?Poll $poll = null;
Expand Down Expand Up @@ -668,6 +668,7 @@ public function isDenominationEditable(): bool
!$this->isLocalElectionTypes()
&& !$this->isCommitteeSupervisorType()
&& !$this->isConsultationType()
&& !$this->isVoteType()
&& !$this->isTerritorialAssemblyType();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Normalizer/DesignationDenormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function denormalize($data, string $class, ?string $format = null, array
if ($designation->getCandidacyEndDate() !== $voteDate = $designation->getVoteStartDate()) {
$designation->setCandidacyEndDate($voteDate);
}
} elseif ($designation->isConsultationType()) {
} elseif ($designation->isConsultationType() || $designation->isVoteType()) {
$designation->alertTitle = $designation->alertTitle ?: $designation->getTitle();
$designation->alertCtaLabel = $designation->alertCtaLabel ?: 'Voir';
$designation->alertDescription = $designation->alertDescription ?: (new UnicodeString($designation->getDescription() ?? ''))->truncate(200, '', false);
Expand Down
10 changes: 6 additions & 4 deletions src/Repository/AdherentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -1322,13 +1322,15 @@ public function findAllForConsultation(int $minYear, array $zones): array
->setParameter('status', Adherent::ENABLED)
;

$condition = new Orx();

foreach (range($minYear, date('Y')) as $key => $year) {
$qb
->orWhere('a.tags LIKE :tag'.$key)
->setParameter('tag'.$key, '%'.TagEnum::getAdherentYearTag($year).'%')
;
$condition->add('a.tags LIKE :tag'.$key);
$qb->setParameter('tag'.$key, '%'.TagEnum::getAdherentYearTag($year).'%');
}

$qb->andWhere($condition);

$this->withGeoZones(
$zones,
$qb,
Expand Down
5 changes: 1 addition & 4 deletions src/Repository/VotingPlatform/DesignationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,7 @@ public function findAllActiveForAdherent(Adherent $adherent, array $types = [],
false
);

$conditions->add(
\sprintf('(designation.electionCreationDate IS NULL OR designation.electionCreationDate > :adhesion_date) AND designation.id IN (%s)', $zoneQueryBuilder->getDQL())
);
$queryBuilder->setParameter('adhesion_date', $adherent->getRegisteredAt());
$conditions->add(\sprintf('designation.id IN (%s)', $zoneQueryBuilder->getDQL()));
}

$votingPlatformElectionQueryBuilder = $this->getEntityManager()->createQueryBuilder()
Expand Down
4 changes: 2 additions & 2 deletions src/Security/Voter/VotingPlatformAbleToVoteVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function doVoteOnAttribute(string $attribute, Adherent $adherent, $sub
return false;
}

if ($designation->isConsultationType()) {
if ($designation->isConsultationType() || $designation->isVoteType()) {
if ($designation->targetYear) {
$foundTargetTag = false;
foreach (range($designation->targetYear, date('Y')) as $year) {
Expand Down Expand Up @@ -76,7 +76,7 @@ protected function doVoteOnAttribute(string $attribute, Adherent $adherent, $sub

if (!$adherentIsInVotersList) {
// Allow to vote adherent who are not on the list for CONSULTATION election
if ($designation->isConsultationType()) {
if ($designation->isConsultationType() || $designation->isVoteType()) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/VotingPlatform/Notifier/ElectionNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private function sendNotification(int $notification, Election $election, callabl

$this->batchSendEmail($getRecipientsCallback, $createMessageCallback);

$election->markSentNotification(Designation::NOTIFICATION_VOTE_OPENED);
$election->markSentNotification($notification);
$this->entityManager->flush();
}

Expand Down

0 comments on commit 15ed82f

Please sign in to comment.