Add assignee changed notification event support

This commit is contained in:
2026-05-18 23:30:32 +00:00
parent 3ddfcc89f9
commit c9050886ac
13 changed files with 558 additions and 12 deletions
@@ -60,7 +60,7 @@ class BuildProjectNotificationSettingsPayload
'value' => '$project_name',
],
[
'description' => 'Origin status label for status moves; blank for ticket create.',
'description' => 'Origin status label for status moves; blank for ticket create and assignee changes.',
'value' => '$status_from',
],
[
@@ -71,6 +71,14 @@ class BuildProjectNotificationSettingsPayload
'description' => 'Actor name when the event has a known user.',
'value' => '$actor_name',
],
[
'description' => 'Previous assignee name when the event updates assignment; blank otherwise.',
'value' => '$assignee_from',
],
[
'description' => 'New assignee name when the event updates assignment; blank when unassigned.',
'value' => '$assignee_to',
],
];
}
}
@@ -0,0 +1,63 @@
<?php
namespace App\Actions\Notifications;
use App\Enums\NotificationEventType;
use App\Models\Project;
use App\Models\Ticket;
use App\Models\TicketStatus;
use App\Models\User;
use Carbon\CarbonImmutable;
class BuildTicketAssigneeChangedPayload
{
public function handle(
Project $project,
Ticket $ticket,
?User $actor,
?int $fromAssigneeId,
?string $fromAssigneeName,
?int $toAssigneeId,
?string $toAssigneeName,
CarbonImmutable $occurredAt,
): TicketStatusChangedPayload {
$ticket->loadMissing('ticketStatus.boardColumn');
return new TicketStatusChangedPayload(
eventType: NotificationEventType::TicketAssigneeChanged,
projectId: $project->id,
projectKey: $project->key,
projectName: $project->name,
ticketId: $ticket->id,
ticketKey: $ticket->ticket_key,
ticketTitle: $ticket->title,
ticketUrl: route('projects.tickets.show', [$project, $ticket]),
actorId: $actor?->id,
actorName: $actor?->name,
fromStatusId: null,
fromStatusLabel: null,
toStatusId: $ticket->ticket_status_id,
toStatusLabel: $this->statusLabel($ticket->ticketStatus),
occurredAt: $occurredAt,
fromAssigneeId: $fromAssigneeId,
fromAssigneeName: $fromAssigneeName,
toAssigneeId: $toAssigneeId,
toAssigneeName: $toAssigneeName,
);
}
private function statusLabel(?TicketStatus $ticketStatus): string
{
if ($ticketStatus === null) {
return 'Unknown status';
}
$ticketStatus->loadMissing('boardColumn');
if ($ticketStatus->boardColumn === null || $ticketStatus->boardColumn->name === $ticketStatus->name) {
return $ticketStatus->name;
}
return "{$ticketStatus->boardColumn->name} / {$ticketStatus->name}";
}
}
@@ -207,6 +207,16 @@ class MatchNotificationFilters
'id' => $actorId,
'name' => $actorName,
],
'assignee' => [
'from' => [
'id' => $payload->fromAssigneeId,
'name' => $payload->fromAssigneeName,
],
'to' => [
'id' => $payload->toAssigneeId,
'name' => $payload->toAssigneeName,
],
],
'status' => [
'from' => [
'id' => $fromStatusId,
@@ -0,0 +1,26 @@
<?php
namespace App\Actions\Notifications;
use App\Enums\NotificationEventType;
use Illuminate\Contracts\Events\ShouldDispatchAfterCommit;
use Illuminate\Foundation\Events\Dispatchable;
final readonly class TicketAssigneeChanged implements NotificationEvent, ShouldDispatchAfterCommit
{
use Dispatchable;
public function __construct(
public TicketStatusChangedPayload $payload,
) {}
public function eventType(): NotificationEventType
{
return NotificationEventType::TicketAssigneeChanged;
}
public function payload(): NotificationEventPayload
{
return $this->payload;
}
}
@@ -17,11 +17,16 @@ final readonly class TicketStatusChangedPayload implements NotificationEventPayl
public string $ticketUrl,
public ?int $actorId,
public ?string $actorName,
public int $fromStatusId,
public string $fromStatusLabel,
public ?int $fromStatusId,
public ?string $fromStatusLabel,
public int $toStatusId,
public string $toStatusLabel,
public CarbonImmutable $occurredAt,
public ?int $fromAssigneeId = null,
public ?string $fromAssigneeName = null,
public ?int $toAssigneeId = null,
public ?string $toAssigneeName = null,
public NotificationEventType $eventType = NotificationEventType::TicketStatusChanged,
) {}
public function projectId(): int
@@ -50,9 +55,11 @@ final readonly class TicketStatusChangedPayload implements NotificationEventPayl
'$ticket_key' => $this->ticketKey,
'$ticket_title' => $this->ticketTitle,
'$project_name' => $this->projectName,
'$status_from' => $this->fromStatusLabel,
'$status_from' => $this->fromStatusLabel ?? '',
'$status_to' => $this->toStatusLabel,
'$actor_name' => $this->actorName ?? '',
'$assignee_from' => $this->fromAssigneeName ?? '',
'$assignee_to' => $this->toAssigneeName ?? '',
];
}
@@ -62,7 +69,11 @@ final readonly class TicketStatusChangedPayload implements NotificationEventPayl
* project: array{id: int, key: string, name: string},
* ticket: array{id: int, key: string, title: string},
* actor: array{id: int, name: string}|null,
* from: array{id: int, label: string},
* assignee: array{
* from: array{id: int, name: string}|null,
* to: array{id: int, name: string}|null
* },
* from: array{id: int, label: string}|null,
* to: array{id: int, label: string},
* ticket_url: string,
* occurred_at: string
@@ -71,7 +82,7 @@ final readonly class TicketStatusChangedPayload implements NotificationEventPayl
public function toArray(): array
{
return [
'event_type' => NotificationEventType::TicketStatusChanged->value,
'event_type' => $this->eventType->value,
'project' => [
'id' => $this->projectId,
'key' => $this->projectKey,
@@ -88,10 +99,26 @@ final readonly class TicketStatusChangedPayload implements NotificationEventPayl
'id' => $this->actorId,
'name' => $this->actorName,
],
'from' => [
'id' => $this->fromStatusId,
'label' => $this->fromStatusLabel,
'assignee' => [
'from' => $this->fromAssigneeId === null || $this->fromAssigneeName === null
? null
: [
'id' => $this->fromAssigneeId,
'name' => $this->fromAssigneeName,
],
'to' => $this->toAssigneeId === null || $this->toAssigneeName === null
? null
: [
'id' => $this->toAssigneeId,
'name' => $this->toAssigneeName,
],
],
'from' => $this->fromStatusId === null || $this->fromStatusLabel === null
? null
: [
'id' => $this->fromStatusId,
'label' => $this->fromStatusLabel,
],
'to' => [
'id' => $this->toStatusId,
'label' => $this->toStatusLabel,