Pflege Adresse und Zugangsschlüssel der Shinkan-Anbindung in der Verwaltung
Werte aus der Umgebung des Servers haben Vorrang, sonst gilt der in der Verwaltung gepflegte. Der Schlüssel liegt verschlüsselt in site_settings und wird nie angezeigt. Änderung nur für Katalog- und Systemverwalter. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bcda189267
commit
26ca79cd22
8 files changed
+320
-17
No files matched your search
@@ -6,7 +6,9 @@
|
||||
use App\Domain\Catalog\ExerciseImportRun;
|
||||
use App\Domain\Catalog\ExerciseSource;
|
||||
use App\Domain\Catalog\ExerciseSourceSnapshot;
|
||||
use App\Domain\Catalog\ShinkanConnection;
|
||||
use App\Domain\Catalog\ShinkanImport;
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Resources\Practices\PracticeResource;
|
||||
use App\Models\User;
|
||||
@@ -34,13 +36,57 @@ class Uebernahme extends Page
|
||||
|
||||
protected string $view = 'filament.pages.uebernahme';
|
||||
|
||||
public string $url = '';
|
||||
|
||||
public string $apiKey = '';
|
||||
|
||||
public string $feedback = '';
|
||||
|
||||
public bool $feedbackError = false;
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return ContentElementResource::editor();
|
||||
return ContentElementResource::editor() || static::canConfigure();
|
||||
}
|
||||
|
||||
/** Adresse und Schlüssel ändern dürfen nur Katalogverwalter und Systemverwalter. */
|
||||
public static function canConfigure(): bool
|
||||
{
|
||||
$user = Filament::auth()->user();
|
||||
|
||||
return $user instanceof User
|
||||
&& ($user->hasStaffRole(StaffRole::Katalogverwalter) || $user->hasStaffRole(StaffRole::Systemverwalter));
|
||||
}
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->url = app(ShinkanConnection::class)->source('url') === ShinkanConnection::ADMIN ? (string) app(ShinkanConnection::class)->url() : '';
|
||||
}
|
||||
|
||||
public function saveConnection(): void
|
||||
{
|
||||
abort_unless(static::canConfigure(), 403);
|
||||
|
||||
try {
|
||||
$user = Filament::auth()->user();
|
||||
app(ShinkanConnection::class)->save($this->url, $this->apiKey, $user instanceof User ? $user : null);
|
||||
$this->apiKey = '';
|
||||
$this->feedbackError = false;
|
||||
$this->feedback = 'Die Anbindung ist gespeichert. Werte aus der Umgebung des Servers haben weiterhin Vorrang. Prüfe die Verbindung, bevor du den Katalog abrufst.';
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->feedbackError = true;
|
||||
$this->feedback = $exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public function removeKey(): void
|
||||
{
|
||||
abort_unless(static::canConfigure(), 403);
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
app(ShinkanConnection::class)->forgetKey($user instanceof User ? $user : null);
|
||||
$this->feedbackError = false;
|
||||
$this->feedback = 'Der in der Verwaltung gepflegte Zugangsschlüssel ist entfernt.';
|
||||
}
|
||||
|
||||
public function getHeading(): string|Htmlable|null
|
||||
@@ -124,6 +170,7 @@ public function daten(): array
|
||||
'zeilen' => $rows,
|
||||
'eingerichtet' => app(ShinkanImport::class)->configured(),
|
||||
'anbindung' => app(ShinkanImport::class)->status(),
|
||||
'darfAendern' => static::canConfigure(),
|
||||
'letzterLauf' => ExerciseImportRun::query()->orderByDesc('id')->first(),
|
||||
];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user