Skip to content

Commit 388d3aa

Browse files
committed
TicketUpdatedJob enhancement
1 parent 8b78f2c commit 388d3aa

8 files changed

Lines changed: 16 additions & 13 deletions

File tree

app/Http/Livewire/Kanban.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function onStatusChanged($recordId, $statusId, $fromOrderedIds, $toOrdere
123123
->title(__('Status updated'))
124124
->body(__('The ticket status has been successfully updated'))
125125
->send();
126-
TicketUpdatedJob::dispatch($ticket, __('Status'), $before, __(config('system.statuses.' . $ticket->status . '.title') ?? '-'));
126+
TicketUpdatedJob::dispatch($ticket, __('Status'), $before, __(config('system.statuses.' . $ticket->status . '.title') ?? '-'), auth()->user());
127127
} else {
128128
Notification::make()
129129
->success()

app/Http/Livewire/TicketDetails/Content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ public function save(): void
7979
]);
8080
$this->updating = false;
8181
$this->emit('ticketSaved');
82-
TicketUpdatedJob::dispatch($this->ticket, __('Content'), htmlspecialchars(strip_tags($before)), htmlspecialchars(strip_tags($this->ticket->content)));
82+
TicketUpdatedJob::dispatch($this->ticket, __('Content'), htmlspecialchars(strip_tags($before)), htmlspecialchars(strip_tags($this->ticket->content)), auth()->user());
8383
}
8484
}

app/Http/Livewire/TicketDetails/Priority.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ public function save(): void
7979
]);
8080
$this->updating = false;
8181
$this->emit('ticketSaved');
82-
TicketUpdatedJob::dispatch($this->ticket, __('Priority'), $before, __(config('system.priorities.' . $this->ticket->priority . '.title') ?? '-'));
82+
TicketUpdatedJob::dispatch($this->ticket, __('Priority'), $before, __(config('system.priorities.' . $this->ticket->priority . '.title') ?? '-'), auth()->user());
8383
}
8484
}

app/Http/Livewire/TicketDetails/Responsible.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function save(): void
8080
$this->updating = false;
8181
$this->ticket = $this->ticket->refresh();
8282
$this->emit('ticketSaved');
83-
TicketUpdatedJob::dispatch($this->ticket, __('Responsible'), $before, ($this->ticket->responsible?->name ?? '-'));
83+
TicketUpdatedJob::dispatch($this->ticket, __('Responsible'), $before, ($this->ticket->responsible?->name ?? '-'), auth()->user());
8484
}
8585

8686
/**

app/Http/Livewire/TicketDetails/Status.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ public function save(): void
7878
]);
7979
$this->updating = false;
8080
$this->emit('ticketSaved');
81-
TicketUpdatedJob::dispatch($this->ticket, __('Status'), $before, __(config('system.statuses.' . $this->ticket->status . '.title') ?? '-'));
81+
TicketUpdatedJob::dispatch($this->ticket, __('Status'), $before, __(config('system.statuses.' . $this->ticket->status . '.title') ?? '-'), auth()->user());
8282
}
8383
}

app/Http/Livewire/TicketDetails/Title.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ public function save(): void
7777
]);
7878
$this->updating = false;
7979
$this->emit('ticketSaved');
80-
TicketUpdatedJob::dispatch($this->ticket, __('Title'), $before, $this->ticket->title);
80+
TicketUpdatedJob::dispatch($this->ticket, __('Title'), $before, $this->ticket->title, auth()->user());
8181
}
8282
}

app/Http/Livewire/TicketDetails/Type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ public function save(): void
7878
]);
7979
$this->updating = false;
8080
$this->emit('ticketSaved');
81-
TicketUpdatedJob::dispatch($this->ticket, __('Type'), $before, __(config('system.types.' . $this->ticket->type . '.title') ?? '-'));
81+
TicketUpdatedJob::dispatch($this->ticket, __('Type'), $before, __(config('system.types.' . $this->ticket->type . '.title') ?? '-'), auth()->user());
8282
}
8383
}

app/Jobs/TicketUpdatedJob.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Notifications\CommentCreateNotification;
88
use App\Notifications\TicketUpdatedNotification;
99
use Illuminate\Bus\Queueable;
10+
use Illuminate\Contracts\Auth\Authenticatable;
1011
use Illuminate\Contracts\Queue\ShouldBeUnique;
1112
use Illuminate\Contracts\Queue\ShouldQueue;
1213
use Illuminate\Foundation\Bus\Dispatchable;
@@ -21,18 +22,20 @@ class TicketUpdatedJob implements ShouldQueue
2122
private string $field;
2223
private string $before;
2324
private string $after;
25+
private User|Authenticatable $user;
2426

2527
/**
2628
* Create a new job instance.
2729
*
2830
* @return void
2931
*/
30-
public function __construct(Ticket $ticket, string $field, string $before, string $after)
32+
public function __construct(Ticket $ticket, string $field, string $before, string $after, User|Authenticatable $user)
3133
{
3234
$this->ticket = $ticket;
3335
$this->field = $field;
3436
$this->before = $before;
3537
$this->after = $after;
38+
$this->user = $user;
3639
}
3740

3841
/**
@@ -43,14 +46,14 @@ public function __construct(Ticket $ticket, string $field, string $before, strin
4346
public function handle()
4447
{
4548
if ($this->before !== $this->after) {
46-
$users = User::whereNull('register_token')->get();
47-
foreach ($users as $user) {
49+
$users = User::whereNull('register_token')->where('id', '<>', $this->user->id)->get();
50+
foreach ($users as $u) {
4851
if (
49-
(has_all_permissions($user, 'view-all-tickets') && $this->ticket->owner_id !== $user->id)
52+
(has_all_permissions($u, 'view-all-tickets') && $this->ticket->owner_id !== $u->id)
5053
||
51-
(has_all_permissions($user, 'view-own-tickets') && ($this->ticket->owner_id === $user->id || $this->ticket->responsible_id === $user->id) && $this->ticket->owner_id !== $user->id)
54+
(has_all_permissions($u, 'view-own-tickets') && ($this->ticket->owner_id === $u->id || $this->ticket->responsible_id === $u->id) && $this->ticket->owner_id !== $u->id)
5255
) {
53-
$user->notify(new TicketUpdatedNotification($this->ticket, $this->field, $this->before, $this->after, $user));
56+
$u->notify(new TicketUpdatedNotification($this->ticket, $this->field, $this->before, $this->after, $this->user));
5457
}
5558
}
5659
}

0 commit comments

Comments
 (0)