Enforce topology rules and fix device deletion flow
This commit is contained in:
@@ -77,6 +77,19 @@ function endpointExists($sql, string $type, int $id): bool
|
||||
return false;
|
||||
}
|
||||
|
||||
function isTopologyPairAllowed(string $typeA, string $typeB): bool
|
||||
{
|
||||
$allowed = ['device' => true, 'module' => true, 'outlet' => true, 'patchpanel' => true];
|
||||
if (!isset($allowed[$typeA]) || !isset($allowed[$typeB])) {
|
||||
return false;
|
||||
}
|
||||
if ($typeA === 'patchpanel' || $typeB === 'patchpanel') {
|
||||
return ($typeA === 'patchpanel' && in_array($typeB, ['patchpanel', 'outlet'], true))
|
||||
|| ($typeB === 'patchpanel' && in_array($typeA, ['patchpanel', 'outlet'], true));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function loadConnections($sql): void
|
||||
{
|
||||
$contextType = strtolower(trim((string)($_GET['context_type'] ?? 'all')));
|
||||
@@ -189,6 +202,9 @@ function saveConnection($sql): void
|
||||
if ($portAId <= 0 || $portBId <= 0) {
|
||||
jsonError('port_a_id und port_b_id sind erforderlich', 400);
|
||||
}
|
||||
if (!isTopologyPairAllowed($portAType, $portBType)) {
|
||||
jsonError('Patchpanel-Ports duerfen nur mit Patchpanel-Ports oder Netzwerkdosen-Ports verbunden werden', 400);
|
||||
}
|
||||
|
||||
if ($portAType === $portBType && $portAId === $portBId) {
|
||||
jsonError('Port A und Port B duerfen nicht identisch sein', 400);
|
||||
|
||||
Reference in New Issue
Block a user