diff --git a/src/permission/PermissibleBase.php b/src/permission/PermissibleBase.php index cfab34bc3..2856ed75f 100644 --- a/src/permission/PermissibleBase.php +++ b/src/permission/PermissibleBase.php @@ -146,13 +146,13 @@ class PermissibleBase implements Permissible{ if($perm === null){ throw new \InvalidStateException("Unregistered root permission $name"); } - $this->permissions[$name] = new PermissionAttachmentInfo($name, null, $isGranted); + $this->permissions[$name] = new PermissionAttachmentInfo($name, null, $isGranted, null); $permManager->subscribeToPermission($name, $this); - $this->calculateChildPermissions($perm->getChildren(), !$isGranted, null); + $this->calculateChildPermissions($perm->getChildren(), !$isGranted, null, $this->permissions[$name]); } foreach($this->attachments as $attachment){ - $this->calculateChildPermissions($attachment->getPermissions(), false, $attachment); + $this->calculateChildPermissions($attachment->getPermissions(), false, $attachment, null); } $diff = []; @@ -189,16 +189,16 @@ class PermissibleBase implements Permissible{ /** * @param bool[] $children */ - private function calculateChildPermissions(array $children, bool $invert, ?PermissionAttachment $attachment) : void{ + private function calculateChildPermissions(array $children, bool $invert, ?PermissionAttachment $attachment, ?PermissionAttachmentInfo $parent) : void{ $permManager = PermissionManager::getInstance(); foreach($children as $name => $v){ $perm = $permManager->getPermission($name); $value = ($v xor $invert); - $this->permissions[$name] = new PermissionAttachmentInfo($name, $attachment, $value); + $this->permissions[$name] = new PermissionAttachmentInfo($name, $attachment, $value, $parent); $permManager->subscribeToPermission($name, $this); if($perm instanceof Permission){ - $this->calculateChildPermissions($perm->getChildren(), !$value, $attachment); + $this->calculateChildPermissions($perm->getChildren(), !$value, $attachment, $this->permissions[$name]); } } } diff --git a/src/permission/PermissionAttachmentInfo.php b/src/permission/PermissionAttachmentInfo.php index 3bb4f0c5b..b786d567e 100644 --- a/src/permission/PermissionAttachmentInfo.php +++ b/src/permission/PermissionAttachmentInfo.php @@ -33,10 +33,14 @@ class PermissionAttachmentInfo{ /** @var bool */ private $value; - public function __construct(string $permission, ?PermissionAttachment $attachment, bool $value){ + /** @var PermissionAttachmentInfo|null */ + private $groupPermission; + + public function __construct(string $permission, ?PermissionAttachment $attachment, bool $value, ?PermissionAttachmentInfo $groupPermission){ $this->permission = $permission; $this->attachment = $attachment; $this->value = $value; + $this->groupPermission = $groupPermission; } public function getPermission() : string{ @@ -50,4 +54,10 @@ class PermissionAttachmentInfo{ public function getValue() : bool{ return $this->value; } + + /** + * Returns the info of the permission group that caused this permission to be set, if any. + * If null, the permission was set explicitly, either by a permission attachment or base permission. + */ + public function getGroupPermissionInfo() : ?PermissionAttachmentInfo{ return $this->groupPermission; } }