feat: add branch overviews scoped outdoor plans and complete room moves
This commit is contained in:
1 parent
0cc4b35995
commit
9374ac9e35
9 files changed
+1144
-1025
No files matched your search
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
require __DIR__ . '/support/access-runtime.php';
|
||||
$module = new AccessFixtureModule(); initializeAccessFixture($module);
|
||||
$method = static fn(string $name, mixed ...$args): mixed => (new ReflectionMethod($module, $name))->invoke($module, ...$args);
|
||||
$as = static function (string $name) use ($module, $method): void {
|
||||
foreach ($method('accounts') as $id => $a) if ($a['name'] === $name) {
|
||||
(new ReflectionProperty(NextFloor::class, 'requestUser'))->setValue($module, [...$a, 'id' => $id, 'session_id' => 'fixture-' . $name, 'csrf' => 'fixture']);
|
||||
(new ReflectionProperty(NextFloor::class, 'requestScope'))->setValue($module, null); return;
|
||||
}
|
||||
};
|
||||
$before = $method('building'); $after = $before;
|
||||
$source = &$after['floors'][0];
|
||||
$target = [...$source, 'id' => 'og', 'name' => 'Obergeschoss', 'elevation' => 3, 'rooms' => [], 'furniture' => [], 'placements' => []];
|
||||
$target['rooms'][] = array_shift($source['rooms']);
|
||||
$target['furniture'][] = array_shift($source['furniture']);
|
||||
$target['placements'][] = array_shift($source['placements']);
|
||||
unset($source); $after['floors'][] = $target;
|
||||
$as('admin'); $method('saveBuilding', $after);
|
||||
$accounts = array_column($method('accounts'), null, 'name');
|
||||
check($accounts['office']['rooms'] === [['target' => 'room:og:office2', 'access' => 'control']], 'Room control rights follow the moved room');
|
||||
check($accounts['officeview']['rooms'] === [['target' => 'room:og:office2', 'access' => 'view']], 'Readonly room rights stay readonly');
|
||||
check($accounts['device']['devices'] === [['target' => 'furniture:og:wallbox', 'access' => 'control']], 'Explicit device rights follow its unique identity');
|
||||
check($accounts['empty']['rooms'] === [] && $accounts['empty']['devices'] === [], 'Moving cannot create a new grant');
|
||||
$as('office'); $tree = $method('visibleTree', $method('objectTree'));
|
||||
$ids = array_column(array_column($tree['variables'], 'attributes'), 'symcon_id'); sort($ids);
|
||||
check($ids === [101, 102, 103, 104, 105], 'The moved room still exposes exactly its original native variables');
|
||||
$as('device'); $method('authorizeApi', 'variables/action', ['data' => ['entity_id' => 'light.102']]);
|
||||
$as('admin'); $method('saveBuilding', $before);
|
||||
$accounts = array_column($method('accounts'), null, 'name');
|
||||
check($accounts['office']['rooms'][0]['target'] === 'room:eg:office2', 'Undo restores the original grant key');
|
||||
check($accounts['device']['devices'][0]['target'] === 'furniture:eg:wallbox', 'Undo also restores the explicit device key');
|
||||
|
||||
// An ambiguous ID may be a duplicate rather than a move; never guess and widen its grant.
|
||||
$ambiguous = $after; $ambiguous['floors'][0]['furniture'][] = $target['furniture'][0];
|
||||
$method('saveBuilding', $ambiguous);
|
||||
$accounts = array_column($method('accounts'), null, 'name');
|
||||
check($accounts['device']['devices'][0]['target'] === 'furniture:eg:wallbox', 'Duplicate identities never trigger automatic grant migration');
|
||||
echo "OK: room/device grants follow unique floor moves and undo, preserve view/control levels and native visibility, reject ambiguous identities and create no grants\n";
|
||||
+5
-1
@@ -19,11 +19,15 @@ $b['floors'][0]['building_id'] = 'ras19';
|
||||
$outside = ['id' => 'garden', 'name' => 'Außen', 'building_id' => null, 'outdoor_location_id' => 'urbach', 'elevation' => 0, 'height' => 2.5,
|
||||
'rooms' => [], 'openings' => [], 'placements' => [], 'outdoor' => [], 'furniture' => [['id' => 'garden-meter', 'type' => 'wallbox', 'name' => 'Gartengerät', 'entity' => 'sensor.203', 'x' => 1, 'z' => 2]]];
|
||||
$b['floors'][] = $outside;
|
||||
$b['floors'][] = [...$outside, 'id' => 'branch-garden', 'outdoor_location_id' => null, 'outdoor_branch_id' => 'hq', 'furniture' => [[...$outside['furniture'][0], 'id' => 'branch-meter', 'name' => 'Hofgerät']]];
|
||||
$b['floors'][] = [...$outside, 'id' => 'building-garden', 'outdoor_location_id' => null, 'outdoor_building_id' => 'ras19', 'furniture' => [[...$outside['furniture'][0], 'id' => 'building-meter', 'name' => 'Terrassengerät']]];
|
||||
$as('admin'); $method('authorizeApi', 'building/save', ['building' => $b]); $method('saveBuilding', $b);
|
||||
check($method('building')['topology'] === $b['topology'], 'The complete hierarchy persists without changing native links');
|
||||
$form = $module->GetConfigurationForm();
|
||||
check(str_contains($form, 'Urbach / Zentrale / RAS19 / Erdgeschoss / Büro 2'), 'Room choices include their complete topology path');
|
||||
check(str_contains($form, 'Urbach / Außen / Gartengerät'), 'Outdoor device grants belong to the location path');
|
||||
check(str_contains($form, 'Urbach / Zentrale / Außen / Hofgerät'), 'Branch outdoor device grants use their own full path');
|
||||
check(str_contains($form, 'Urbach / Zentrale / RAS19 / Außen / Terrassengerät'), 'Building outdoor device grants use their own full path');
|
||||
|
||||
$as('office');
|
||||
$tree = $method('visibleTree', $method('objectTree'));
|
||||
@@ -34,4 +38,4 @@ check($visible['topology'] === $b['topology'], 'Users retain the complete logica
|
||||
check($visible['floors'][1]['furniture'][0]['entity'] === 'none', 'Unapproved outdoor status is still filtered server-side');
|
||||
$as('empty');
|
||||
check($method('visibleTree', $method('objectTree'))['variables'] === [], 'Adding topology cannot grant access to an empty account');
|
||||
echo "OK: persisted five-level topology and location outdoors; complete grant choice paths; unchanged room keys; scoped state and native permissions\n";
|
||||
echo "OK: persisted five-level topology with location/branch/building outdoors; complete grant choice paths; unchanged room keys; scoped state and native permissions\n";
|
||||
Reference in new issue
Block a user