Skip to content

Commit

Permalink
fix tests with fixtures #3610
Browse files Browse the repository at this point in the history
  • Loading branch information
emilschn committed Jan 30, 2025
1 parent 278d57c commit d347164
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/EventSubscriber/SuiviCreatedSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ public function onSuiviCreated(SuiviCreatedEvent $event): void
}

if (Signalement::STATUS_DRAFT === $suivi->getSignalement()->getStatut()
|| Signalement::STATUS_CLOSED === $suivi->getSignalement()->getStatut()
|| Signalement::STATUS_ARCHIVED === $suivi->getSignalement()->getStatut()) {
return;
}

if (Suivi::CONTEXT_NOTIFY_USAGER_ONLY !== $suivi->getContext()) {
$this->notificationAndMailSender->sendNewSuiviToAdminsAndPartners($suivi);
$this->notificationAndMailSender->sendNewSuiviToAdminsAndPartners(
suivi: $suivi,
sendEmail: (Signalement::STATUS_CLOSED !== $suivi->getSignalement()->getStatut())
);
}

if ($suivi->getSendMail()
Expand Down
19 changes: 10 additions & 9 deletions src/Service/NotificationAndMailSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public function sendNewAffectation(Affectation $affectation): void
$this->send($mailerType, $recipients);
}

public function sendNewSuiviToAdminsAndPartners(Suivi $suivi): void
public function sendNewSuiviToAdminsAndPartners(Suivi $suivi, bool $sendEmail): void
{
$mailerType = NotificationMailerType::TYPE_NEW_COMMENT_BACK;
$mailerType = $sendEmail ? NotificationMailerType::TYPE_NEW_COMMENT_BACK : null;
$this->suivi = $suivi;
$this->signalement = $suivi->getSignalement();
$territory = $this->signalement->getTerritory();
Expand Down Expand Up @@ -102,7 +102,7 @@ public function sendNewSuiviToUsagers(Suivi $suivi): void
}
}

private function send(NotificationMailerType $notificationMailerType, ArrayCollection $recipients, bool $isInAppNotificationCreated = false): void
private function send(?NotificationMailerType $notificationMailerType, ArrayCollection $recipients, bool $isInAppNotificationCreated = false): void
{
if ($isInAppNotificationCreated) {
foreach ($recipients as $user) {
Expand All @@ -113,7 +113,9 @@ private function send(NotificationMailerType $notificationMailerType, ArrayColle
$this->entityManager->flush();
}

$this->sendMail($recipients, $notificationMailerType);
if ($notificationMailerType) {
$this->sendMail($recipients, $notificationMailerType);
}
}

private function createInAppNotification($user): void
Expand Down Expand Up @@ -223,13 +225,12 @@ private function isUserNotified(Partner $partner, User $user): bool
// - the user must be active and not an admin
// - if entity is Affectation
// - if entity is Suivi: we check that the partner of the user is different from the partner of the user who created the suivi
// TODO: activate when suivi is out of ActivityListener
/*if ($entity instanceof Suivi) {
$suiviPartner = $entity->getCreatedBy()?->getPartnerInTerritory($entity->getSignalement()->getTerritory());
}*/
if (!empty($this->suivi)) {
$suiviPartner = $this->suivi->getCreatedBy()?->getPartnerInTerritory($this->suivi->getSignalement()->getTerritory());
}

return User::STATUS_ACTIVE === $user->getStatut()
&& !$user->isSuperAdmin() && !$user->isTerritoryAdmin()
&& (!empty($this->affectation)/* || ($entity->getCreatedBy() && $partner !== $suiviPartner) */);
&& (!empty($this->affectation) || ($this->suivi->getCreatedBy() && $partner !== $suiviPartner));

Check failure on line 234 in src/Service/NotificationAndMailSender.php

View workflow job for this annotation

GitHub Actions / Histologe (PHP 8.3)

Variable $suiviPartner might not be defined.
}
}

0 comments on commit d347164

Please sign in to comment.