Detect group hierarchy loops and break them.
This commit is contained in:
parent
ea0e65d300
commit
756aa56710
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue