Detect group hierarchy loops and break them.

This commit is contained in:
Isaac Connor 2021-12-03 12:03:23 -05:00
parent ea0e65d300
commit 756aa56710
1 changed files with 10 additions and 1 deletions

View File

@ -167,9 +167,15 @@ class Group extends ZM_Object {
public function Parents() {
$Parents = array();
$Parent = $this->Parent();
$seen_parents = array();
while ($Parent) {
$seen_parents[$Parent->Id()] = $Parent;
array_unshift($Parents, $Parent);
$Parent = $Parent->Parent();
if ($Parent and isset($seen_parents[$Parent->Id()])) {
Warning("Detected hierarchy loop in group {$Parent->Name()}");
break;
}
}
return $Parents;
}
@ -189,6 +195,9 @@ class Group extends ZM_Object {
public function canView($u=null) {
global $user;
if (!$u) $u = $user;
if (!count($this->Monitors()) and !count($this->Children())) {
return true;
}
# Can view if we can view any of the monitors in it.
foreach ($this->Monitors() as $monitor) {
if ($monitor->canView($u)) return true;