<?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
namespace Friendica\Repository;
-use Friendica\BaseModel;
use Friendica\BaseRepository;
use Friendica\Collection;
-use Friendica\Core\L10n;
-use Friendica\Database\DBA;
-use Friendica\DI;
+use Friendica\Database\Database;
use Friendica\Model;
use Friendica\Model\Group;
use Friendica\Network\HTTPException;
+use Friendica\Util\ACLFormatter;
+use Psr\Log\LoggerInterface;
class PermissionSet extends BaseRepository
{
+ /** @var int Virtual permission set id for public permission */
+ const PUBLIC = 0;
+
protected static $table_name = 'permissionset';
protected static $model_class = Model\PermissionSet::class;
protected static $collection_class = Collection\PermissionSets::class;
+ /** @var ACLFormatter */
+ private $aclFormatter;
+
+ public function __construct(Database $dba, LoggerInterface $logger, ACLFormatter $aclFormatter)
+ {
+ parent::__construct($dba, $logger);
+
+ $this->aclFormatter = $aclFormatter;
+ }
+
/**
* @param array $data
* @return Model\PermissionSet
{
if (isset($condition['id']) && !$condition['id']) {
return $this->create([
- 'id' => 0,
+ 'id' => self::PUBLIC,
'uid' => $condition['uid'] ?? 0,
'allow_cid' => '',
'allow_gid' => '',
string $deny_cid = null,
string $deny_gid = null
) {
- $ACLFormatter = DI::aclFormatter();
-
- $allow_cid = $ACLFormatter->sanitize($allow_cid);
- $allow_gid = $ACLFormatter->sanitize($allow_gid);
- $deny_cid = $ACLFormatter->sanitize($deny_cid);
- $deny_gid = $ACLFormatter->sanitize($deny_gid);
+ $allow_cid = $this->aclFormatter->sanitize($allow_cid);
+ $allow_gid = $this->aclFormatter->sanitize($allow_gid);
+ $deny_cid = $this->aclFormatter->sanitize($deny_cid);
+ $deny_gid = $this->aclFormatter->sanitize($deny_gid);
// Public permission
if (!$allow_cid && !$allow_gid && !$deny_cid && !$deny_gid) {
- return 0;
+ return self::PUBLIC;
}
$condition = [
public function selectByContactId($contact_id, $uid)
{
$groups = [];
- if (DBA::exists('contact', ['id' => $contact_id, 'uid' => $uid, 'blocked' => false])) {
+ if ($this->dba->exists('contact', ['id' => $contact_id, 'uid' => $uid, 'blocked' => false])) {
$groups = Group::getIdsByContactId($contact_id);
}