feat: copy the house managers of the selected houses on assignment mailings
This commit is contained in:
1 parent
2c51ddf86f
commit
f22d1f1199
17 files changed
+292
-23
No files matched your search
+18
-1
@@ -5,9 +5,11 @@ namespace App\Controller\Administrative\AssignmentMailing;
|
|||||||
use App\Controller\Traits\AuthenticatedUserTrait;
|
use App\Controller\Traits\AuthenticatedUserTrait;
|
||||||
use App\Email\MailBodyRenderer;
|
use App\Email\MailBodyRenderer;
|
||||||
use App\Entity\Upload;
|
use App\Entity\Upload;
|
||||||
|
use App\Entity\User;
|
||||||
use App\Form\AssignmentMailingAddType;
|
use App\Form\AssignmentMailingAddType;
|
||||||
use App\Form\AssignmentMailingType;
|
use App\Form\AssignmentMailingType;
|
||||||
use App\Model\AssignmentMailingDto;
|
use App\Model\AssignmentMailingDto;
|
||||||
|
use App\Model\TeamerMailingRecipientsDto;
|
||||||
use App\Service\Teamer\AssignmentMailingDraftHandler;
|
use App\Service\Teamer\AssignmentMailingDraftHandler;
|
||||||
use App\Service\Teamer\AssignmentMailingService;
|
use App\Service\Teamer\AssignmentMailingService;
|
||||||
use App\Service\Teamer\MailingAttachmentHandler;
|
use App\Service\Teamer\MailingAttachmentHandler;
|
||||||
@@ -81,8 +83,23 @@ abstract class AbstractAssignmentMailingController extends AbstractController
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'mailingDto' => $mailingDto,
|
'mailingDto' => $mailingDto,
|
||||||
'recipients' => $this->mailingService->resolveRecipients($mailingDto),
|
|
||||||
'addForm' => $this->createForm(AssignmentMailingAddType::class)->createView(),
|
'addForm' => $this->createForm(AssignmentMailingAddType::class)->createView(),
|
||||||
|
] + $this->recipientsContext($mailingDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The recipients and the house managers in CC, named on the compose page and in the
|
||||||
|
* confirmation.
|
||||||
|
*
|
||||||
|
* @return array{recipients: TeamerMailingRecipientsDto, houseManagers: User[]}
|
||||||
|
*/
|
||||||
|
protected function recipientsContext(AssignmentMailingDto $mailingDto): array
|
||||||
|
{
|
||||||
|
$recipients = $this->mailingService->resolveRecipients($mailingDto);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'recipients' => $recipients,
|
||||||
|
'houseManagers' => array_merge(...array_values($this->mailingService->resolveHouseManagerCc($mailingDto, $recipients))),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ class ConfirmController extends AbstractAssignmentMailingController
|
|||||||
'valid' => $form->isSubmitted() && $form->isValid(),
|
'valid' => $form->isSubmitted() && $form->isValid(),
|
||||||
'attachmentError' => $this->mailingService->validateAttachments($mailingDto),
|
'attachmentError' => $this->mailingService->validateAttachments($mailingDto),
|
||||||
'attachmentSize' => $this->mailingService->getAttachmentSize($mailingDto),
|
'attachmentSize' => $this->mailingService->getAttachmentSize($mailingDto),
|
||||||
'recipients' => $this->mailingService->resolveRecipients($mailingDto),
|
] + $this->recipientsContext($mailingDto) + $this->attachmentsContext($mailingDto));
|
||||||
] + $this->attachmentsContext($mailingDto));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,6 +104,11 @@ class Mailer
|
|||||||
$email->replyTo($config['reply_to']);
|
$email->replyTo($config['reply_to']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// on every mail of a multi-recipient 'to', like the rest of the mail
|
||||||
|
if ([] !== $config['cc']) {
|
||||||
|
$email->cc(...$config['cc']);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($config['attachments'] as $attachment) {
|
foreach ($config['attachments'] as $attachment) {
|
||||||
/* @var EmailAttachmentInterface $attachment */
|
/* @var EmailAttachmentInterface $attachment */
|
||||||
$attachment->attachTo($email);
|
$attachment->attachTo($email);
|
||||||
@@ -117,13 +122,14 @@ class Mailer
|
|||||||
public function send(TemplatedEmail $email): void
|
public function send(TemplatedEmail $email): void
|
||||||
{
|
{
|
||||||
$recipients = array_map(fn (Address $address) => $address->toString(), $email->getTo());
|
$recipients = array_map(fn (Address $address) => $address->toString(), $email->getTo());
|
||||||
|
$cc = array_map(fn (Address $address) => $address->toString(), $email->getCc());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->mailer->send($email);
|
$this->mailer->send($email);
|
||||||
$this->logger->info('Send email', [
|
$this->logger->info('Send email', [
|
||||||
'to' => $recipients,
|
'to' => $recipients,
|
||||||
'subject' => $email->getSubject(),
|
'subject' => $email->getSubject(),
|
||||||
]);
|
] + ([] !== $cc ? ['cc' => $cc] : []));
|
||||||
} catch (TransportExceptionInterface $e) {
|
} catch (TransportExceptionInterface $e) {
|
||||||
$this->logger->error('Email could not be sent', [
|
$this->logger->error('Email could not be sent', [
|
||||||
'to' => $recipients,
|
'to' => $recipients,
|
||||||
@@ -146,6 +152,7 @@ class Mailer
|
|||||||
'transport' => null,
|
'transport' => null,
|
||||||
'bus_transport' => null,
|
'bus_transport' => null,
|
||||||
'reply_to' => null,
|
'reply_to' => null,
|
||||||
|
'cc' => [],
|
||||||
])
|
])
|
||||||
->setRequired([
|
->setRequired([
|
||||||
'template',
|
'template',
|
||||||
@@ -159,6 +166,7 @@ class Mailer
|
|||||||
->setAllowedTypes('transport', ['null', 'string'])
|
->setAllowedTypes('transport', ['null', 'string'])
|
||||||
->setAllowedTypes('bus_transport', ['null', 'string'])
|
->setAllowedTypes('bus_transport', ['null', 'string'])
|
||||||
->setAllowedTypes('reply_to', ['null', 'string'])
|
->setAllowedTypes('reply_to', ['null', 'string'])
|
||||||
|
->setAllowedTypes('cc', 'string[]')
|
||||||
;
|
;
|
||||||
|
|
||||||
return $resolver->resolve($options);
|
return $resolver->resolve($options);
|
||||||
|
|||||||
@@ -19,11 +19,14 @@ use App\Model\TeamerMailingRecipientsDto;
|
|||||||
* With $listColleagues every mail ends with the names and addresses of the other recipients,
|
* With $listColleagues every mail ends with the names and addresses of the other recipients,
|
||||||
* taken from the same snapshot. $replyTo is decided when the mailing is queued, so a deploy
|
* taken from the same snapshot. $replyTo is decided when the mailing is queued, so a deploy
|
||||||
* that changes it does not reroute answers to a mailing already on its way.
|
* that changes it does not reroute answers to a mailing already on its way.
|
||||||
|
*
|
||||||
|
* A recipient's 'cc' holds the addresses that get their mail in copy - the house managers of an
|
||||||
|
* assignment mailing, each on one mail only, see AssignmentMailingService::resolveHouseManagerCc().
|
||||||
*/
|
*/
|
||||||
class SendTeamerMailing
|
class SendTeamerMailing
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param array<int, array{email: string, firstName: string, lastName: string, fullName: string}> $recipients
|
* @param array<int, array{email: string, firstName: string, lastName: string, fullName: string, cc?: list<string>}> $recipients
|
||||||
* @param array<int, array{path: string, name: string}> $attachments
|
* @param array<int, array{path: string, name: string}> $attachments
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@@ -38,6 +41,7 @@ class SendTeamerMailing
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<int, array{path: string, name: string}> $attachments
|
* @param array<int, array{path: string, name: string}> $attachments
|
||||||
|
* @param array<int, list<string>> $cc teamer id => addresses
|
||||||
*/
|
*/
|
||||||
public static function fromRecipients(
|
public static function fromRecipients(
|
||||||
string $subject,
|
string $subject,
|
||||||
@@ -46,6 +50,7 @@ class SendTeamerMailing
|
|||||||
array $attachments = [],
|
array $attachments = [],
|
||||||
bool $listColleagues = false,
|
bool $listColleagues = false,
|
||||||
?string $replyTo = null,
|
?string $replyTo = null,
|
||||||
|
array $cc = [],
|
||||||
): self {
|
): self {
|
||||||
$snapshot = [];
|
$snapshot = [];
|
||||||
|
|
||||||
@@ -60,6 +65,7 @@ class SendTeamerMailing
|
|||||||
'firstName' => $recipient->getFirstName(),
|
'firstName' => $recipient->getFirstName(),
|
||||||
'lastName' => $recipient->getLastName(),
|
'lastName' => $recipient->getLastName(),
|
||||||
'fullName' => $recipient->getFullName(),
|
'fullName' => $recipient->getFullName(),
|
||||||
|
'cc' => $cc[$recipient->getId()] ?? [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +83,7 @@ class SendTeamerMailing
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<int, array{email: string, firstName: string, lastName: string, fullName: string}>
|
* @return array<int, array{email: string, firstName: string, lastName: string, fullName: string, cc?: list<string>}>
|
||||||
*/
|
*/
|
||||||
public function getRecipients(): array
|
public function getRecipients(): array
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -122,13 +122,13 @@ class UserRepository extends ServiceEntityRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The house managers the nightly reminder may write to: not deleted and not blocked - a blocked
|
* The house managers still in office: not deleted and not blocked. The nightly reminder writes
|
||||||
* account cannot log in to do what it is reminded of. Hotel codes and muted notifications are
|
* to them (a blocked account cannot log in to do what it is reminded of) and an assignment
|
||||||
* the caller's to check.
|
* mailing puts them in CC. Hotel codes and muted notifications are the caller's to check.
|
||||||
*
|
*
|
||||||
* @return User[]
|
* @return User[]
|
||||||
*/
|
*/
|
||||||
public function findHouseManagersToRemind(): array
|
public function findActiveHouseManagers(): array
|
||||||
{
|
{
|
||||||
$qb = $this->createQueryBuilder('user');
|
$qb = $this->createQueryBuilder('user');
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class FeedbackReminderService
|
|||||||
$today = ($today ?? new \DateTimeImmutable('today'))->setTime(0, 0);
|
$today = ($today ?? new \DateTimeImmutable('today'))->setTime(0, 0);
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
|
||||||
foreach ($this->userRepository->findHouseManagersToRemind() as $houseManager) {
|
foreach ($this->userRepository->findActiveHouseManagers() as $houseManager) {
|
||||||
if (true === $houseManager->isMuteNotifications() || [] === $houseManager->getHotelCodes()) {
|
if (true === $houseManager->isMuteNotifications() || [] === $houseManager->getHotelCodes()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use App\Entity\User;
|
|||||||
use App\Message\SendTeamerMailing;
|
use App\Message\SendTeamerMailing;
|
||||||
use App\Model\AssignmentMailingDto;
|
use App\Model\AssignmentMailingDto;
|
||||||
use App\Model\TeamerMailingRecipientsDto;
|
use App\Model\TeamerMailingRecipientsDto;
|
||||||
|
use App\Repository\UserRepository;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Messenger\MessageBusInterface;
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
@@ -15,8 +16,8 @@ use Symfony\Component\Messenger\MessageBusInterface;
|
|||||||
/**
|
/**
|
||||||
* Sends a mailing to the teamers confirmed on a set of assignments. Recipients, placeholders and
|
* Sends a mailing to the teamers confirmed on a set of assignments. Recipients, placeholders and
|
||||||
* the fan-out in the worker are the teamer mailing's, see TeamerMailingService; what this adds is
|
* the fan-out in the worker are the teamer mailing's, see TeamerMailingService; what this adds is
|
||||||
* the attachments, the list of colleagues at the end of each mail and the Mailing record of what
|
* the attachments, the list of colleagues at the end of each mail, the house managers in CC and
|
||||||
* went out.
|
* the Mailing record of what went out.
|
||||||
*/
|
*/
|
||||||
class AssignmentMailingService
|
class AssignmentMailingService
|
||||||
{
|
{
|
||||||
@@ -26,6 +27,7 @@ class AssignmentMailingService
|
|||||||
private readonly EntityManagerInterface $entityManager,
|
private readonly EntityManagerInterface $entityManager,
|
||||||
private readonly MessageBusInterface $messageBus,
|
private readonly MessageBusInterface $messageBus,
|
||||||
private readonly LoggerInterface $logger,
|
private readonly LoggerInterface $logger,
|
||||||
|
private readonly UserRepository $userRepository,
|
||||||
private readonly string $assignmentMailingReplyTo,
|
private readonly string $assignmentMailingReplyTo,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
@@ -35,6 +37,73 @@ class AssignmentMailingService
|
|||||||
return $this->teamerMailingService->resolveAssignmentRecipients($mailingDto->getAssignments());
|
return $this->teamerMailingService->resolveAssignmentRecipients($mailingDto->getAssignments());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The house managers who get the mailing in CC, by the teamer whose mail carries them.
|
||||||
|
*
|
||||||
|
* Every house manager of a house on the selected assignments (User::hasHotelCodeMatch(), the
|
||||||
|
* rule that gives them access to the house's teamers) is in CC on exactly one mail: that of
|
||||||
|
* the first recipient confirmed on an assignment of their house, in the recipients' order.
|
||||||
|
* Muted notifications do not count, this is no notification. Left out is a house manager who
|
||||||
|
* gets the mailing anyway, as one of the teamers or under one of their addresses.
|
||||||
|
*
|
||||||
|
* @return array<int, User[]> teamer id => house managers
|
||||||
|
*/
|
||||||
|
public function resolveHouseManagerCc(AssignmentMailingDto $mailingDto, TeamerMailingRecipientsDto $recipients): array
|
||||||
|
{
|
||||||
|
$recipientEmails = [];
|
||||||
|
$hotelCodes = [];
|
||||||
|
|
||||||
|
foreach ($recipients->getEligible() as $recipient) {
|
||||||
|
$recipientEmails[] = mb_strtolower((string) $recipient->getEmail());
|
||||||
|
// in the recipients' order, which decides whose mail carries a house manager
|
||||||
|
$hotelCodes[$recipient->getId()] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($mailingDto->getAssignments() as $assignment) {
|
||||||
|
$hotelCode = (string) $assignment->getDestination()?->getHotelCode();
|
||||||
|
|
||||||
|
if ('' === $hotelCode) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($assignment->getConfirmedDispositions() as $disposition) {
|
||||||
|
$teamerId = $disposition->getTeamer()?->getId();
|
||||||
|
|
||||||
|
if (null !== $teamerId && isset($hotelCodes[$teamerId])) {
|
||||||
|
$hotelCodes[$teamerId][] = $hotelCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$cc = [];
|
||||||
|
|
||||||
|
foreach ($this->userRepository->findActiveHouseManagers() as $houseManager) {
|
||||||
|
$email = (string) $houseManager->getEmail();
|
||||||
|
$teamerId = $houseManager->getTeamer()?->getId();
|
||||||
|
|
||||||
|
if (
|
||||||
|
'' === trim($email)
|
||||||
|
|| in_array(mb_strtolower($email), $recipientEmails, true)
|
||||||
|
|| (null !== $teamerId && isset($hotelCodes[$teamerId]))
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($hotelCodes as $recipientId => $codes) {
|
||||||
|
foreach ($codes as $hotelCode) {
|
||||||
|
if ($houseManager->hasHotelCodeMatch($hotelCode)) {
|
||||||
|
$cc[$recipientId][] = $houseManager;
|
||||||
|
|
||||||
|
continue 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// in the recipients' order, as the compose page names them
|
||||||
|
return array_filter(array_replace(array_fill_keys(array_keys($hotelCodes), []), $cc));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The template's files plus the ones dropped for this mailing, in bytes.
|
* The template's files plus the ones dropped for this mailing, in bytes.
|
||||||
*/
|
*/
|
||||||
@@ -118,6 +187,11 @@ class AssignmentMailingService
|
|||||||
$this->entityManager->persist($mailing);
|
$this->entityManager->persist($mailing);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
$cc = array_map(
|
||||||
|
fn (array $houseManagers) => array_map(fn (User $houseManager) => (string) $houseManager->getEmail(), $houseManagers),
|
||||||
|
$this->resolveHouseManagerCc($mailingDto, $recipients)
|
||||||
|
);
|
||||||
|
|
||||||
$this->messageBus->dispatch(SendTeamerMailing::fromRecipients(
|
$this->messageBus->dispatch(SendTeamerMailing::fromRecipients(
|
||||||
(string) $mailingDto->getSubject(),
|
(string) $mailingDto->getSubject(),
|
||||||
(string) $mailingDto->getMessage(),
|
(string) $mailingDto->getMessage(),
|
||||||
@@ -125,7 +199,8 @@ class AssignmentMailingService
|
|||||||
$this->attachmentHandler->toMessageAttachments($attachments),
|
$this->attachmentHandler->toMessageAttachments($attachments),
|
||||||
listColleagues: true,
|
listColleagues: true,
|
||||||
// answers go to the travel management inbox, not to the app's sender address
|
// answers go to the travel management inbox, not to the app's sender address
|
||||||
replyTo: $this->assignmentMailingReplyTo
|
replyTo: $this->assignmentMailingReplyTo,
|
||||||
|
cc: $cc
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->logger->info('Send assignment mailing', [
|
$this->logger->info('Send assignment mailing', [
|
||||||
@@ -134,6 +209,7 @@ class AssignmentMailingService
|
|||||||
'assignment_ids' => $mailing->getAssignments()->map(fn ($assignment) => $assignment->getId())->toArray(),
|
'assignment_ids' => $mailing->getAssignments()->map(fn ($assignment) => $assignment->getId())->toArray(),
|
||||||
'attachments' => count($attachments),
|
'attachments' => count($attachments),
|
||||||
'recipients' => $mailing->getRecipientCount(),
|
'recipients' => $mailing->getRecipientCount(),
|
||||||
|
'house_managers_cc' => count($cc, COUNT_RECURSIVE) - count($cc),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $mailing;
|
return $mailing;
|
||||||
|
|||||||
@@ -133,7 +133,9 @@ class TeamerMailingService
|
|||||||
self::TRANSPORT,
|
self::TRANSPORT,
|
||||||
$this->mailingBusTransport,
|
$this->mailingBusTransport,
|
||||||
$mailing->listsColleagues() ? self::colleaguesOf($recipients, $index) : [],
|
$mailing->listsColleagues() ? self::colleaguesOf($recipients, $index) : [],
|
||||||
$mailing->getReplyTo()
|
$mailing->getReplyTo(),
|
||||||
|
// a mailing queued before the CC has none
|
||||||
|
$recipient['cc'] ?? []
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,6 +256,7 @@ class TeamerMailingService
|
|||||||
*
|
*
|
||||||
* @param EmailAttachmentInterface[] $attachments
|
* @param EmailAttachmentInterface[] $attachments
|
||||||
* @param array<int, array{fullName: string, email: string}> $colleagues
|
* @param array<int, array{fullName: string, email: string}> $colleagues
|
||||||
|
* @param list<string> $cc
|
||||||
*/
|
*/
|
||||||
private function sendTo(
|
private function sendTo(
|
||||||
string $email,
|
string $email,
|
||||||
@@ -264,6 +267,7 @@ class TeamerMailingService
|
|||||||
?string $busTransport = null,
|
?string $busTransport = null,
|
||||||
array $colleagues = [],
|
array $colleagues = [],
|
||||||
?string $replyTo = null,
|
?string $replyTo = null,
|
||||||
|
array $cc = [],
|
||||||
): void {
|
): void {
|
||||||
// $bodyHtml is already rendered and escaped mail HTML, see MailBodyRenderer -
|
// $bodyHtml is already rendered and escaped mail HTML, see MailBodyRenderer -
|
||||||
// email/teamer_mailing.html.twig prints it with |raw. The colleagues are plain values,
|
// email/teamer_mailing.html.twig prints it with |raw. The colleagues are plain values,
|
||||||
@@ -279,6 +283,7 @@ class TeamerMailingService
|
|||||||
'transport' => $transport,
|
'transport' => $transport,
|
||||||
'bus_transport' => $busTransport,
|
'bus_transport' => $busTransport,
|
||||||
'reply_to' => $replyTo,
|
'reply_to' => $replyTo,
|
||||||
|
'cc' => $cc,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,12 @@
|
|||||||
{{ recipients.eligible|map(recipient => recipient.fullName)|join(', ') }}
|
{{ recipients.eligible|map(recipient => recipient.fullName)|join(', ') }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if houseManagers is not empty %}
|
||||||
|
<div class="pt-2 text-sm">
|
||||||
|
<span class="font-bold">In Kopie (Hausleitung):</span>
|
||||||
|
{{ include('administrative/assignment_mailing/_house_managers.html.twig') }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<ul class="flex flex-col space-y-1 py-4">
|
<ul class="flex flex-col space-y-1 py-4">
|
||||||
{% for assignment in mailingDto.assignments %}
|
{% for assignment in mailingDto.assignments %}
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
{# A house manager without a name on their account is named by their address. #}
|
||||||
|
{{ houseManagers|map(houseManager => houseManager.fullName|trim ?: houseManager.email)|join(', ') }}
|
||||||
@@ -21,6 +21,9 @@
|
|||||||
<div class="pb-4">
|
<div class="pb-4">
|
||||||
Die Mail geht an <strong>{{ recipients.eligibleCount }}</strong> Teamer:innen auf
|
Die Mail geht an <strong>{{ recipients.eligibleCount }}</strong> Teamer:innen auf
|
||||||
{{ mailingDto.assignments|length }} {{ mailingDto.assignments|length == 1 ? 'Einsatz' : 'Einsätzen' }}.
|
{{ mailingDto.assignments|length }} {{ mailingDto.assignments|length == 1 ? 'Einsatz' : 'Einsätzen' }}.
|
||||||
|
{% if houseManagers is not empty %}
|
||||||
|
In Kopie geht sie an die Hausleitung: {{ include('administrative/assignment_mailing/_house_managers.html.twig') }}.
|
||||||
|
{% endif %}
|
||||||
Das lässt sich nicht zurücknehmen.
|
Das lässt sich nicht zurücknehmen.
|
||||||
</div>
|
</div>
|
||||||
<div class="p-4 bg-gray-50 border border-gray-200 rounded-md">
|
<div class="p-4 bg-gray-50 border border-gray-200 rounded-md">
|
||||||
|
|||||||
+101
-2
@@ -18,6 +18,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
use Symfony\Component\DomCrawler\Crawler;
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
use Symfony\Component\Mime\Address;
|
||||||
use Symfony\Component\Mime\Email;
|
use Symfony\Component\Mime\Email;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -254,6 +255,69 @@ class AssignmentMailingControllerTest extends WebTestCase
|
|||||||
$this->assertSame(['Anna Muster ([email protected])'], $this->colleaguesIn('[email protected]'));
|
$this->assertSame(['Anna Muster ([email protected])'], $this->colleaguesIn('[email protected]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Each house manager once per mailing, on the mail of the first recipient of their house -
|
||||||
|
* muted or not - and never one of another house or a blocked one.
|
||||||
|
*/
|
||||||
|
public function testHouseManagersAreInCcOnOneMailOfTheirHouse(): void
|
||||||
|
{
|
||||||
|
// codes of no real house: other tests leave house managers of real ones in db_test
|
||||||
|
$schwendi = $this->assignment('Schwendi', 'XQSWE');
|
||||||
|
$rotbach = $this->assignment('Rotbach', 'XQR');
|
||||||
|
$this->place($this->teamer('Anna'), $schwendi, Disposition::STATUS_CONFIRMED);
|
||||||
|
$this->place($this->teamer('Cem'), $schwendi, Disposition::STATUS_CONFIRMED);
|
||||||
|
$this->place($this->teamer('Dora'), $rotbach, Disposition::STATUS_CONFIRMED);
|
||||||
|
$this->houseManager('Greta', ['XQR']);
|
||||||
|
$this->houseManager('Hugo', ['XQS']);
|
||||||
|
$this->houseManager('Hanna', ['XQS'])->setMuteNotifications(true);
|
||||||
|
$this->houseManager('Paul', ['XQP']);
|
||||||
|
$this->houseManager('Dieter', ['XQS'])->setDisabledAt(new \DateTimeImmutable());
|
||||||
|
$this->login('ROLE_MANAGER');
|
||||||
|
|
||||||
|
$crawler = $this->startMailing($schwendi, $rotbach);
|
||||||
|
|
||||||
|
$this->assertStringContainsString(
|
||||||
|
'In Kopie (Hausleitung): Hugo Hausleitung, Hanna Hausleitung, Greta Hausleitung',
|
||||||
|
$crawler->filter('#mailing-assignments')->text()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->client->request('POST', self::COMPOSE_URL.'/send', [
|
||||||
|
'assignment_mailing' => $this->mailingFields($crawler, 'Treffpunkt', 'Hallo'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEmailCount(3);
|
||||||
|
$this->assertSame(['[email protected]', '[email protected]'], $this->ccIn('[email protected]'));
|
||||||
|
$this->assertSame([], $this->ccIn('[email protected]'));
|
||||||
|
$this->assertSame(['[email protected]'], $this->ccIn('[email protected]'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Placed on the travel as a teamer, or writing under the address of one, the house manager has
|
||||||
|
* the mail already.
|
||||||
|
*/
|
||||||
|
public function testAHouseManagerWhoIsARecipientIsNotInCc(): void
|
||||||
|
{
|
||||||
|
$assignment = $this->assignment('Schwendi', 'XQS');
|
||||||
|
$anna = $this->teamer('Anna');
|
||||||
|
$this->place($anna, $assignment, Disposition::STATUS_CONFIRMED);
|
||||||
|
$this->place($this->teamer('Cem'), $assignment, Disposition::STATUS_CONFIRMED);
|
||||||
|
$this->houseManager('Hugo', ['XQS'])->setTeamer($anna);
|
||||||
|
$this->houseManager('Hanna', ['XQS'])->setEmail('[email protected]');
|
||||||
|
$this->login('ROLE_MANAGER');
|
||||||
|
|
||||||
|
$crawler = $this->startMailing($assignment);
|
||||||
|
|
||||||
|
$this->assertStringNotContainsString('In Kopie', $crawler->filter('#mailing-assignments')->text());
|
||||||
|
|
||||||
|
$this->client->request('POST', self::COMPOSE_URL.'/send', [
|
||||||
|
'assignment_mailing' => $this->mailingFields($crawler, 'Treffpunkt', 'Hallo'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEmailCount(2);
|
||||||
|
$this->assertSame([], $this->ccIn('[email protected]'));
|
||||||
|
$this->assertSame([], $this->ccIn('[email protected]'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testColleagueNamesAreEscaped(): void
|
public function testColleagueNamesAreEscaped(): void
|
||||||
{
|
{
|
||||||
$assignment = $this->assignment('Schwendi');
|
$assignment = $this->assignment('Schwendi');
|
||||||
@@ -354,6 +418,22 @@ class AssignmentMailingControllerTest extends WebTestCase
|
|||||||
$this->fail(sprintf('No mail to %s', $to));
|
$this->fail(sprintf('No mail to %s', $to));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The CC addresses of the mail sent to the given address.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
private function ccIn(string $to): array
|
||||||
|
{
|
||||||
|
foreach ($this->getMailerMessages() as $message) {
|
||||||
|
if ($message instanceof Email && $to === $message->getTo()[0]->getAddress()) {
|
||||||
|
return array_map(fn (Address $address) => $address->getAddress(), $message->getCc());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->fail(sprintf('No mail to %s', $to));
|
||||||
|
}
|
||||||
|
|
||||||
private function startMailing(Assignment ...$assignments): Crawler
|
private function startMailing(Assignment ...$assignments): Crawler
|
||||||
{
|
{
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
@@ -399,12 +479,12 @@ class AssignmentMailingControllerTest extends WebTestCase
|
|||||||
$this->client->loginUser($user);
|
$this->client->loginUser($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function assignment(string $hotel): Assignment
|
private function assignment(string $hotel, string $hotelCode = 'DKI'): Assignment
|
||||||
{
|
{
|
||||||
$destination = (new Destination())
|
$destination = (new Destination())
|
||||||
->setProduct('Davos Klosters')
|
->setProduct('Davos Klosters')
|
||||||
->setHotel($hotel)
|
->setHotel($hotel)
|
||||||
->setHotelCode('DKI')
|
->setHotelCode($hotelCode)
|
||||||
->setHotelBusProId(1)
|
->setHotelBusProId(1)
|
||||||
->setCountry('CH')
|
->setCountry('CH')
|
||||||
->setDateFrom(new \DateTimeImmutable('+7 days'))
|
->setDateFrom(new \DateTimeImmutable('+7 days'))
|
||||||
@@ -424,6 +504,25 @@ class AssignmentMailingControllerTest extends WebTestCase
|
|||||||
return $assignment;
|
return $assignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string[] $hotelCodes
|
||||||
|
*/
|
||||||
|
private function houseManager(string $firstName, array $hotelCodes): User
|
||||||
|
{
|
||||||
|
$user = (new User())
|
||||||
|
->setFirstName($firstName)
|
||||||
|
->setLastName('Hausleitung')
|
||||||
|
->setEmail(strtolower($firstName).'[email protected]')
|
||||||
|
->setRoles(['ROLE_HOUSE_MANAGER'])
|
||||||
|
->setHotelCodes($hotelCodes)
|
||||||
|
->setBusProAddressId(1)
|
||||||
|
->setBusProPersonId(1)
|
||||||
|
;
|
||||||
|
$this->entityManager->persist($user);
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
private function teamer(string $firstName): Teamer
|
private function teamer(string $firstName): Teamer
|
||||||
{
|
{
|
||||||
$teamer = (new Teamer())
|
$teamer = (new Teamer())
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ class EmailTextMailRenderingTest extends KernelTestCase
|
|||||||
'transport' => null,
|
'transport' => null,
|
||||||
'bus_transport' => null,
|
'bus_transport' => null,
|
||||||
'reply_to' => null,
|
'reply_to' => null,
|
||||||
|
'cc' => [],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$html = $email->getHtmlBody();
|
$html = $email->getHtmlBody();
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ class MailerTest extends KernelTestCase
|
|||||||
'transport' => $transport,
|
'transport' => $transport,
|
||||||
'bus_transport' => null,
|
'bus_transport' => null,
|
||||||
'reply_to' => null,
|
'reply_to' => null,
|
||||||
|
'cc' => [],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ class HouseManagerReminderQueryTest extends KernelTestCase
|
|||||||
|
|
||||||
/** @var UserRepository $repository */
|
/** @var UserRepository $repository */
|
||||||
$repository = $this->entityManager->getRepository(User::class);
|
$repository = $this->entityManager->getRepository(User::class);
|
||||||
$reminded = $repository->findHouseManagersToRemind();
|
$reminded = $repository->findActiveHouseManagers();
|
||||||
|
|
||||||
$this->assertContains($active, $reminded);
|
$this->assertContains($active, $reminded);
|
||||||
$this->assertNotContains($blocked, $reminded);
|
$this->assertNotContains($blocked, $reminded);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class FeedbackReminderServiceTest extends TestCase
|
|||||||
{
|
{
|
||||||
$houseManager = $this->houseManager('[email protected]', ['DKI']);
|
$houseManager = $this->houseManager('[email protected]', ['DKI']);
|
||||||
|
|
||||||
$this->userRepository->method('findHouseManagersToRemind')->willReturn([$houseManager]);
|
$this->userRepository->method('findActiveHouseManagers')->willReturn([$houseManager]);
|
||||||
$this->destinationRepository
|
$this->destinationRepository
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('findPendingForHouseManager')
|
->method('findPendingForHouseManager')
|
||||||
@@ -66,7 +66,7 @@ class FeedbackReminderServiceTest extends TestCase
|
|||||||
|
|
||||||
public function testMutedHouseManagersAndThoseWithoutHotelCodesAreSkipped(): void
|
public function testMutedHouseManagersAndThoseWithoutHotelCodesAreSkipped(): void
|
||||||
{
|
{
|
||||||
$this->userRepository->method('findHouseManagersToRemind')->willReturn([
|
$this->userRepository->method('findActiveHouseManagers')->willReturn([
|
||||||
$this->houseManager('[email protected]', ['DKI'])->setMuteNotifications(true),
|
$this->houseManager('[email protected]', ['DKI'])->setMuteNotifications(true),
|
||||||
$this->houseManager('[email protected]', []),
|
$this->houseManager('[email protected]', []),
|
||||||
]);
|
]);
|
||||||
@@ -83,7 +83,7 @@ class FeedbackReminderServiceTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testNoMailOnANightNothingIsDue(): void
|
public function testNoMailOnANightNothingIsDue(): void
|
||||||
{
|
{
|
||||||
$this->userRepository->method('findHouseManagersToRemind')->willReturn([$this->houseManager('[email protected]', ['DKI'])]);
|
$this->userRepository->method('findActiveHouseManagers')->willReturn([$this->houseManager('[email protected]', ['DKI'])]);
|
||||||
$this->destinationRepository->method('findPendingForHouseManager')->willReturn([$this->row($this->travel(10))]);
|
$this->destinationRepository->method('findPendingForHouseManager')->willReturn([$this->row($this->travel(10))]);
|
||||||
$this->mailer->expects($this->never())->method('createAndSendEmail');
|
$this->mailer->expects($this->never())->method('createAndSendEmail');
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ class FeedbackReminderServiceTest extends TestCase
|
|||||||
$due = $this->travel(14);
|
$due = $this->travel(14);
|
||||||
$quiet = $this->travel(10);
|
$quiet = $this->travel(10);
|
||||||
|
|
||||||
$this->userRepository->method('findHouseManagersToRemind')->willReturn([$this->houseManager('[email protected]', ['DKI'])]);
|
$this->userRepository->method('findActiveHouseManagers')->willReturn([$this->houseManager('[email protected]', ['DKI'])]);
|
||||||
$this->destinationRepository->method('findPendingForHouseManager')->willReturn([$this->row($quiet), $this->row($due)]);
|
$this->destinationRepository->method('findPendingForHouseManager')->willReturn([$this->row($quiet), $this->row($due)]);
|
||||||
$this->mailer
|
$this->mailer
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
@@ -124,7 +124,7 @@ class FeedbackReminderServiceTest extends TestCase
|
|||||||
$untouched = $this->travel(3); // ended 2026-11-17
|
$untouched = $this->travel(3); // ended 2026-11-17
|
||||||
$submitted = $this->travel(1); // ended 2026-11-19
|
$submitted = $this->travel(1); // ended 2026-11-19
|
||||||
|
|
||||||
$this->userRepository->method('findHouseManagersToRemind')->willReturn([$this->houseManager('[email protected]', ['DKI'])]);
|
$this->userRepository->method('findActiveHouseManagers')->willReturn([$this->houseManager('[email protected]', ['DKI'])]);
|
||||||
$this->destinationRepository->method('findPendingForHouseManager')->willReturn([
|
$this->destinationRepository->method('findPendingForHouseManager')->willReturn([
|
||||||
$this->row($beforeGoLive, null, 2),
|
$this->row($beforeGoLive, null, 2),
|
||||||
$this->row($draft, 'draft', 0),
|
$this->row($draft, 'draft', 0),
|
||||||
|
|||||||
@@ -338,6 +338,52 @@ class TeamerMailingServiceTest extends TestCase
|
|||||||
$this->assertSame(['[email protected]', '[email protected]'], $replyTo);
|
$this->assertSame(['[email protected]', '[email protected]'], $replyTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSendMailingPutsEachRecipientsCcOnTheirMailOnly(): void
|
||||||
|
{
|
||||||
|
$cc = [];
|
||||||
|
$this->mailer
|
||||||
|
->expects($this->exactly(2))
|
||||||
|
->method('createAndSendEmail')
|
||||||
|
->willReturnCallback(function (array $context, array $options) use (&$cc): void {
|
||||||
|
$cc[$options['to']] = $options['cc'];
|
||||||
|
})
|
||||||
|
;
|
||||||
|
|
||||||
|
$anna = $this->createRecipient('Anna', 'Berg', '[email protected]');
|
||||||
|
$recipients = (new TeamerMailingRecipientsDto())
|
||||||
|
->addEligible($anna)
|
||||||
|
->addEligible($this->createRecipient('Bea', 'Ohm', '[email protected]'))
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->service->sendMailing(SendTeamerMailing::fromRecipients(
|
||||||
|
'Betreff',
|
||||||
|
'Nachricht',
|
||||||
|
$recipients,
|
||||||
|
cc: [$anna->getId() => ['[email protected]', '[email protected]']]
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertSame([
|
||||||
|
'[email protected]' => ['[email protected]', '[email protected]'],
|
||||||
|
'[email protected]' => [],
|
||||||
|
], $cc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAMailingQueuedWithoutTheCcSendsNone(): void
|
||||||
|
{
|
||||||
|
$this->mailer
|
||||||
|
->expects($this->once())
|
||||||
|
->method('createAndSendEmail')
|
||||||
|
->willReturnCallback(function (array $context, array $options): void {
|
||||||
|
$this->assertSame([], $options['cc']);
|
||||||
|
})
|
||||||
|
;
|
||||||
|
|
||||||
|
// the snapshot as it was queued before the 'cc' key existed
|
||||||
|
$this->service->sendMailing(new SendTeamerMailing('Betreff', 'Nachricht', [
|
||||||
|
['email' => '[email protected]', 'firstName' => 'Anna', 'lastName' => 'Berg', 'fullName' => 'Anna Berg'],
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A preview has to stay on the default relay and the default queue, or composing a
|
* A preview has to stay on the default relay and the default queue, or composing a
|
||||||
* mailing would wait on the same worker the mailing itself is queued behind.
|
* mailing would wait on the same worker the mailing itself is queued behind.
|
||||||
|
|||||||
Reference in new issue
Block a user