Neues Plugin IT-Service (OpenNIT); Abteilung bei „Geschrieben von“
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 4m42s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m41s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m32s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m7s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m30s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m35s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 4m42s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m41s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m32s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m7s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m30s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m35s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c713194a83
commit
c1117829c3
139 changed files with 2455 additions and 398 deletions
94
plugins-core/it-service/src/OpenNit/Settings.php
Normal file
94
plugins-core/it-service/src/OpenNit/Settings.php
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\ItService\OpenNit;
|
||||
|
||||
use App\Support\Settings as PortalSettings;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Zugangsdaten zu OpenNIT. Token und Signing-Secret liegen verschlüsselt in den Einstellungen.
|
||||
*/
|
||||
class Settings
|
||||
{
|
||||
public const URL = 'it_service.url';
|
||||
|
||||
public const TOKEN = 'it_service.token';
|
||||
|
||||
public const SECRET = 'it_service.secret';
|
||||
|
||||
/** null = Einstellung in OpenNIT, true = sofort reservieren, false = immer Anfrage */
|
||||
public const AUTO_RESERVE = 'it_service.auto_reserve';
|
||||
|
||||
public const INTRO = 'it_service.intro';
|
||||
|
||||
public function __construct(private readonly PortalSettings $settings) {}
|
||||
|
||||
public function url(): string
|
||||
{
|
||||
return rtrim((string) $this->settings->get(self::URL, ''), '/');
|
||||
}
|
||||
|
||||
public function token(): string
|
||||
{
|
||||
return $this->decrypt(self::TOKEN);
|
||||
}
|
||||
|
||||
public function secret(): string
|
||||
{
|
||||
return $this->decrypt(self::SECRET);
|
||||
}
|
||||
|
||||
public function configured(): bool
|
||||
{
|
||||
return $this->url() !== '' && $this->token() !== '' && $this->secret() !== '';
|
||||
}
|
||||
|
||||
public function autoReserve(): ?bool
|
||||
{
|
||||
$value = $this->settings->get(self::AUTO_RESERVE);
|
||||
|
||||
return $value === null ? null : (bool) $value;
|
||||
}
|
||||
|
||||
public function intro(): ?string
|
||||
{
|
||||
return $this->settings->get(self::INTRO) ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{url: string, token?: ?string, secret?: ?string, auto_reserve: ?string, intro: ?string} $data leere Token/Secret = unverändert
|
||||
*/
|
||||
public function save(array $data): void
|
||||
{
|
||||
$this->settings->set(self::URL, rtrim(trim($data['url']), '/'));
|
||||
|
||||
foreach ([self::TOKEN => $data['token'] ?? null, self::SECRET => $data['secret'] ?? null] as $key => $value) {
|
||||
if (filled($value)) {
|
||||
$this->settings->set($key, Crypt::encryptString(trim($value)));
|
||||
}
|
||||
}
|
||||
|
||||
$this->settings->set(self::AUTO_RESERVE, match ($data['auto_reserve'] ?? '') {
|
||||
'yes' => true,
|
||||
'no' => false,
|
||||
default => null,
|
||||
});
|
||||
$this->settings->set(self::INTRO, $data['intro'] ?? null);
|
||||
}
|
||||
|
||||
private function decrypt(string $key): string
|
||||
{
|
||||
$value = $this->settings->get($key);
|
||||
|
||||
if (! is_string($value) || $value === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
return Crypt::decryptString($value);
|
||||
} catch (Throwable) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue