getOwner())) return false; return $own->guid == $this->guid; } /* * Check whether this agent is a member of the given object */ public function isMemberOf(obj $obj) : bool { foreach ($obj->getMembers() as $memb) { if ($memb->guid == $this->guid) return true; } return false; } /* * Check whether this agent is assigned to the given issue */ public function isAssignedTo(issue $issue) : bool { foreach ($issue->getAssignees() as $assign) { if ($assign->assignee->guid == $this->guid && $assign->signedoff == "" && $assign->dismissed == "") return true; } return false; } /* * Get all contained users. For users, this is an array containing * only $this. For groups, this is an array containing the owner * and all members. */ public abstract function getContainedUsers() : array; /* * Send an email message to this agent using stored configuration * parameters. If config is not established, delivery is not * attempted. Return status. */ public abstract function sendEmail(string $subj, string $mesg, ?string $attachPath = NULL, ?string $attachName = NULL, bool $ignoreEmailConf = false) : bool; /* * Get the display name for this agent. For groups this is the * object name; for users, this is the object name, unless an * alias is set. */ public function getDisplayName() : string { if ($this->objtype != "user") return $this->name; $user = new user($this->guid); if ($user->alias != "") return $user->alias; return $user->name; } /* * Get all pads this agent owns or is a member of. This isn't * necessarily all pads this agent has access permission for. * Results are sorted by ownership, then by name. */ public function getPads_ordByOwnByName() : array { $pads = array(); /* owner */ $query = "SELECT guid FROM objects WHERE objtype = 'pad' AND " . "owner = '" . database::esc($this->guid) . "' ORDER BY name"; $res = database::query($query); foreach ($res as $p) $pads[] = new pad($p['guid']); /* members */ $query = "SELECT o.guid FROM objects o JOIN members m ON " . "o.guid = m.guid WHERE o.objtype = 'pad' AND " . "m.member = '" . database::esc($this->guid) . "' ORDER BY o.name"; $res = database::query($query); foreach ($res as $p) $pads[] = new pad($p['guid']); return $pads; } /* * Check whether this agent has access permission for given * object */ public function canAccess(obj $obj) : bool { if ($this->admin) return true; if ($this->guid == $obj->guid) return true; if ($this->isOwnerOf($obj)) return true; if ($this->isMemberOf($obj)) return true; if ($obj->pubAcc) return true; if ($obj->parent) { $parent = new obj($obj->parent); if ($this->canAccessSub($parent)) return true; } else if ($obj->owner) { $owner = new obj($obj->owner); if ($this->canAccessSub($owner)) return true; } return false; } /* * Check whether this agent has modify permission for given * object */ public function canModify(obj $obj) : bool { if ($this->admin) return true; if ($this->guid == $obj->guid) return true; if ($this->isOwnerOf($obj)) return true; if ($this->isMemberOf($obj) && $obj->membModify) return true; if ($obj->parent) { $parent = new obj($obj->parent); if ($this->canModifySub($parent)) return true; } else if ($obj->owner) { $owner = new obj($obj->owner); if ($this->canModifySub($owner)) return true; } return false; } /* * Check whether this agent has modify members permission for * given object */ public function canModifyMembers(obj $obj) : bool { if ($this->admin) return true; if ($this->guid == $obj->guid) return true; if ($this->isOwnerOf($obj)) return true; if ($this->isMemberOf($obj) && $obj->membMemb) return true; if ($obj->parent) { $parent = new obj($obj->parent); if ($this->canModifySubMembers($parent)) return true; } else if ($obj->owner) { $owner = new obj($obj->owner); if ($this->canModifySubMembers($owner)) return true; } return false; } /* * Check whether this agent has modify permissions permission * for given object */ public function canModifyPermissions(obj $obj) : bool { if ($this->admin) return true; if ($this->guid == $obj->guid) return true; if ($this->isOwnerOf($obj)) return true; if ($obj->parent) { $parent = new obj($obj->parent); if ($this->canModifySubPermissions($parent)) return true; } else if ($obj->owner) { $owner = new obj($obj->owner); if ($this->canModifySubPermissions($owner)) return true; } return false; } /* * Check whether this agent has access-sub permission for * given object */ public function canAccessSub(obj $obj) : bool { if ($this->admin) return true; if ($this->guid == $obj->guid) return true; if ($this->isOwnerOf($obj)) return true; if ($this->isMemberOf($obj) && $obj->membAccs) return true; if ($obj->pubAccs) return true; if ($obj->parent) { $parent = new obj($obj->parent); if ($this->canAccessSub($parent)) return true; } else if ($obj->owner) { $owner = new obj($obj->owner); if ($this->canAccessSub($owner)) return true; } return false; } /* * Check whether this agent has create-sub permission * for given object */ public function canCreateSub(obj $obj) : bool { if ($this->admin) return true; if ($this->guid == $obj->guid) return true; if ($this->isOwnerOf($obj)) return true; if ($this->isMemberOf($obj) && $obj->membCres) return true; if ($obj->pubCres) return true; if ($obj->parent) { $parent = new obj($obj->parent); if ($this->canCreateSub($parent)) return true; } else if ($obj->owner) { $owner = new obj($obj->owner); if ($this->canCreateSub($owner)) return true; } return false; } /* * Check whether this agent has modify-sub permission * for given object */ public function canModifySub(obj $obj) : bool { if ($this->admin) return true; if ($this->guid == $obj->guid) return true; if ($this->isOwnerOf($obj)) return true; if ($this->isMemberOf($obj) && $obj->membModifys) return true; if ($obj->parent) { $parent = new obj($obj->parent); if ($this->canModifySub($parent)) return true; } else if ($obj->owner) { $owner = new obj($obj->owner); if ($this->canModifySub($owner)) return true; } return false; } /* * Check whether this agent has modify-sub-members * permission for given object */ public function canModifySubMembers(obj $obj) : bool { if ($this->admin) return true; if ($this->guid == $obj->guid) return true; if ($this->isOwnerOf($obj)) return true; if ($this->isMemberOf($obj) && $obj->membMembs) return true; if ($obj->parent) { $parent = new obj($obj->parent); if ($this->canModifySubMembers($parent)) return true; } else if ($obj->owner) { $owner = new obj($obj->owner); if ($this->canModifySubMembers($owner)) return true; } return false; } /* * Check whether this agent has modify-sub-permissions * permission for given object */ public function canModifySubPermissions(obj $obj) : bool { if ($this->admin) return true; if ($this->guid == $obj->guid) return true; if ($this->isOwnerOf($obj)) return true; if ($obj->parent) { $parent = new obj($obj->parent); if ($this->canModifySubPermissions($parent)) return true; } else if ($obj->owner) { $owner = new obj($obj->owner); if ($this->canModifySubPermissions($owner)) return true; } return false; } } ?>