major updates
This commit is contained in:
@@ -32,6 +32,7 @@ final class TicketCommentStoreController extends Controller
|
||||
$allowedMimes = (array) config('helpdesk.allowed_mimes', ['jpg', 'jpeg', 'png', 'pdf', 'txt', 'log', 'zip']);
|
||||
|
||||
$validated = $request->validate([
|
||||
'subject' => ['nullable', 'string', 'max:180'],
|
||||
'commentBody' => ['nullable', 'string'],
|
||||
'internal' => ['nullable', 'boolean'],
|
||||
'parent_id' => [
|
||||
@@ -48,16 +49,24 @@ final class TicketCommentStoreController extends Controller
|
||||
abort_if($user === null, 403);
|
||||
|
||||
$body = trim((string) ($validated['commentBody'] ?? ''));
|
||||
$subject = trim((string) ($validated['subject'] ?? ''));
|
||||
|
||||
if ($body === '' && filled($validated['canned_response_id'] ?? null)) {
|
||||
if (filled($validated['canned_response_id'] ?? null)) {
|
||||
$response = CannedResponse::query()
|
||||
->where('is_active', true)
|
||||
->findOrFail((int) $validated['canned_response_id']);
|
||||
|
||||
$body = trim($renderer->render($response->body, $ticket, $user));
|
||||
if ($body === '') {
|
||||
$body = trim($renderer->render($response->body, $ticket, $user));
|
||||
}
|
||||
|
||||
if ($subject === '') {
|
||||
$subject = (string) $response->name;
|
||||
}
|
||||
}
|
||||
|
||||
$body = $this->normaliseHtmlBody($body);
|
||||
$subject = $this->normaliseSubject($subject, $body, filled($validated['parent_id'] ?? null));
|
||||
|
||||
validator(['commentBody' => $body], [
|
||||
'commentBody' => ['required', 'string', 'min:2'],
|
||||
@@ -73,12 +82,34 @@ final class TicketCommentStoreController extends Controller
|
||||
internal: (bool) ($validated['internal'] ?? false) && $this->userCanCreateInternalNote($user),
|
||||
files: $uploadedFiles,
|
||||
parentId: filled($validated['parent_id'] ?? null) ? (int) $validated['parent_id'] : null,
|
||||
subject: $subject,
|
||||
);
|
||||
|
||||
return redirect()
|
||||
->route('helpdesk.tickets.show', $ticket)
|
||||
->with('ticket-comment-added', filled($validated['parent_id'] ?? null) ? 'Reply posted.' : 'Comment posted.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive a user-friendly Lotus Notes style response subject.
|
||||
*/
|
||||
private function normaliseSubject(string $subject, string $body, bool $isReply): string
|
||||
{
|
||||
$subject = trim(strip_tags(html_entity_decode($subject, ENT_QUOTES | ENT_HTML5, 'UTF-8')));
|
||||
|
||||
if ($subject !== '') {
|
||||
return Str::limit($subject, 180, '');
|
||||
}
|
||||
|
||||
$plain = trim(preg_replace('/\s+/', ' ', strip_tags(html_entity_decode($body, ENT_QUOTES | ENT_HTML5, 'UTF-8'))) ?: '');
|
||||
|
||||
if ($plain === '') {
|
||||
return $isReply ? 'RE: Response' : 'Response';
|
||||
}
|
||||
|
||||
return ($isReply ? 'RE: ' : '').Str::limit($plain, 120, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep supported formatting tags but strip scripts and unsafe inline handlers.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user