40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once dirname(__DIR__, 4) . '/src/App/bootstrap.php';
|
|
|
|
use App\ConfigLoader;
|
|
use App\GiteaDeployStatusService;
|
|
|
|
session_start();
|
|
|
|
$authUser = is_array($_SESSION['desktop_auth']['user'] ?? null) ? $_SESSION['desktop_auth']['user'] : [];
|
|
$groups = array_values(array_map('strval', (array) ($authUser['groups'] ?? [])));
|
|
$isAdmin = in_array('administrators', $groups, true);
|
|
|
|
$projectRoot = dirname(__DIR__, 4);
|
|
$service = new GiteaDeployStatusService(ConfigLoader::load($projectRoot, 'gitea'));
|
|
|
|
if (!$service->shouldShowInTray($isAdmin)) {
|
|
respond([
|
|
'error' => 'forbidden',
|
|
'message' => 'Kein Zugriff auf den Gitea-Deploy-Status.',
|
|
], 403);
|
|
}
|
|
|
|
respond([
|
|
'data' => $service->status(),
|
|
]);
|
|
|
|
/**
|
|
* @param array<string, mixed> $payload
|
|
*/
|
|
function respond(array $payload, int $statusCode = 200): never
|
|
{
|
|
http_response_code($statusCode);
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
echo json_encode($payload, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|