fixe duploads and attachments

This commit is contained in:
Mark Gregory
2026-06-16 18:25:54 +01:00
parent c008fc67dc
commit bcd133e27a
4 changed files with 276 additions and 33 deletions
+57 -3
View File
@@ -6,8 +6,10 @@ namespace Modules\Helpdesk\Livewire;
use App\Models\User;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Schema;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
@@ -41,6 +43,8 @@ final class TicketShow extends Component
public ?int $priority_id = null;
public ?int $agent_id = null;
public ?int $reply_parent_id = null;
public string $replyBody = '';
@@ -53,6 +57,7 @@ final class TicketShow extends Component
$this->ticket = $this->freshTicket($ticket);
$this->status_id = $this->ticket->status_id;
$this->priority_id = $this->ticket->priority_id;
$this->agent_id = $this->ticket->agent_id;
}
public function startReply(int $commentId): void
@@ -73,7 +78,7 @@ final class TicketShow extends Component
$this->validate([
'commentBody' => ['required', 'string', 'min:2'],
'attachments.*' => 'file|max:'.config('helpdesk.max_upload_kb').'|mimes:'.implode(',', config('helpdesk.allowed_mimes')),
'attachments.*' => 'file|max:'.config('helpdesk.max_upload_kb', 10240).'|mimes:'.implode(',', config('helpdesk.allowed_mimes', ['jpg', 'jpeg', 'png', 'pdf', 'txt', 'log', 'zip'])),
]);
$tickets->comment($this->ticket, Auth::user(), $this->commentBody, $this->internal, $this->attachments);
@@ -101,7 +106,6 @@ final class TicketShow extends Component
$this->dispatch('helpdesk-reply-added');
}
public function applyCannedResponse(CannedResponseRenderer $renderer): void
{
$this->authorize('comment', $this->ticket);
@@ -167,11 +171,27 @@ final class TicketShow extends Component
$this->dispatch('helpdesk-priority-updated');
}
public function updateAgent(WorkflowNotificationService $workflow): void
{
$this->authorize('update', $this->ticket);
$this->validate(['agent_id' => ['nullable', 'integer', 'exists:users,id']]);
$this->ticket->forceFill([
'agent_id' => $this->agent_id,
'last_activity_at' => now(),
])->save();
$this->ticket = $this->freshTicket($this->ticket);
$workflow->dispatch($this->ticket, 'ticket.updated', Auth::user());
$this->dispatch('helpdesk-agent-updated');
}
public function render(): View
{
return view('helpdesk::livewire.ticket-show', [
'statuses' => Status::query()->orderBy('sort_order')->get(),
'priorities' => Priority::query()->orderBy('sort_order')->get(),
'agents' => $this->agentOptions(),
'cannedResponses' => CannedResponse::query()->where('is_active', true)->orderBy('sort_order')->orderBy('name')->get(),
])->layout('layouts.app');
}
@@ -207,10 +227,44 @@ final class TicketShow extends Component
return $ticket;
}
/**
* Return assignable users. Falls back to all tenant users when helpdesk flags/roles are absent.
*
* @return EloquentCollection<int, User>
*/
private function agentOptions(): EloquentCollection
{
return User::query()
->select(['id', 'name', 'email', 'company_id'])
->when($this->ticket->company_id !== null && Schema::hasColumn('users', 'company_id'), function ($query): void {
$query->where(function ($query): void {
$query->where('company_id', $this->ticket->company_id)
->orWhereNull('company_id');
});
})
->when(Schema::hasColumn('users', 'helpdesk_agent') || Schema::hasColumn('users', 'helpdesk_admin'), function ($query): void {
$query->where(function ($query): void {
if (Schema::hasColumn('users', 'helpdesk_agent')) {
$query->orWhere('helpdesk_agent', true);
}
if (Schema::hasColumn('users', 'helpdesk_admin')) {
$query->orWhere('helpdesk_admin', true);
}
if ($this->agent_id !== null) {
$query->orWhereKey($this->agent_id);
}
});
})
->orderBy('name')
->get();
}
/**
* Build an unlimited nested comment tree from a flat eager-loaded collection.
*
* @param Collection<int|string, Collection<int, mixed>> $grouped
* @param Collection<int|string, Collection<int, mixed>> $grouped
* @return Collection<int, mixed>
*/
private function buildCommentTree(Collection $grouped, ?int $parentId = null): Collection