refactor(vikon): fetch parts from VIKON API instead of hardcoded config

This commit is contained in:
F4ilji
2026-07-05 11:32:54 +05:00
parent 9a9521c570
commit 8cf195efb0
7 changed files with 36 additions and 41 deletions
@@ -49,10 +49,24 @@ class CheckAccessAction
];
}
// Extract parts per module from the API response
$partsByModule = [];
if (isset($body['tree_access']) && is_array($body['tree_access'])) {
foreach ($body['tree_access'] as $moduleId => $moduleData) {
if (isset($moduleData['parts']) && is_array($moduleData['parts'])) {
$partsByModule[$moduleId] = array_map(
fn($p) => ['id' => $p['id'], 'name' => $p['name'] ?? $p['id'], 'access' => $p['access'] ?? true],
$moduleData['parts']
);
}
}
}
return [
'has_access' => true,
'error' => null,
'modules_tree' => $body['tree_access'],
'parts' => $partsByModule,
];
} catch (\Throwable $e) {
Log::error('Vikon access check failed', ['error' => $e->getMessage()]);
@@ -24,11 +24,6 @@ class UpdatePartAction
{
$config = $this->modulesConfig[$moduleId] ?? throw new \RuntimeException("Unknown module: {$moduleId}");
$allowedParts = config('vikon.parts', [])[$moduleId] ?? [];
if (!in_array($part, $allowedParts, true)) {
throw new \RuntimeException("Invalid part '{$part}' for module {$moduleId}");
}
Log::info('Vikon: starting part update', ['module' => $moduleId, 'part' => $part]);
// Step 1: Request generation