proper closer status
This commit is contained in:
@@ -16,6 +16,7 @@ use Illuminate\Validation\Rule;
|
||||
use Modules\Helpdesk\Models\Status;
|
||||
use Modules\Helpdesk\Models\Ticket;
|
||||
use Modules\Helpdesk\Services\SlaService;
|
||||
use Modules\Helpdesk\Services\TicketService;
|
||||
use Modules\Helpdesk\Services\WorkflowNotificationService;
|
||||
|
||||
final class TicketControlsController extends Controller
|
||||
@@ -64,7 +65,7 @@ final class TicketControlsController extends Controller
|
||||
/**
|
||||
* Persist the selected ticket status from the ticket detail controls.
|
||||
*/
|
||||
public function updateStatus(Request $request, Ticket $ticket, WorkflowNotificationService $workflow, SlaService $sla): RedirectResponse
|
||||
public function updateStatus(Request $request, Ticket $ticket, WorkflowNotificationService $workflow, SlaService $sla, TicketService $tickets): RedirectResponse
|
||||
{
|
||||
$this->hydrateUserRelations($ticket);
|
||||
|
||||
@@ -72,10 +73,21 @@ final class TicketControlsController extends Controller
|
||||
|
||||
$validated = $request->validate([
|
||||
'status_id' => ['required', 'integer', Rule::exists('helpdesk_statuses', 'id')],
|
||||
'closure_comment' => ['nullable', 'string', 'min:10', 'max:5000'],
|
||||
'closure_internal' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
$status = Status::query()->findOrFail((int) $validated['status_id']);
|
||||
|
||||
if ($status->is_closed) {
|
||||
validator($validated, [
|
||||
'closure_comment' => ['required', 'string', 'min:10', 'max:5000'],
|
||||
], [
|
||||
'closure_comment.required' => 'A closure comment is required before closing the ticket.',
|
||||
'closure_comment.min' => 'The closure comment must explain why the ticket is being closed.',
|
||||
])->validate();
|
||||
}
|
||||
|
||||
$this->updateTicket($ticket, [
|
||||
'status_id' => $status->id,
|
||||
'completed_at' => $status->is_closed ? now() : null,
|
||||
@@ -85,12 +97,24 @@ final class TicketControlsController extends Controller
|
||||
$this->ensureBoardContainsStatus($ticket, (int) $status->id);
|
||||
|
||||
$fresh = $this->freshTicketForAction($ticket);
|
||||
$actor = $this->actor();
|
||||
|
||||
if ($status->is_closed) {
|
||||
$tickets->comment(
|
||||
$fresh,
|
||||
$actor,
|
||||
trim((string) $validated['closure_comment']),
|
||||
(bool) ($validated['closure_internal'] ?? false),
|
||||
[],
|
||||
null,
|
||||
'Closure comment'
|
||||
);
|
||||
|
||||
$fresh = $this->freshTicketForAction($ticket);
|
||||
$sla->recordClosure($fresh);
|
||||
}
|
||||
|
||||
$workflow->dispatch($fresh, $status->is_closed ? 'ticket.closed' : 'ticket.updated', $this->actor());
|
||||
$workflow->dispatch($fresh, $status->is_closed ? 'ticket.closed' : 'ticket.updated', $actor);
|
||||
|
||||
return redirect()
|
||||
->route('helpdesk.tickets.show', $fresh)
|
||||
|
||||
Reference in New Issue
Block a user