Detect group hierarchy loops and break them.

This commit is contained in:
Isaac Connor 2021-12-03 12:03:23 -05:00
parent 5f9dcabee1
commit 1277e75278
1 changed files with 10 additions and 1 deletions

View File

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