Mache die Übernahme aus Shinkan auffindbar und zeige den Zustand der Anbindung
CI Feature / test (push) Successful in 2m25s

Die Übungsliste verweist mit „Aus Shinkan übernehmen“ auf die Übernahmeseite. Die Seite zeigt Adresse (nur Host) und
Schlüssel (nur ob hinterlegt) und prüft die Verbindung, ohne etwas zu übernehmen.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-23 17:25:37 +01:00
1 parent 881703ba0e
commit bc140a0e83
5 files changed
+117 -7

No files matched your search

+39
View File
@@ -37,6 +37,45 @@ public function configured(): bool
return filled(config('services.shinkan.url')) && filled(config('services.shinkan.key')); return filled(config('services.shinkan.url')) && filled(config('services.shinkan.key'));
} }
/**
* Zustand der Anbindung ohne Werte: Adresse und Schlüssel stehen nur in der Umgebungsdatei des Servers.
*
* @return array{url: bool, key: bool, host: string|null}
*/
public function status(): array
{
$url = (string) config('services.shinkan.url');
return [
'url' => filled($url),
'key' => filled(config('services.shinkan.key')),
'host' => filled($url) ? (parse_url($url, PHP_URL_HOST) ?: null) : null,
];
}
/**
* Verbindung prüfen, ohne etwas zu speichern. Der Katalogabruf legt auf der Seite von Shinkan einen Stand an; hier
* wird nur gezählt, was die Quelle für Lara & Felix bereitstellt.
*
* @return array{ok: bool, message: string}
*/
public function check(): array
{
if (! $this->configured()) {
return ['ok' => false, 'message' => 'Die Anbindung ist nicht eingerichtet. Adresse und Schlüssel fehlen in der Umgebung des Servers.'];
}
try {
$catalog = $this->get('/catalog');
} catch (Throwable $exception) {
return ['ok' => false, 'message' => 'Die Verbindung ist fehlgeschlagen: '.$this->plain($exception)];
}
$count = count((array) ($catalog['exercises'] ?? []));
return ['ok' => true, 'message' => 'Die Verbindung funktioniert. Die Quelle stellt '.$count.($count === 1 ? ' Übung' : ' Übungen').' bereit. Es wurde nichts übernommen.'];
}
public function fetch(): ExerciseImportRun public function fetch(): ExerciseImportRun
{ {
$run = ExerciseImportRun::query()->create(['status' => 'laeuft', 'started_at' => now()]); $run = ExerciseImportRun::query()->create(['status' => 'laeuft', 'started_at' => now()]);
+12 -2
View File
@@ -24,13 +24,13 @@ class Uebernahme extends Page
{ {
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte'; protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
protected static ?string $navigationLabel = 'Übernahme (Shinkan)'; protected static ?string $navigationLabel = 'Übungen aus Shinkan';
protected static ?int $navigationSort = 6; protected static ?int $navigationSort = 6;
protected static ?string $slug = 'uebernahme'; protected static ?string $slug = 'uebernahme';
protected static ?string $title = 'Übernahme aus Shinkan'; protected static ?string $title = 'Übungen aus Shinkan übernehmen';
protected string $view = 'filament.pages.uebernahme'; protected string $view = 'filament.pages.uebernahme';
@@ -64,6 +64,15 @@ public function fetch(): void
: (string) $run->error; : (string) $run->error;
} }
public function check(): void
{
abort_unless(static::canAccess(), 403);
$result = app(ShinkanImport::class)->check();
$this->feedbackError = ! $result['ok'];
$this->feedback = $result['message'];
}
public function adopt(int $snapshotId): void public function adopt(int $snapshotId): void
{ {
abort_unless(static::canAccess(), 403); abort_unless(static::canAccess(), 403);
@@ -114,6 +123,7 @@ public function daten(): array
return [ return [
'zeilen' => $rows, 'zeilen' => $rows,
'eingerichtet' => app(ShinkanImport::class)->configured(), 'eingerichtet' => app(ShinkanImport::class)->configured(),
'anbindung' => app(ShinkanImport::class)->status(),
'letzterLauf' => ExerciseImportRun::query()->orderByDesc('id')->first(), 'letzterLauf' => ExerciseImportRun::query()->orderByDesc('id')->first(),
]; ];
} }
@@ -4,6 +4,7 @@
use App\Domain\Catalog\CompositionKind; use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\ContentService; use App\Domain\Catalog\ContentService;
use App\Filament\Pages\Uebernahme;
use App\Filament\Resources\ContentElements\ContentElementResource; use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Support\ListsCompositions; use App\Filament\Support\ListsCompositions;
use App\Filament\Support\ReportsDomainRules; use App\Filament\Support\ReportsDomainRules;
@@ -55,6 +56,18 @@ public function content(Schema $schema): Schema
protected function getHeaderActions(): array protected function getHeaderActions(): array
{ {
if ($this->kind() === CompositionKind::Exercise) {
return [
$this->createCompositionAction($this->kind()),
Action::make('shinkan')
->label('Aus Shinkan übernehmen')
->icon('heroicon-o-arrow-down-tray')
->color('gray')
->visible(fn (): bool => ContentElementResource::editor())
->url(fn (): string => Uebernahme::getUrl()),
];
}
if ($this->onDesk()) { if ($this->onDesk()) {
return [$this->createCompositionAction($this->kind())]; return [$this->createCompositionAction($this->kind())];
} }
@@ -1,14 +1,22 @@
@php($daten = $this->daten()) @php($daten = $this->daten())
<div class="vw"> <div class="vw">
<header class="vw-kopf"> <header class="vw-kopf">
<h1 class="vw-titel">Übernahme aus Shinkan</h1> <h1 class="vw-titel">Übungen aus Shinkan übernehmen</h1>
<p class="vw-feld-hilfe">Shinkan stellt für Lara &amp; Felix ausgewählte Übungen bereit. „Abrufen“ aktualisiert nur den Quellenstand. Erst „Übernehmen“ legt eine unveränderliche lokale Fassung an. Produkte verwenden sie erst, wenn du sie dort einsetzt und das Produkt veröffentlichst.</p> <p class="vw-feld-hilfe">Shinkan stellt für Lara &amp; Felix ausgewählte Übungen bereit. „Abrufen“ aktualisiert nur den Quellenstand. Erst „Übernehmen“ legt eine unveränderliche lokale Fassung an. Produkte verwenden sie erst, wenn du sie dort einsetzt und das Produkt veröffentlichst.</p>
<p> <section class="vw-abschnitt" aria-labelledby="anbindung-titel">
<button type="button" class="button button-primary" wire:click="fetch" wire:loading.attr="disabled" @disabled(! $daten['eingerichtet'])>Katalog abrufen</button> <h2 id="anbindung-titel" class="vw-abschnitt-titel">Anbindung</h2>
<dl class="vw-fakten">
<div><dt>Adresse der Quelle</dt><dd>{{ $daten['anbindung']['url'] ? ($daten['anbindung']['host'] ?? 'eingetragen') : 'nicht eingetragen' }}</dd></div>
<div><dt>Zugangsschlüssel</dt><dd>{{ $daten['anbindung']['key'] ? 'hinterlegt (wird nie angezeigt)' : 'nicht hinterlegt' }}</dd></div>
</dl>
@unless ($daten['eingerichtet']) @unless ($daten['eingerichtet'])
<span class="vw-feld-hilfe">Die Anbindung ist in dieser Umgebung nicht eingerichtet.</span> <p class="vw-band" role="note">Die Anbindung ist in dieser Umgebung nicht eingerichtet. Adresse und Schlüssel liegen aus Sicherheitsgründen nur in der Umgebungsdatei des Servers (<code>SHINKAN_DISTRIBUTION_URL</code> und <code>SHINKAN_DISTRIBUTION_KEY</code>). Sie werden nicht in dieser Oberfläche gespeichert und stehen nie im Repository.</p>
@endunless @endunless
</p> <p>
<button type="button" class="button button-secondary" wire:click="check" wire:loading.attr="disabled" @disabled(! $daten['eingerichtet'])>Verbindung prüfen</button>
<button type="button" class="button button-primary" wire:click="fetch" wire:loading.attr="disabled" @disabled(! $daten['eingerichtet'])>Katalog abrufen</button>
</p>
</section>
@if ($this->feedback !== '') @if ($this->feedback !== '')
<p class="vw-band {{ $this->feedbackError ? 'is-fehler' : '' }}" role="status">{{ $this->feedback }}</p> <p class="vw-band {{ $this->feedbackError ? 'is-fehler' : '' }}" role="status">{{ $this->feedback }}</p>
@endif @endif
+40
View File
@@ -11,6 +11,7 @@
use App\Domain\Catalog\ExerciseSourceSnapshot; use App\Domain\Catalog\ExerciseSourceSnapshot;
use App\Domain\Catalog\ShinkanImport; use App\Domain\Catalog\ShinkanImport;
use App\Filament\Pages\Uebernahme; use App\Filament\Pages\Uebernahme;
use App\Filament\Resources\Practices\Pages\ListPractices;
use App\Models\User; use App\Models\User;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -245,6 +246,45 @@ public function test_the_page_lists_states_and_adopts_on_purpose(): void
$this->assertNotNull($snapshot->fresh()->adopted_version_id); $this->assertNotNull($snapshot->fresh()->adopted_version_id);
} }
public function test_the_exercise_list_leads_to_the_takeover_page(): void
{
$user = User::factory()->redakteur()->create();
$user->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
Livewire::actingAs($user, 'staff')
->test(ListPractices::class)
->assertSee('Aus Shinkan übernehmen')
->assertSee(Uebernahme::getUrl(), false);
}
public function test_the_page_shows_the_connection_state_without_values_and_checks_the_connection(): void
{
$user = User::factory()->redakteur()->create();
$user->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
$this->fake([$this->document('h1')], [], 'c1');
Livewire::actingAs($user, 'staff')
->test(Uebernahme::class)
->assertSee('Adresse der Quelle')
->assertSee('shinkan.test')
->assertSee('hinterlegt (wird nie angezeigt)')
->assertDontSee('geheim-fuer-den-test')
->assertDontSee('https://shinkan.test')
->call('check')
->assertSee('Die Verbindung funktioniert. Die Quelle stellt 1 Übung bereit. Es wurde nichts übernommen.');
$this->assertSame(0, ExerciseSourceSnapshot::query()->count());
config(['services.shinkan.key' => null]);
Livewire::actingAs($user, 'staff')
->test(Uebernahme::class)
->assertSee('nicht hinterlegt')
->assertSee('SHINKAN_DISTRIBUTION_KEY')
->call('check')
->assertSee('nicht eingerichtet');
}
private function freshHttp(): void private function freshHttp(): void
{ {
Http::swap(new Factory); Http::swap(new Factory);