Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Visites] Notifications aux autres partenaires affectés #2565

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/EventSubscriber/InterventionAbortedSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function onInterventionAborted(Event $event): void
suivi: $suivi,
currentUser: $currentUser,
notificationMailerType: NotificationMailerType::TYPE_VISITE_ABORTED_TO_PARTNER,
notifyOtherAffectedPartners: true,
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/EventSubscriber/InterventionCanceledSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function onInterventionCanceled(Event $event): void
suivi: $suivi,
currentUser: $currentUser,
notificationMailerType: null,
notifyOtherAffectedPartners: true,
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/EventSubscriber/InterventionConfirmedSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function onInterventionConfirmed(Event $event): void
suivi: $suivi,
currentUser: $currentUser,
notificationMailerType: NotificationMailerType::TYPE_VISITE_CONFIRMED_TO_PARTNER,
notifyOtherAffectedPartners: true,
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/EventSubscriber/InterventionCreatedSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function onInterventionCreated(InterventionCreatedEvent $event): void
suivi: $suivi,
currentUser: $event->getUser(),
notificationMailerType: null,
notifyOtherAffectedPartners: true,
hmeneuvrier marked this conversation as resolved.
Show resolved Hide resolved
);
}

Expand Down
1 change: 1 addition & 0 deletions src/EventSubscriber/InterventionRescheduledSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function onInterventionRescheduled(InterventionRescheduledEvent $event):
suivi: $suivi,
currentUser: $event->getUser(),
notificationMailerType: null,
notifyOtherAffectedPartners: true,
);
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/Manager/SignalementManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Dto\Request\Signalement\SituationFoyerRequest;
use App\Dto\SignalementAffectationListView;
use App\Entity\Affectation;
use App\Entity\Enum\AffectationStatus;
use App\Entity\Enum\MotifCloture;
use App\Entity\Enum\ProfileDeclarant;
use App\Entity\Enum\ProprioType;
Expand Down Expand Up @@ -261,6 +262,23 @@ public function findEmailsAffectedToSignalement(Signalement $signalement): array
return array_merge($sendTo, $partnersEmail);
}

public function findUsersAffectedToSignalement(
Signalement $signalement,
AffectationStatus $statusAffectation,
Partner $partnerToExclude
): array {
$list = [];
$affectations = $signalement->getAffectations();
foreach ($affectations as $affectation) {
$partner = $affectation->getPartner();
if ((!$partnerToExclude || $partnerToExclude != $partner) && $affectation->getStatut() === $statusAffectation->value) {
$list = array_merge($list, $partner->getUsers()->toArray());
}
}

return array_unique($list, \SORT_REGULAR);
}

public function updateFromSignalementQualification(
SignalementQualification $signalementQualification,
QualificationNDERequest $qualificationNDERequest
Expand Down
15 changes: 14 additions & 1 deletion src/Service/Signalement/VisiteNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace App\Service\Signalement;

use App\Entity\Affectation;
use App\Entity\Enum\AffectationStatus;
use App\Entity\Enum\Qualification;
use App\Entity\Intervention;
use App\Entity\Suivi;
use App\Entity\User;
use App\Factory\NotificationFactory;
use App\Factory\SuiviFactory;
use App\Manager\SignalementManager;
use App\Manager\SuiviManager;
use App\Repository\UserRepository;
use App\Service\Mailer\NotificationMail;
Expand All @@ -21,6 +23,7 @@ class VisiteNotifier
{
public function __construct(
private EntityManagerInterface $entityManager,
private SignalementManager $signalementManager,
private SuiviFactory $suiviFactory,
private SuiviManager $suiviManager,
private NotificationFactory $notificationFactory,
Expand Down Expand Up @@ -53,16 +56,26 @@ public function notifyAgents(
?NotificationMailerType $notificationMailerType,
bool $notifyAdminTerritory = true,
?Affectation $affectation = null,
bool $notifyOtherAffectedPartners = false,
): void {
if ($intervention) {
$listUsersPartner = $intervention->getPartner() && $intervention->getPartner() != $currentUser?->getPartner() ?
$listUsersToNotify = [];
$listUsersPartner = $intervention->getPartner() && $intervention->getPartner() != $currentUser?->getPartner() && !$notifyOtherAffectedPartners ?
$intervention->getPartner()->getUsers()->toArray() : [];
if ($notifyAdminTerritory) {
$listUsersTerritoryAdmin = $this->userRepository->findActiveTerritoryAdmins($intervention->getSignalement()->getTerritory(), $intervention->getSignalement()->getInseeOccupant());
$listUsersToNotify = array_unique(array_merge($listUsersTerritoryAdmin, $listUsersPartner), \SORT_REGULAR);
} else {
$listUsersToNotify = $listUsersPartner;
}
if ($notifyOtherAffectedPartners) {
$listAffected = $this->signalementManager->findUsersAffectedToSignalement(
$intervention->getSignalement(),
AffectationStatus::STATUS_ACCEPTED,
$intervention->getPartner()
);
$listUsersToNotify = array_unique(array_merge($listUsersToNotify, $listAffected), \SORT_REGULAR);
}
} else {
$listUsersToNotify = $affectation->getPartner()->getUsers();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ public function testAddPastVisiteNotDone(): void
);

$this->assertResponseRedirects('/bo/signalements/'.$signalement->getUuid());
$this->assertEmailCount(3);
$this->assertEmailCount(2);
}
}
2 changes: 1 addition & 1 deletion tests/Functional/Manager/InterventionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testCreatePastVisiteFromRequest(): void
$intervention->getConcludeProcedure()
));

$this->assertEmailCount(3);
$this->assertEmailCount(2);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/Functional/Service/Signalement/VisiteNotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Entity\Signalement;
use App\Factory\NotificationFactory;
use App\Factory\SuiviFactory;
use App\Manager\SignalementManager;
use App\Manager\SuiviManager;
use App\Repository\SignalementRepository;
use App\Repository\UserRepository;
Expand All @@ -22,6 +23,7 @@ protected function setUp(): void
{
$kernel = self::bootKernel();
$entityManager = $kernel->getContainer()->get('doctrine')->getManager();
$signalementManager = static::getContainer()->get(SignalementManager::class);
$suiviFactory = static::getContainer()->get(SuiviFactory::class);
$suiviManager = static::getContainer()->get(SuiviManager::class);
$notificationFactory = static::getContainer()->get(NotificationFactory::class);
Expand All @@ -30,6 +32,7 @@ protected function setUp(): void

$this->visiteNotifier = new VisiteNotifier(
$entityManager,
$signalementManager,
$suiviFactory,
$suiviManager,
$notificationFactory,
Expand Down
Loading