77use App \Notifications \CommentCreateNotification ;
88use App \Notifications \TicketUpdatedNotification ;
99use Illuminate \Bus \Queueable ;
10+ use Illuminate \Contracts \Auth \Authenticatable ;
1011use Illuminate \Contracts \Queue \ShouldBeUnique ;
1112use Illuminate \Contracts \Queue \ShouldQueue ;
1213use 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