Move to PermissionSet::isPublic()

This commit is contained in:
Philipp Holzer 2021-10-17 23:39:18 +02:00
parent caa977c24e
commit bf224b58f8
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432
2 changed files with 18 additions and 12 deletions

View file

@ -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);
}

View file

@ -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)
*