IT-Service: Dateianhang beim Ticket
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m45s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m0s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m2s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m23s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m17s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m38s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m23s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 21:16:11 +00:00
parent e9283752c6
commit 011a421b29
111 changed files with 561 additions and 451 deletions

View file

@ -96,9 +96,10 @@ class ItServiceController extends Controller
'category_id' => $categories ? ['required', 'integer', Rule::in($categories)] : ['nullable', 'integer'],
'location_id' => $locations ? ['required', 'integer', Rule::in($locations)] : ['nullable', 'integer'],
'asset_id' => ['nullable', 'integer'],
], [], ['subject' => 'Betreff', 'description' => 'Nachricht', 'category_id' => 'Kategorie', 'location_id' => 'Standort']);
'attachment' => ['nullable', 'file', 'max:10240', 'mimes:jpg,jpeg,png,gif,webp,pdf,txt,doc,docx'],
], ['attachment.mimes' => 'Bitte ein Bild, PDF, Text- oder Word-Dokument anhängen.'], ['subject' => 'Betreff', 'description' => 'Nachricht', 'category_id' => 'Kategorie', 'location_id' => 'Standort', 'attachment' => 'Anhang']);
$id = $this->orFail(fn () => $this->it->createTicket($request->user(), $data), 'subject');
$id = $this->orFail(fn () => $this->it->createTicket($request->user(), $data, $request->file('attachment')), 'subject');
return $id > 0
? to_route('it-service.tickets.show', $id)->with('status', 'Ticket erstellt – die IT meldet sich.')

View file

@ -3,8 +3,10 @@
namespace Inhaus\Plugins\ItService;
use App\Models\User;
use App\Support\Images;
use App\Support\RichText;
use Illuminate\Http\Client\Response;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Arr;
use Inhaus\Plugins\ItService\OpenNit\Client;
use Inhaus\Plugins\ItService\OpenNit\Settings;
@ -90,9 +92,9 @@ class ItService
/**
* @param array{subject: string, description?: ?string, category_id?: ?int, location_id?: ?int, asset_id?: ?int} $data
*/
public function createTicket(User $user, array $data): int
public function createTicket(User $user, array $data, ?UploadedFile $attachment = null): int
{
$response = $this->client->post('/tickets', array_filter([
$body = array_filter([
'subject' => $data['subject'],
'from_email' => $user->email,
'from_name' => $user->name,
@ -100,7 +102,17 @@ class ItService
'category_id' => $data['category_id'] ?? null,
'location_id' => $data['location_id'] ?? null,
'asset_id' => $data['asset_id'] ?? null,
], fn ($value) => $value !== null && $value !== ''));
], fn ($value) => $value !== null && $value !== '');
// Anhang wie im WordPress-Plugin von OpenNIT: Data-URL plus Name und Typ
if ($attachment) {
$mime = $attachment->getMimeType() ?: 'application/octet-stream';
$body['attachment_b64'] = Images::withLocalCopy($attachment, fn (string $path) => 'data:'.$mime.';base64,'.base64_encode((string) file_get_contents($path)));
$body['attachment_name'] = $attachment->getClientOriginalName();
$body['attachment_mime'] = $mime;
}
$response = $this->client->post('/tickets', $body);
return (int) ($response['id'] ?? $response['ticket_id'] ?? 0);
}