From bf224b58f8824315ef431ed42b4a1e70ad84b71a Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 17 Oct 2021 23:39:18 +0200 Subject: [PATCH] Move to PermissionSet::isPublic() --- .../PermissionSet/Depository/PermissionSet.php | 14 ++------------ .../PermissionSet/Entity/PermissionSet.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Security/PermissionSet/Depository/PermissionSet.php b/src/Security/PermissionSet/Depository/PermissionSet.php index 09ecceaf0..b91f45218 100644 --- a/src/Security/PermissionSet/Depository/PermissionSet.php +++ b/src/Security/PermissionSet/Depository/PermissionSet.php @@ -86,16 +86,6 @@ class PermissionSet extends BaseDepository return new Collection\PermissionSets(parent::_select($condition, $params)->getArrayCopy()); } - private function checkPublic(Entity\PermissionSet $permissionSet): bool - { - return (($permissionSet->id === self::PUBLIC) || - (is_null($permissionSet->id) && - empty($permissionSet->allow_cid) && - empty($permissionSet->allow_gid) && - empty($permissionSet->deny_cid) && - empty($permissionSet->deny_gid))); - } - /** * Converts a given PermissionSet into a DB compatible row array * @@ -221,7 +211,7 @@ class PermissionSet extends BaseDepository } // Don't select/update Public permission sets - if ($this->checkPublic($permissionSet)) { + if ($permissionSet->isPublic()) { return $this->selectPublicForUser($permissionSet->uid); } @@ -241,7 +231,7 @@ class PermissionSet extends BaseDepository public function save(Entity\PermissionSet $permissionSet): Entity\PermissionSet { // Don't save/update the common public PermissionSet - if ($this->checkPublic($permissionSet)) { + if ($permissionSet->isPublic()) { return $this->selectPublicForUser($permissionSet->uid); } diff --git a/src/Security/PermissionSet/Entity/PermissionSet.php b/src/Security/PermissionSet/Entity/PermissionSet.php index 849871647..6a0409331 100644 --- a/src/Security/PermissionSet/Entity/PermissionSet.php +++ b/src/Security/PermissionSet/Entity/PermissionSet.php @@ -3,6 +3,7 @@ namespace Friendica\Security\PermissionSet\Entity; use Friendica\BaseEntity; +use Friendica\Security\PermissionSet\Depository\PermissionSet as PermissionSetDepository; /** * @property-read int|null $id @@ -47,6 +48,21 @@ class PermissionSet extends BaseEntity $this->deny_gid = $deny_gid; } + /** + * Checks, if the current PermissionSet is a/the public PermissionSet + * + * @return bool + */ + public function isPublic(): bool + { + return (($this->id === PermissionSetDepository::PUBLIC) || + (is_null($this->id) && + empty($this->allow_cid) && + empty($this->allow_gid) && + empty($this->deny_cid) && + empty($this->deny_gid))); + } + /** * Creates a new Entity with a new allowed_cid list (wipes the id because it isn't the same entity anymore) *