Add assignee changed notification event support
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Actions\Tickets;
|
||||
|
||||
use App\Actions\Notifications\BuildTicketAssigneeChangedPayload;
|
||||
use App\Actions\Notifications\TicketAssigneeChanged;
|
||||
use App\Actions\Tickets\Support\TicketAcceptanceCriteriaData;
|
||||
use App\Enums\TicketWorklogEntryType;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketFieldDefinition;
|
||||
use App\Models\TicketFieldValue;
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -15,6 +18,7 @@ use Illuminate\Support\Facades\DB;
|
||||
class UpdateProjectTicket
|
||||
{
|
||||
public function __construct(
|
||||
private readonly BuildTicketAssigneeChangedPayload $buildTicketAssigneeChangedPayload,
|
||||
private readonly CreateTicketWorklogEntry $createTicketWorklogEntry,
|
||||
private readonly SyncProjectTicketFieldValues $syncProjectTicketFieldValues,
|
||||
) {}
|
||||
@@ -67,6 +71,7 @@ class UpdateProjectTicket
|
||||
'parentTicket',
|
||||
'project',
|
||||
'ticketPriority',
|
||||
'ticketStatus.boardColumn',
|
||||
'ticketType',
|
||||
]);
|
||||
|
||||
@@ -96,6 +101,7 @@ class UpdateProjectTicket
|
||||
|
||||
$changes = [];
|
||||
$summaryLabels = [];
|
||||
$assigneeChange = null;
|
||||
|
||||
$this->trackScalarChange(
|
||||
$changes,
|
||||
@@ -173,13 +179,23 @@ class UpdateProjectTicket
|
||||
}
|
||||
|
||||
if ($ticket->assignee_user_id !== $ticketAttributes['assignee_user_id']) {
|
||||
$toAssigneeId = $ticketAttributes['assignee_user_id'];
|
||||
$toAssigneeName = $toAssigneeId === null
|
||||
? null
|
||||
: User::query()->find($toAssigneeId)?->name;
|
||||
|
||||
$changes['assignee'] = [
|
||||
'from' => $ticket->assignee?->name,
|
||||
'to' => $ticketAttributes['assignee_user_id'] === null
|
||||
? null
|
||||
: User::query()->find($ticketAttributes['assignee_user_id'])?->name,
|
||||
'to' => $toAssigneeName,
|
||||
];
|
||||
$summaryLabels[] = 'assignee';
|
||||
|
||||
$assigneeChange = [
|
||||
'from_id' => $ticket->assignee_user_id,
|
||||
'from_name' => $ticket->assignee?->name,
|
||||
'to_id' => $toAssigneeId,
|
||||
'to_name' => $toAssigneeName,
|
||||
];
|
||||
}
|
||||
|
||||
if ($ticket->author_user_id !== $ticketAttributes['author_user_id']) {
|
||||
@@ -225,6 +241,21 @@ class UpdateProjectTicket
|
||||
$changes,
|
||||
);
|
||||
|
||||
if ($assigneeChange !== null) {
|
||||
TicketAssigneeChanged::dispatch(
|
||||
$this->buildTicketAssigneeChangedPayload->handle(
|
||||
$ticket->project,
|
||||
$ticket,
|
||||
$actor,
|
||||
$assigneeChange['from_id'],
|
||||
$assigneeChange['from_name'],
|
||||
$assigneeChange['to_id'],
|
||||
$assigneeChange['to_name'],
|
||||
CarbonImmutable::now(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user