uploader; $staff = $this->staff($file); $this->notifier->send('file_quarantined', $staff, subject: $file, data: [ 'itemName' => $file->name, 'uploaderName' => $uploader->name ?? __('a deleted account'), 'threat' => $threat, ]); // The uploader hears it once. Without this check a staff member // who uploaded an infected file would get both messages, which // read as two different files. if ($uploader !== null && ! $staff->contains(fn (User $member): bool => $member->is($uploader))) { $this->notifier->send('upload_blocked', [$uploader], subject: $file, data: [ 'itemName' => $file->name, 'threat' => $threat, ]); } } /** * Staff who can release this file — the permission, and a client * scope that reaches its uploader (see QuarantineController). * * @return \Illuminate\Support\Collection */ private function staff(File $file): \Illuminate\Support\Collection { return User::query() ->where('type', UserType::Staff) ->where('active', true) ->get() ->filter(fn (User $staff): bool => $this->permissions->allows($staff, Permission::ReleaseQuarantinedFiles)) ->filter(function (User $staff) use ($file): bool { $uploaders = $this->scope->uploaderIds($staff); return $uploaders === null || in_array($file->uploaded_by, $uploaders, true); }) ->values(); } }