IT-Service: /api/ex ergänzen, HTML-Antworten als Fehler, Kategorie und Standort Pflicht
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m35s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m32s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m54s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m53s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m1s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m17s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m31s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m11s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m33s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 20:17:39 +00:00
parent df7ebfa6cd
commit 7969a7ac83
108 changed files with 525 additions and 445 deletions

View file

@ -15,6 +15,7 @@ const props = defineProps({
assetId: { type: Number, default: null },
assets: { type: Object, required: true },
options: { type: Object, required: true },
defaultLocation: { type: Number, default: null },
});
const myAssets = computed(() => (props.assets.ok ? props.assets.data : []));
@ -26,7 +27,7 @@ const form = useForm({
subject: '',
description: '',
category_id: null,
location_id: null,
location_id: props.defaultLocation,
});
function submit() {
@ -77,20 +78,20 @@ function submit() {
<Panel title="Beschreibung" class="lg:col-span-7 xl:col-span-8">
<div class="grid gap-4">
<div class="grid gap-4 sm:grid-cols-2">
<FormField id="category" label="Kategorie" :error="form.errors.category_id" :hint="categories.length ? '' : 'Kategorien konnten nicht geladen werden.'">
<NativeSelect id="category" v-model="form.category_id" :options="categories" placeholder="– bitte wählen –" :required="categories.length > 0" :disabled="!categories.length" />
</FormField>
<FormField id="location" label="Standort" :error="form.errors.location_id" :hint="locations.length ? 'Wo tritt das Problem auf?' : 'Standorte konnten nicht geladen werden.'">
<NativeSelect id="location" v-model="form.location_id" :options="locations" placeholder="– bitte wählen –" :required="locations.length > 0" :disabled="!locations.length" />
</FormField>
</div>
<FormField id="subject" label="Betreff" :error="form.errors.subject">
<Input id="subject" v-model="form.subject" maxlength="200" placeholder="z. B. Drucker im 2. OG druckt nicht" required />
</FormField>
<FormField id="description" label="Was ist passiert?" :error="form.errors.description" hint="Seit wann? Gibt es eine Fehlermeldung? Was haben Sie schon versucht?">
<Textarea id="description" v-model="form.description" rows="7" maxlength="20000" required />
</FormField>
<div class="grid gap-4 sm:grid-cols-2">
<FormField v-if="categories.length" id="category" label="Kategorie" :error="form.errors.category_id">
<NativeSelect id="category" v-model="form.category_id" :options="categories" placeholder="– bitte wählen –" />
</FormField>
<FormField v-if="locations.length" id="location" label="Standort" :error="form.errors.location_id">
<NativeSelect id="location" v-model="form.location_id" :options="locations" placeholder="– bitte wählen –" />
</FormField>
</div>
<div class="flex justify-end border-t pt-4">
<Button type="submit" :disabled="form.processing">
<LoaderCircle v-if="form.processing" class="animate-spin" /><Send v-else /> Ticket absenden

View file

@ -13,7 +13,7 @@ use Filament\Pages\Page;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Inhaus\Plugins\ItService\OpenNit\Client;
use Inhaus\Plugins\ItService\ItService;
use Inhaus\Plugins\ItService\OpenNit\OpenNitException;
use Inhaus\Plugins\ItService\OpenNit\Settings;
use UnitEnum;
@ -66,6 +66,7 @@ class ItServiceSettings extends Page
TextInput::make('url')
->label('API-Adresse')
->placeholder('https://itdoku.example.de/api/ex')
->helperText('Nur die Serveradresse eingetragen? „/api/ex“ wird automatisch ergänzt.')
->url()
->required()
->regex('#^https://#i')
@ -120,11 +121,15 @@ class ItServiceSettings extends Page
->label('Verbindung testen')
->icon(Heroicon::OutlinedSignal)
->color('gray')
->action(function (Client $client) {
->action(function () {
try {
$categories = count((array) ($client->get('/ticket-categories')['categories'] ?? []));
$types = count((array) ($client->get('/device-types')['types'] ?? []));
Notification::make()->success()->title('Verbindung klappt')->body("{$categories} Ticket-Kategorien und {$types} Gerätetypen gefunden.")->send();
$it = app(ItService::class);
$options = $it->ticketOptions();
$types = $it->deviceTypes();
$devices = $it->loanDevices(null, null, null);
Notification::make()->success()->title('Verbindung klappt')
->body(sprintf('%d Ticket-Kategorien, %d Standorte, %d Gerätetypen und %d Leihgeräte gefunden.', count($options['categories']), count($options['locations']), count($types), count($devices)))
->send();
} catch (OpenNitException $e) {
Notification::make()->danger()->title('Keine Verbindung')->body($e->getMessage().($e->status ? " (HTTP {$e->status})" : ''))->persistent()->send();
}

View file

@ -8,6 +8,7 @@ use Closure;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Inertia\Inertia;
use Inertia\Response;
@ -60,22 +61,42 @@ class ItServiceController extends Controller
{
$user = $request->user();
$options = $this->attempt(fn () => $this->it->ticketOptions());
// Standort aus dem Profil vorbelegen, wenn er in OpenNIT genauso heißt
$location = null;
if ($options['ok'] && filled($user->location)) {
foreach ($options['data']['locations'] as $option) {
if (mb_strtolower(trim($option['label'], '– ')) === mb_strtolower(trim($user->location))) {
$location = $option['value'];
break;
}
}
}
return Inertia::render('it-service::TicketCreate', [
'assetId' => $request->integer('geraet') ?: null,
'assets' => $this->attempt(fn () => $this->it->assets($user)),
'options' => $this->attempt(fn () => $this->it->ticketOptions()),
'options' => $options,
'defaultLocation' => $location,
]);
}
public function storeTicket(Request $request): RedirectResponse
{
// Kategorie und Standort sind Pflicht, sobald OpenNIT welche anbietet.
$options = $this->attempt(fn () => $this->it->ticketOptions());
$categories = $options['ok'] ? array_column($options['data']['categories'], 'value') : [];
$locations = $options['ok'] ? array_column($options['data']['locations'], 'value') : [];
$data = $request->validate([
'subject' => ['required', 'string', 'max:200'],
'description' => ['required', 'string', 'max:20000'],
'category_id' => ['nullable', 'integer'],
'location_id' => ['nullable', 'integer'],
'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' => 'Beschreibung']);
], [], ['subject' => 'Betreff', 'description' => 'Beschreibung', 'category_id' => 'Kategorie', 'location_id' => 'Standort']);
$id = $this->orFail(fn () => $this->it->createTicket($request->user(), $data), 'subject');

View file

@ -256,7 +256,8 @@ class ItService
*/
private function list(array $data, string $key): array
{
$items = $data[$key] ?? (array_is_list($data) ? $data : []);
// Laut Doku {"key": [...]}; manche Versionen verpacken in {"data": …}
$items = $data[$key] ?? $data['data'][$key] ?? (isset($data['data']) && is_array($data['data']) && array_is_list($data['data']) ? $data['data'] : null) ?? (array_is_list($data) ? $data : []);
return array_values(array_filter((array) $items, fn ($item) => is_array($item) || is_string($item)));
}

View file

@ -134,7 +134,16 @@ class Client
*/
private function json(Response $response): array
{
$data = (array) $response->json();
$decoded = $response->json();
// Eine HTML-Seite (falsche Adresse, Anmeldeseite …) ist keine leere Liste.
if ($response->successful() && ! is_array($decoded)) {
Log::warning('OpenNIT lieferte keine JSON-Antwort', ['body' => mb_substr($response->body(), 0, 300)]);
throw new OpenNitException('Der IT-Service hat keine gültige API-Antwort geliefert. Bitte die API-Adresse prüfen (sie endet auf „/api/ex“).', 502);
}
$data = (array) $decoded;
if (! $response->successful()) {
Log::info("OpenNIT antwortete {$response->status()}", ['body' => mb_substr($response->body(), 0, 500)]);

View file

@ -26,7 +26,21 @@ class Settings
public function url(): string
{
return rtrim((string) $this->settings->get(self::URL, ''), '/');
return self::normalizeUrl((string) $this->settings->get(self::URL, ''));
}
/**
* Nur die Adresse des Servers eingetragen? Dann gehört „/api/ex“ dazu.
*/
public static function normalizeUrl(string $url): string
{
$url = rtrim(trim($url), '/');
if ($url !== '' && in_array((string) parse_url($url, PHP_URL_PATH), ['', '/'], true)) {
$url .= '/api/ex';
}
return $url;
}
public function token(): string
@ -61,7 +75,7 @@ class Settings
*/
public function save(array $data): void
{
$this->settings->set(self::URL, rtrim(trim($data['url']), '/'));
$this->settings->set(self::URL, self::normalizeUrl($data['url']));
foreach ([self::TOKEN => $data['token'] ?? null, self::SECRET => $data['secret'] ?? null] as $key => $value) {
if (filled($value)) {