feat: configurable recipient list for notifications of role nominations

This commit is contained in:
2026-09-16 09:21:04 +02:00
parent 6a8328a564
commit 5d7ffd7d58
5 changed files with 22 additions and 50 deletions
@@ -16,8 +16,8 @@ use Psr\Log\LoggerInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* The notification goes to the people who can act on it, and to nobody else: an account merely
* nominated for ROLE_ADMIN must not be told about other people's nominations.
* The notification goes to the addresses configured in config/services.yaml, and to nobody else:
* the audience does not follow whoever currently holds ROLE_ADMIN.
*/
class RoleNominationHandlerTest extends TestCase
{
@@ -31,14 +31,11 @@ class RoleNominationHandlerTest extends TestCase
private ?int $generatedReferenceType = null;
public function testMailsEveryAdministrator(): void
public function testMailsTheConfiguredRecipients(): void
{
$handler = $this->handler(
$this->user(7, '[email protected]'),
[
$this->user(1, '[email protected]', [Role::ADMIN]),
$this->user(2, '[email protected]', [Role::ADMIN]),
],
['[email protected]', '[email protected]'],
);
$handler(new RoleNominationMessage(7, [Role::ADMIN]));
@@ -57,14 +54,14 @@ class RoleNominationHandlerTest extends TestCase
public function testAMissingAccountIsANoOp(): void
{
$handler = $this->handler(null, [$this->user(1, '[email protected]', [Role::ADMIN])]);
$handler = $this->handler(null, ['[email protected]']);
$handler(new RoleNominationMessage(7, [Role::ADMIN]));
self::assertNull($this->sentOptions);
}
public function testWithoutAnAdministratorNothingIsSent(): void
public function testWithoutAConfiguredRecipientNothingIsSent(): void
{
$handler = $this->handler($this->user(7, '[email protected]'), []);
@@ -88,13 +85,12 @@ class RoleNominationHandlerTest extends TestCase
}
/**
* @param User[] $administrators
* @param string[] $recipients
*/
private function handler(?User $nominee, array $administrators): RoleNominationHandler
private function handler(?User $nominee, array $recipients): RoleNominationHandler
{
$userRepository = $this->createStub(UserRepository::class);
$userRepository->method('find')->willReturn($nominee);
$userRepository->method('findAdministrators')->willReturn($administrators);
$mailer = $this->createStub(Mailer::class);
$mailer
@@ -123,6 +119,7 @@ class RoleNominationHandlerTest extends TestCase
$mailer,
new RoleApprovalUrlGenerator($urlGenerator),
$this->createStub(LoggerInterface::class),
$recipients,
);
}
}