2018-10-30 20:24:15 +03:00
|
|
|
<?php
|
|
|
|
|
2019-12-03 21:57:53 +03:00
|
|
|
declare(strict_types=1);
|
2018-10-30 20:24:15 +03:00
|
|
|
|
|
|
|
/**
|
2019-12-03 21:57:53 +03:00
|
|
|
* @copyright 2018
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @author Maxence Lange <maxence@artificial-owl.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
*
|
2018-10-30 20:24:15 +03:00
|
|
|
* @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
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-02-20 13:38:19 +03:00
|
|
|
namespace OC\FullTextSearch\Model;
|
2018-10-30 20:24:15 +03:00
|
|
|
|
|
|
|
use JsonSerializable;
|
2019-02-20 13:38:19 +03:00
|
|
|
use OCP\FullTextSearch\Model\IDocumentAccess;
|
2018-10-30 20:24:15 +03:00
|
|
|
|
|
|
|
/**
|
2019-02-20 13:38:19 +03:00
|
|
|
* Class IDocumentAccess
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* This object is used as a data transfer object when
|
|
|
|
*
|
|
|
|
* - indexing a document,
|
|
|
|
* - generating a search request.
|
|
|
|
*
|
|
|
|
* During the index, it is used to define which users, groups, circles, ...
|
|
|
|
* have access to the IndexDocument
|
|
|
|
*
|
|
|
|
* During the search, it is internally use to define to which group, circles, ...
|
|
|
|
* a user that perform the search belongs to.
|
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* @see IIndexDocument::setAccess
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* @package OC\FullTextSearch\Model
|
2018-10-30 20:24:15 +03:00
|
|
|
*/
|
2019-02-20 13:38:19 +03:00
|
|
|
final class DocumentAccess implements IDocumentAccess, JsonSerializable {
|
|
|
|
|
2018-10-30 20:24:15 +03:00
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $ownerId;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $viewerId = '';
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $users = [];
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $groups = [];
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $circles = [];
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $links = [];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Owner of the document can be set at the init of the object.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* IDocumentAccess constructor.
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @param string $ownerId
|
|
|
|
*/
|
|
|
|
public function __construct(string $ownerId = '') {
|
|
|
|
$this->setOwnerId($ownerId);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the Owner of the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @param string $ownerId
|
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* @return IDocumentAccess
|
2018-10-30 20:24:15 +03:00
|
|
|
*/
|
2019-02-20 13:38:19 +03:00
|
|
|
public function setOwnerId(string $ownerId): IDocumentAccess {
|
2018-10-30 20:24:15 +03:00
|
|
|
$this->ownerId = $ownerId;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Owner of the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getOwnerId(): string {
|
|
|
|
return $this->ownerId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the viewer of the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @param string $viewerId
|
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* @return IDocumentAccess
|
2018-10-30 20:24:15 +03:00
|
|
|
*/
|
2019-02-20 13:38:19 +03:00
|
|
|
public function setViewerId(string $viewerId): IDocumentAccess {
|
2018-10-30 20:24:15 +03:00
|
|
|
$this->viewerId = $viewerId;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the viewer of the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getViewerId(): string {
|
|
|
|
return $this->viewerId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the list of users that have read access to the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @param array $users
|
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* @return IDocumentAccess
|
2018-10-30 20:24:15 +03:00
|
|
|
*/
|
2019-02-20 13:38:19 +03:00
|
|
|
public function setUsers(array $users): IDocumentAccess {
|
2018-10-30 20:24:15 +03:00
|
|
|
$this->users = $users;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an entry to the list of users that have read access to the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @param string $user
|
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* @return IDocumentAccess
|
2018-10-30 20:24:15 +03:00
|
|
|
*/
|
2019-02-20 13:38:19 +03:00
|
|
|
public function addUser(string $user): IDocumentAccess {
|
2018-10-30 20:24:15 +03:00
|
|
|
$this->users[] = $user;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add multiple entries to the list of users that have read access to the
|
|
|
|
* document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @param array $users
|
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* @return IDocumentAccess
|
2018-10-30 20:24:15 +03:00
|
|
|
*/
|
2019-02-20 13:38:19 +03:00
|
|
|
public function addUsers($users): IDocumentAccess {
|
2018-10-30 20:24:15 +03:00
|
|
|
$this->users = array_merge($this->users, $users);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the complete list of users that have read access to the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getUsers(): array {
|
|
|
|
return $this->users;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the list of groups that have read access to the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @param array $groups
|
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* @return IDocumentAccess
|
2018-10-30 20:24:15 +03:00
|
|
|
*/
|
2019-02-20 13:38:19 +03:00
|
|
|
public function setGroups(array $groups): IDocumentAccess {
|
2018-10-30 20:24:15 +03:00
|
|
|
$this->groups = $groups;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an entry to the list of groups that have read access to the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @param string $group
|
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* @return IDocumentAccess
|
2018-10-30 20:24:15 +03:00
|
|
|
*/
|
2019-02-20 13:38:19 +03:00
|
|
|
public function addGroup(string $group): IDocumentAccess {
|
2018-10-30 20:24:15 +03:00
|
|
|
$this->groups[] = $group;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add multiple entries to the list of groups that have read access to the
|
|
|
|
* document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @param array $groups
|
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* @return IDocumentAccess
|
2018-10-30 20:24:15 +03:00
|
|
|
*/
|
|
|
|
public function addGroups(array $groups) {
|
|
|
|
$this->groups = array_merge($this->groups, $groups);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the complete list of groups that have read access to the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getGroups(): array {
|
|
|
|
return $this->groups;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the list of circles that have read access to the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @param array $circles
|
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* @return IDocumentAccess
|
2018-10-30 20:24:15 +03:00
|
|
|
*/
|
2019-02-20 13:38:19 +03:00
|
|
|
public function setCircles(array $circles): IDocumentAccess {
|
2018-10-30 20:24:15 +03:00
|
|
|
$this->circles = $circles;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an entry to the list of circles that have read access to the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @param string $circle
|
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* @return IDocumentAccess
|
2018-10-30 20:24:15 +03:00
|
|
|
*/
|
2019-02-20 13:38:19 +03:00
|
|
|
public function addCircle(string $circle): IDocumentAccess {
|
2018-10-30 20:24:15 +03:00
|
|
|
$this->circles[] = $circle;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add multiple entries to the list of groups that have read access to the
|
|
|
|
* document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @param array $circles
|
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* @return IDocumentAccess
|
2018-10-30 20:24:15 +03:00
|
|
|
*/
|
2019-02-20 13:38:19 +03:00
|
|
|
public function addCircles(array $circles): IDocumentAccess {
|
2018-10-30 20:24:15 +03:00
|
|
|
$this->circles = array_merge($this->circles, $circles);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the complete list of circles that have read access to the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getCircles(): array {
|
|
|
|
return $this->circles;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the list of links that have read access to the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @param array $links
|
|
|
|
*
|
2019-02-20 13:38:19 +03:00
|
|
|
* @return IDocumentAccess
|
2018-10-30 20:24:15 +03:00
|
|
|
*/
|
2019-02-20 13:38:19 +03:00
|
|
|
public function setLinks(array $links): IDocumentAccess {
|
2018-10-30 20:24:15 +03:00
|
|
|
$this->links = $links;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of links that have read access to the document.
|
|
|
|
*
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getLinks(): array {
|
|
|
|
return $this->links;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-03-04 13:49:29 +03:00
|
|
|
* @since 16.0.0
|
2018-10-30 20:24:15 +03:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function jsonSerialize(): array {
|
|
|
|
return [
|
|
|
|
'ownerId' => $this->getOwnerId(),
|
|
|
|
'viewerId' => $this->getViewerId(),
|
|
|
|
'users' => $this->getUsers(),
|
|
|
|
'groups' => $this->getGroups(),
|
|
|
|
'circles' => $this->getCircles(),
|
|
|
|
'links' => $this->getLinks()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|