mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-24 23:55:02 +00:00
Improve assignee handling and task assignment logic
- Added `hasAssigneeChanged` method for detecting assignee change - Updated `onTaskAssigned` logic to trigger only on assignee change
This commit is contained in:
@@ -13,7 +13,6 @@ namespace Chill\TaskBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\MainBundle\Serializer\Model\Counter;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
||||
@@ -49,7 +48,6 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
final class SingleTaskController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CenterResolverDispatcherInterface $centerResolverDispatcher,
|
||||
private readonly PaginatorFactory $paginatorFactory,
|
||||
private readonly SingleTaskAclAwareRepositoryInterface $singleTaskAclAwareRepository,
|
||||
private readonly TranslatorInterface $translator,
|
||||
@@ -170,6 +168,9 @@ final class SingleTaskController extends AbstractController
|
||||
->setForm($this->setCreateForm($task, TaskVoter::UPDATE));
|
||||
$this->eventDispatcher->dispatch($event, UIEvent::EDIT_FORM);
|
||||
|
||||
// To keep track of specific assignee change
|
||||
$initialAssignee = $task->getAssignee();
|
||||
|
||||
$form = $event->getForm();
|
||||
|
||||
$form->handleRequest($request);
|
||||
@@ -179,6 +180,13 @@ final class SingleTaskController extends AbstractController
|
||||
$em = $this->managerRegistry->getManager();
|
||||
$em->persist($task);
|
||||
|
||||
if (null !== $task->getAssignee()) {
|
||||
$this->eventDispatcher->dispatch(
|
||||
new AssignTaskEvent($task, $initialAssignee),
|
||||
AssignTaskEvent::PERSIST
|
||||
);
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator
|
||||
@@ -528,7 +536,7 @@ final class SingleTaskController extends AbstractController
|
||||
|
||||
if (null !== $task->getAssignee()) {
|
||||
$this->eventDispatcher->dispatch(
|
||||
new AssignTaskEvent($task, $user),
|
||||
new AssignTaskEvent($task),
|
||||
AssignTaskEvent::PERSIST
|
||||
);
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ class AssignTaskEvent extends Event
|
||||
final public const PERSIST = 'chill_task.assign_task';
|
||||
public function __construct(
|
||||
private readonly SingleTask $task,
|
||||
private readonly User $assignedUser,
|
||||
private readonly User $initialAssignee,
|
||||
) {}
|
||||
|
||||
public function getTask(): SingleTask
|
||||
@@ -28,8 +28,13 @@ class AssignTaskEvent extends Event
|
||||
return $this->task;
|
||||
}
|
||||
|
||||
public function getAssignedUser(): User
|
||||
public function getInitialAssignee(): User
|
||||
{
|
||||
return $this->assignedUser;
|
||||
return $this->initialAssignee;
|
||||
}
|
||||
|
||||
public function hasAssigneeChanged(): bool
|
||||
{
|
||||
return $this->initialAssignee !== $this->task->getAssignee();
|
||||
}
|
||||
}
|
||||
|
@@ -33,13 +33,16 @@ readonly class TaskAssignEventSubscriber implements EventSubscriberInterface
|
||||
|
||||
/**
|
||||
* Send a notification when a user is assigned to a task.
|
||||
*
|
||||
* The notification will be sent to the newly assigned user
|
||||
* Only triggers when the assignee actually changes.
|
||||
*/
|
||||
public function onTaskAssigned(AssignTaskEvent $event): void
|
||||
{
|
||||
if (!$event->hasAssigneeChanged()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$task = $event->getTask();
|
||||
$assignedUser = $event->getAssignedUser();
|
||||
$assignedUser = $task->getAssignee();
|
||||
|
||||
$title = $task->getTitle();
|
||||
|
||||
|
Reference in New Issue
Block a user