3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Security\PermissionSet\Entity;
24 use Friendica\BaseEntity;
25 use Friendica\Security\PermissionSet\Repository\PermissionSet as PermissionSetRepository;
28 * @property-read int|null $id
29 * @property-read int $uid
30 * @property-read string[] $allow_cid
31 * @property-read string[] $allow_gid
32 * @property-read string[] $deny_cid
33 * @property-read string[] $deny_gid
35 class PermissionSet extends BaseEntity
53 * @param string[] $allow_cid
54 * @param string[] $allow_gid
55 * @param string[] $deny_cid
56 * @param string[] $deny_gid
58 * @see \Friendica\Security\PermissionSet\Factory\PermissionSet
60 public function __construct(int $uid, array $allow_cid = [], array $allow_gid = [], array $deny_cid = [], array $deny_gid = [], int $id = null)
64 $this->allow_cid = $allow_cid;
65 $this->allow_gid = $allow_gid;
66 $this->deny_cid = $deny_cid;
67 $this->deny_gid = $deny_gid;
71 * Checks, if the current PermissionSet is a/the public PermissionSet
75 public function isPublic(): bool
77 return (($this->id === PermissionSetRepository::PUBLIC) ||
78 (is_null($this->id) &&
79 empty($this->allow_cid) &&
80 empty($this->allow_gid) &&
81 empty($this->deny_cid) &&
82 empty($this->deny_gid)));
86 * Creates a new Entity with a new allowed_cid list (wipes the id because it isn't the same entity anymore)
88 * @param array $allow_cid
92 public function withAllowedContacts(array $allow_cid): PermissionSet
96 $clone->allow_cid = $allow_cid;