feat(notification) : notifier les collaborateurs ajoutés à une tâche
This commit is contained in:
@@ -57,6 +57,22 @@ final class TaskNotificationListener
|
|||||||
$this->pending[] = ['user' => $new, 'type' => 'task_assigned', 'task' => $entity];
|
$this->pending[] = ['user' => $new, 'type' => 'task_assigned', 'task' => $entity];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ajout de collaborateur(s) (tâche nouvelle ou existante).
|
||||||
|
foreach ($uow->getScheduledCollectionUpdates() as $collection) {
|
||||||
|
$owner = $collection->getOwner();
|
||||||
|
if (!$owner instanceof Task) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ('collaborators' !== $collection->getMapping()->fieldName) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach ($collection->getInsertDiff() as $user) {
|
||||||
|
if ($user instanceof User && $user !== $actor) {
|
||||||
|
$this->pending[] = ['user' => $user, 'type' => 'task_collaborator_added', 'task' => $owner];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postFlush(PostFlushEventArgs $args): void
|
public function postFlush(PostFlushEventArgs $args): void
|
||||||
|
|||||||
@@ -115,6 +115,36 @@ class TaskNotificationListenerTest extends KernelTestCase
|
|||||||
self::assertCount(0, $this->notifications->findBy(['user' => $this->alice]));
|
self::assertCount(0, $this->notifications->findBy(['user' => $this->alice]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAddingCollaboratorCreatesNotification(): void
|
||||||
|
{
|
||||||
|
$this->loginAs($this->actor);
|
||||||
|
|
||||||
|
$task = $this->makeTask();
|
||||||
|
$this->em->persist($task);
|
||||||
|
$this->em->flush();
|
||||||
|
|
||||||
|
$task->addCollaborator($this->alice);
|
||||||
|
$this->em->flush();
|
||||||
|
|
||||||
|
$rows = $this->notifications->findBy(['user' => $this->alice]);
|
||||||
|
self::assertCount(1, $rows);
|
||||||
|
self::assertSame('task_collaborator_added', $rows[0]->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAddingSelfAsCollaboratorCreatesNoNotification(): void
|
||||||
|
{
|
||||||
|
$this->loginAs($this->actor);
|
||||||
|
|
||||||
|
$task = $this->makeTask();
|
||||||
|
$this->em->persist($task);
|
||||||
|
$this->em->flush();
|
||||||
|
|
||||||
|
$task->addCollaborator($this->actor);
|
||||||
|
$this->em->flush();
|
||||||
|
|
||||||
|
self::assertCount(0, $this->notifications->findBy(['user' => $this->actor]));
|
||||||
|
}
|
||||||
|
|
||||||
private function makeUser(string $prefix): User
|
private function makeUser(string $prefix): User
|
||||||
{
|
{
|
||||||
$user = new User();
|
$user = new User();
|
||||||
|
|||||||
Reference in New Issue
Block a user