migrate therinaldos.com data
Build & Deploy to DigitalOcean Space / build (push) Failing after 2m38s

This commit is contained in:
2024-05-05 15:50:45 -04:00
commit ef1ff240d4
23182 changed files with 3801898 additions and 0 deletions
@@ -0,0 +1,598 @@
<?php
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use OC;
use OCA\Circles\AppInfo\Application;
use OCP\IL10N;
class BaseCircle {
public const CIRCLES_SETTINGS_DEFAULT = [
'password_enforcement' => 'false',
'password_single' => '',
'allow_links' => 'false',
'allow_links_auto' => 'false',
'allow_links_files' => 'false'
];
public const CIRCLES_PERSONAL = 1;
public const CIRCLES_SECRET = 2;
public const CIRCLES_CLOSED = 4;
public const CIRCLES_PUBLIC = 8;
public const CIRCLES_ALL = 15;
public const SHORT_UNIQUE_ID_LENGTH = 14;
/** @var int */
private $id;
/** @var IL10N */
protected $l10n;
/** @var string */
private $uniqueId = '';
/** @var string */
private $name;
/** @var string */
private $altName = '';
/** @var DeprecatedMember */
private $owner;
/** @var DeprecatedMember */
private $viewer = null;
/** @var DeprecatedMember */
private $viewerGroup;
/** @var string */
private $description = '';
/** @var array */
private $settings = [];
/** @var string */
private $passwordSingle = '';
/** @var int */
private $type;
/** @var string */
private $contactGroupName = '';
/** @var int */
private $contactAddressBook = 0;
/** @var string */
private $creation;
/** @var DeprecatedMember[] */
private $members;
/** @var DeprecatedMember[] */
private $groups;
/** @var FederatedLink[] */
private $links;
public function __construct($type = -1, $name = '') {
$this->l10n = OC::$server->getL10N(Application::APP_ID);
if ($type > -1) {
$this->type = $type;
}
if ($name !== '') {
$this->name = $name;
}
}
/**
* @param integer $id
*
* @return BaseCircle
*/
public function setId($id) {
$this->id = $id;
return $this;
}
/**
* @return integer
*/
public function getId() {
return $this->id;
}
/**
* @param string $uniqueId
*
* @return $this
*/
public function setUniqueId($uniqueId) {
$this->uniqueId = (string)$uniqueId;
return $this;
}
/**
* @param bool $full
*
* @return string
*/
public function getUniqueId($full = false) {
if ($full) {
return $this->uniqueId;
}
return substr($this->uniqueId, 0, self::SHORT_UNIQUE_ID_LENGTH);
}
public function generateUniqueId() {
$uniqueId = bin2hex(openssl_random_pseudo_bytes(24));
$this->setUniqueId($uniqueId);
$this->setId($this->getUniqueId());
}
/**
* @param string $name
*
* @return BaseCircle
*/
public function setName($name) {
$this->name = $name;
return $this;
}
/**
* @param bool $real
*
* @return string
*/
public function getName(bool $real = false) {
if (!$real && $this->altName !== '') {
return $this->altName;
}
return $this->name;
}
/**
* @param string $name
*
* @return BaseCircle
*/
public function setAltName($name) {
$this->altName = $name;
return $this;
}
/**
* @return string
*/
public function getAltName() {
return $this->altName;
}
/**
* @return DeprecatedMember
*/
public function getOwner() {
return $this->owner;
}
/**
* @param DeprecatedMember $owner
*
* @return BaseCircle
*/
public function setOwner($owner) {
$this->owner = $owner;
return $this;
}
/**
* @return DeprecatedMember
*/
public function getViewer() {
return $this->viewer;
}
/**
* @param DeprecatedMember $user
*
* @return BaseCircle
*/
public function setViewer($user) {
$this->viewer = $user;
return $this;
}
public function hasViewer(): bool {
return ($this->viewer !== null);
}
/**
* @return DeprecatedMember
*/
public function getGroupViewer() {
return $this->viewerGroup;
}
/**
* @param DeprecatedMember $group
*
* @return BaseCircle
*/
public function setGroupViewer($group) {
$this->viewerGroup = $group;
return $this;
}
/**
* @return DeprecatedMember
*/
public function getHigherViewer() {
if ($this->getGroupViewer() === null) {
return $this->getViewer();
}
if ($this->getViewer() === null) {
return $this->getGroupViewer();
}
if ($this->getGroupViewer()
->getLevel() > $this->getViewer()
->getLevel()
) {
return $this->getGroupViewer();
}
return $this->getViewer();
}
/**
* @param string $description
*
* @return BaseCircle
*/
public function setDescription($description) {
$this->description = $description;
return $this;
}
/**
* @return string
*/
public function getDescription() {
return $this->description;
}
/**
* @param int $contactAddressBook
*
* @return BaseCircle
*/
public function setContactAddressBook(int $contactAddressBook) {
$this->contactAddressBook = $contactAddressBook;
return $this;
}
/**
* @return int
*/
public function getContactAddressBook() {
return $this->contactAddressBook;
}
/**
* @param string $contactGroupName
*
* @return BaseCircle
*/
public function setContactGroupName($contactGroupName) {
$this->contactGroupName = $contactGroupName;
return $this;
}
/**
* @return string
*/
public function getContactGroupName() {
return $this->contactGroupName;
}
/**
* @param string|array $settings
* @param bool $all
*
* @return $this
*/
public function setSettings($settings, bool $all = false) {
if (is_array($settings)) {
$this->settings = $settings;
} elseif (is_string($settings)) {
$this->settings = (array)json_decode($settings, true);
}
if (array_key_exists('password_single', $this->settings)) {
$this->setPasswordSingle($this->settings['password_single']);
if (!$all) {
$this->settings['password_single'] = '';
}
}
return $this;
}
/**
* @param bool $json
*
* @return array|string
*/
public function getSettings($json = false) {
if ($json) {
return json_encode($this->settings);
}
$settings = $this->settings;
if ($settings === null) {
$settings = [];
}
$ak = array_keys(self::CIRCLES_SETTINGS_DEFAULT);
foreach ($ak as $k) {
if (!key_exists($k, $settings)) {
$settings[$k] = self::CIRCLES_SETTINGS_DEFAULT[$k];
}
}
return $settings;
}
/**
* @param string $k
* @param mixed $v
*/
public function setSetting($k, $v) {
switch ($k) {
case 'circle_name':
$this->setName($v);
break;
case 'circle_alt_name':
$this->setAltName($v);
break;
case 'circle_desc':
$this->setDescription($v);
break;
default:
$this->settings[$k] = $v;
break;
}
}
/**
* @param string $k
*
* @return string|null
*/
public function getSetting($k) {
if (key_exists($k, $this->settings)) {
return $this->settings[$k];
}
if (key_exists($k, (array)self::CIRCLES_SETTINGS_DEFAULT)) {
return self::CIRCLES_SETTINGS_DEFAULT[$k];
}
return null;
}
/**
* @return string
*/
public function getPasswordSingle(): string {
return $this->passwordSingle;
}
/**
* @param string $passwordSingle
*/
public function setPasswordSingle(string $passwordSingle): void {
$this->passwordSingle = $passwordSingle;
}
/**
*
* @param string $type
*
* @return \OCA\Circles\Model\BaseCircle
*/
public function setType($type) {
$this->type = self::typeInt($type);
return $this;
}
/**
* @return string
*/
public function getType() {
return $this->type;
}
/**
* @param string $creation
*
* @return \OCA\Circles\Model\BaseCircle
*/
public function setCreation($creation) {
$this->creation = $creation;
return $this;
}
/**
* @return string
*/
public function getCreation() {
return $this->creation;
}
/**
* @param array $members
*
* @return BaseCircle
*/
public function setMembers($members) {
$this->members = $members;
return $this;
}
/**
* @return DeprecatedMember[]
*/
public function getMembers() {
return $this->members;
}
/**
* @param array $groups
*
* @return BaseCircle
*/
public function setGroups($groups) {
$this->groups = $groups;
return $this;
}
/**
* @return array
*/
public function getGroups() {
return $this->groups;
}
/**
* @param array $links
*
* @return BaseCircle
*/
public function setLinks($links) {
$this->links = $links;
return $this;
}
/**
* @return array
*/
public function getLinks() {
return $this->links;
}
// public function getRemote() {
// return $this->remote;
// }
//
// public function addRemote($link) {
// array_push($this->remote, $link);
// }
//
// public function getRemoteFromToken($token) {
// foreach ($this->links AS $link) {
// if ($link->getToken() === $token) {
// return $link;
// }
// }
//
// return null;
// }
//
// public function getRemoteFromAddressAndId($address, $id) {
// foreach ($this->links AS $link) {
// if ($link->getAddress() === $address && $link->getUniqueId() === $id) {
// return $link;
// }
// }
//
// return null;
// }
/**
* @param integer|string $type
*
* @return integer
*/
public static function typeInt($type) {
if (is_numeric($type)) {
return (int)$type;
}
switch ($type) {
case 'Personal':
return self::CIRCLES_PERSONAL;
case 'Closed':
return self::CIRCLES_CLOSED;
case 'Secret':
return self::CIRCLES_SECRET;
case 'Public':
return self::CIRCLES_PUBLIC;
}
return 0;
}
}
@@ -0,0 +1,473 @@
<?php
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use JsonSerializable;
use OC;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\Service\MiscService;
use OCP\IL10N;
class BaseMember implements JsonSerializable {
public const LEVEL_NONE = 0;
public const LEVEL_MEMBER = 1;
public const LEVEL_MODERATOR = 4;
public const LEVEL_ADMIN = 8;
public const LEVEL_OWNER = 9;
public const STATUS_NONMEMBER = 'Unknown';
public const STATUS_INVITED = 'Invited';
public const STATUS_REQUEST = 'Requesting';
public const STATUS_MEMBER = 'Member';
public const STATUS_BLOCKED = 'Blocked';
public const STATUS_KICKED = 'Removed';
public const TYPE_USER = 1;
public const TYPE_GROUP = 2;
public const TYPE_MAIL = 3;
public const TYPE_CONTACT = 4;
/** @var string */
private $circleUniqueId;
/** @var IL10N */
protected $l10n;
/** @var string */
private $userId = '';
/** @var string */
private $memberId = '';
/** @var int */
private $type = self::TYPE_USER;
/** @var string */
private $cachedName = '';
/** @var int */
private $cachedUpdate = 0;
/** @var int */
private $level;
/** @var string */
private $status;
/** @var string */
private $contactId = '';
/** @var array */
private $contactMeta = [];
/** @var string */
private $note;
/** @var string */
private $instance = '';
/** @var string */
private $joined = '';
/** @var int */
private $joinedSince;
/** @var bool */
protected $broadcasting = true;
/**
* BaseMember constructor.
*
* @param string $circleUniqueId
* @param string $userId
* @param int $type
*/
public function __construct($userId = '', $type = 0, $circleUniqueId = '') {
$this->l10n = OC::$server->getL10N(Application::APP_ID);
$this->setType($type);
$this->setUserId($userId);
$this->setCircleId($circleUniqueId);
$this->setLevel(DeprecatedMember::LEVEL_NONE);
$this->setStatus(DeprecatedMember::STATUS_NONMEMBER);
}
/**
* @param string $circleUniqueId
*
* @return $this
*/
public function setCircleId($circleUniqueId) {
$this->circleUniqueId = $circleUniqueId;
return $this;
}
/**
* @return string
*/
public function getCircleId() {
return $this->circleUniqueId;
}
/**
* @return int
*/
public function getType() {
return $this->type;
}
public function setType($type) {
$this->type = (int)$type;
}
public function getViewerType() {
if ($this->getType() === 2) {
return 'group';
} else {
return 'user';
}
}
public function setUserId($userId) {
$this->userId = $userId;
return $this;
}
public function getUserId() {
return $this->userId;
}
public function setMemberId($memberId) {
$this->memberId = $memberId;
return $this;
}
public function getMemberId() {
return $this->memberId;
}
public function setCachedName($display) {
$this->cachedName = $display;
return $this;
}
public function getCachedName() {
if ($this->cachedName === '') {
return $this->userId;
}
return $this->cachedName;
}
public function setCachedUpdate(int $time) {
$this->cachedUpdate = $time;
return $this;
}
public function getCachedUpdate(): int {
return $this->cachedUpdate;
}
public function setLevel($level) {
$this->level = (int)$level;
return $this;
}
public function getLevel() {
return $this->level;
}
public function setNote($note) {
$this->note = $note;
return $this;
}
public function getNote() {
return $this->note;
}
public function setInstance($instance) {
$this->instance = $instance;
return $this;
}
public function getInstance() {
return $this->instance;
}
public function setContactId($contactId) {
$this->contactId = $contactId;
return $this;
}
public function getContactId() {
return $this->contactId;
}
/**
* @param array $contactMeta
*
* @return $this
*/
public function setContactMeta(array $contactMeta): self {
$this->contactMeta = $contactMeta;
return $this;
}
/**
* @return array
*/
public function getContactMeta(): array {
return $this->contactMeta;
}
/**
* @param string $k
* @param string $v
*
* @return $this
*/
public function addContactMeta(string $k, string $v): self {
$this->contactMeta[$k] = $v;
return $this;
}
/**
* @param string $k
* @param string $v
*
* @return $this
*/
public function addContactMetaArray(string $k, string $v): self {
if (!array_key_exists($k, $this->contactMeta)) {
$this->contactMeta[$k] = [];
}
$this->contactMeta[$k][] = $v;
return $this;
}
/**
* @param string $k
* @param array $v
*
* @return $this
*/
public function setContactMetaArray(string $k, array $v): self {
$this->contactMeta[$k] = $v;
return $this;
}
/**
* @param $status
*
* @return $this
*/
public function setStatus($status) {
if (is_null($status)) {
$this->status = self::STATUS_NONMEMBER;
} else {
$this->status = $status;
}
return $this;
}
public function getStatus() {
return $this->status;
}
public function setJoined($joined) {
$this->joined = $joined;
return $this;
}
public function getJoined() {
return $this->joined;
}
public function getJoinedSince(): int {
return $this->joinedSince;
}
public function setJoinedSince(int $since) {
$this->joinedSince = $since;
}
public function isLevel($level) {
return ($this->getLevel() >= $level);
}
public function isAlmostMember() {
return ($this->getStatus() === DeprecatedMember::STATUS_INVITED
|| $this->getStatus() === DeprecatedMember::STATUS_REQUEST);
}
protected function setAsAMember($level = 1) {
$this->setStatus(DeprecatedMember::STATUS_MEMBER);
$this->setLevel($level);
}
/**
* @param $arr
*
* @return null|DeprecatedMember
*/
public static function fromArray($arr) {
if ($arr === null) {
return null;
}
$member = new DeprecatedMember();
$member->setCircleId($arr['circle_id']);
$member->setMemberId($arr['member_id']);
if (array_key_exists('cached_name', $arr)) {
$member->setCachedName($arr['cached_name']);
}
$member->setLevel($arr['level']);
$member->setType(MiscService::get($arr, 'user_type'));
$member->setType(MiscService::get($arr, 'type', $member->getType()));
$member->setInstance($arr['instance']);
$member->setUserId($arr['user_id']);
$member->setStatus($arr['status']);
$member->setInstance($arr['instance']);
$member->setNote($arr['note']);
$member->setJoined($arr['joined']);
return $member;
}
/**
* @param $json
*
* @return DeprecatedMember
*/
public static function fromJSON($json) {
return self::fromArray(json_decode($json, true));
}
public function jsonSerialize() {
return [
'circle_id' => $this->getCircleId(),
'member_id' => $this->getMemberId(),
'user_id' => $this->getUserId(),
'user_type' => $this->getType(),
'cached_name' => $this->getCachedName(),
'contact_id' => $this->getContactId(),
'level' => $this->getLevel(),
'level_string' => $this->getLevelString(),
'status' => $this->getStatus(),
'instance' => $this->getInstance(),
'note' => $this->getNote(),
'joined' => $this->getJoined()
];
}
public function getLevelString() {
switch ($this->getLevel()) {
case self::LEVEL_NONE:
return 'Not a member';
case self::LEVEL_MEMBER:
return 'Member';
case self::LEVEL_MODERATOR:
return 'Moderator';
case self::LEVEL_ADMIN:
return 'Admin';
case self::LEVEL_OWNER:
return 'Owner';
}
return 'none';
}
public function getTypeString() {
switch ($this->getType()) {
case self::TYPE_USER:
return 'Local Member';
case self::TYPE_GROUP:
return 'Group';
case self::TYPE_MAIL:
return 'Mail address';
case self::TYPE_CONTACT:
return 'Contact';
}
return 'none';
}
public function getTypeName() {
switch ($this->getType()) {
case self::TYPE_USER:
case self::TYPE_MAIL:
case self::TYPE_CONTACT:
return 'user';
case self::TYPE_GROUP:
return 'user-group';
}
return 'none';
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,401 @@
<?php
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
/**
* Class DavCard
*
* @package OCA\Circles\Model
*/
class DavCard implements JsonSerializable {
use TArrayTools;
public const TYPE_CONTACT = 1;
public const TYPE_LOCAL = 2;
// const TYPE_FEDERATED = 3;
/** @var int */
private $addressBookId = 0;
/** @var string */
private $owner = '';
/** @var string */
private $cardUri = '';
/** @var string */
private $contactId = '';
/** @var string */
private $fn = '';
/** @var array */
private $emails = [];
/** @var array */
private $clouds = [];
/** @var array */
private $groups = [];
/** @var DeprecatedCircle[] */
private $circles = [];
/** @var string */
private $userId = '';
public function __construct() {
}
/**
* @return int
*/
public function getAddressBookId(): int {
return $this->addressBookId;
}
/**
* @param int $addressBookId
*
* @return DavCard
*/
public function setAddressBookId(int $addressBookId): self {
$this->addressBookId = $addressBookId;
return $this;
}
/**
* @return string
*/
public function getOwner(): string {
return $this->owner;
}
/**
* @param string $owner
*
* @return DavCard
*/
public function setOwner(string $owner): self {
$this->owner = $owner;
return $this;
}
/**
* @return string
*/
public function getCardUri(): string {
return $this->cardUri;
}
/**
* @param string $cardUri
*
* @return DavCard
*/
public function setCardUri(string $cardUri): self {
$this->cardUri = $cardUri;
return $this;
}
/**
* @return string
*/
public function getUniqueId(): string {
return $this->getAddressBookId() . '/' . $this->getCardUri();
}
/**
* @return string
*/
public function getContactId(): string {
return $this->contactId;
}
/**
* @param string $contactId
*
* @return DavCard
*/
public function setContactId(string $contactId): self {
$this->contactId = $contactId;
return $this;
}
/**
* @return string
*/
public function getFn(): string {
return $this->fn;
}
/**
* @param string $fn
*
* @return DavCard
*/
public function setFn(string $fn): self {
$this->fn = $fn;
return $this;
}
/**
* @return array
*/
public function getEmails(): array {
return $this->emails;
}
/**
* @param array $emails
*
* @return DavCard
*/
public function setEmails(array $emails): self {
$this->emails = $emails;
return $this;
}
/**
* @return array
*/
public function getClouds(): array {
return $this->clouds;
}
/**
* @param array $clouds
*
* @return DavCard
*/
public function setClouds(array $clouds): self {
$this->clouds = $clouds;
return $this;
}
/**
* @return array
*/
public function getGroups(): array {
return $this->groups;
}
/**
* @param array $groups
*
* @return DavCard
*/
public function setGroups(array $groups): self {
$this->groups = $groups;
return $this;
}
/**
* @return DeprecatedCircle[]
*/
public function getCircles(): array {
return $this->circles;
}
/**
* @param DeprecatedCircle $circle
*
* @return $this
*/
public function addCircle(DeprecatedCircle $circle): self {
$this->circles[] = $circle;
return $this;
}
/**
* @param array $circles
*
* @return DavCard
*/
public function setCircles(array $circles): self {
$this->circles = $circles;
return $this;
}
/**
* @return string
*/
public function getUserId(): string {
return $this->userId;
}
/**
* @param string $userId
*
* @return DavCard
*/
public function setUserId(string $userId): self {
$this->userId = $userId;
return $this;
}
/**
* @param array $data
*/
public function import(array $data) {
$this->setAddressBookId($this->get('addressBookId', $data));
$this->setOwner($this->get('owner', $data));
$this->setCardUri($this->get('cardUri', $data));
$this->setContactId($this->get('contactId', $data));
$this->setFn($this->get('fn', $data));
$this->setEmails($this->getArray('emails', $data));
$this->setClouds($this->getArray('clouds', $data));
$this->setGroups($this->getArray('groups', $data));
$this->setUserId($this->get('userId', $data));
}
/**
* @param string $dav
*/
public function importFromDav(string $dav) {
$data = $this->parseDav($dav);
$this->setContactId($this->get('UID', $data));
$this->setFn($this->get('FN', $data));
$this->setEmails($this->getArray('EMAILS', $data));
$this->setClouds($this->getArray('CLOUDS', $data));
$this->setGroups($this->getArray('CATEGORIES', $data));
}
/**
* get essential data from the dav content
* (also don't think we need regex)
*
* @param string $dav
*
* @return array
*/
private function parseDav(string $dav): array {
$result = [
'UID' => '',
'FN' => '',
'EMAILS' => [],
'CLOUDS' => [],
'CATEGORIES' => []
];
$data = preg_split('/\R/', $dav);
foreach ($data as $entry) {
if (trim($entry) === '' || strpos($entry, ':') === false) {
continue;
}
[$k, $v] = explode(':', $entry, 2);
$k = strtoupper($k);
if (strpos($entry, ';') !== false) {
[$k] = explode(';', $entry, 2);
}
switch ($k) {
case 'UID':
case 'FN':
$result[$k] = $v;
break;
case 'EMAIL':
if ($v !== '') {
$result['EMAILS'][] = $v;
}
break;
case 'CLOUD':
if ($v !== '') {
$result['CLOUDS'][] = $v;
}
break;
case 'CATEGORIES':
if (strpos($v, ',') === false) {
$result['CATEGORIES'] = [$v];
} else {
$result['CATEGORIES'] = explode(',', $v);
}
break;
}
}
return $result;
}
/**
* @return array
*/
public function jsonSerialize(): array {
return [
'addressBookId' => $this->getAddressBookId(),
'owner' => $this->getOwner(),
'cardUri' => $this->getCardUri(),
'contactId' => $this->getContactId(),
'uniqueId' => $this->getUniqueId(),
'fn' => $this->getFn(),
'emails' => $this->getEmails(),
'clouds' => $this->getClouds(),
'groups' => $this->getGroups(),
'userId' => $this->getUserId()
];
}
}
@@ -0,0 +1,304 @@
<?php
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
use OCA\Circles\Exceptions\CircleTypeNotValidException;
use OCA\Circles\Exceptions\FederatedCircleNotAllowedException;
class DeprecatedCircle extends BaseCircle implements JsonSerializable {
use TArrayTools;
/** @var bool */
private $fullJson = false;
/** @var bool */
private $lightJson = false;
public function getTypeString() {
switch ($this->getType()) {
case self::CIRCLES_PERSONAL:
return 'Personal';
case self::CIRCLES_SECRET:
return 'Secret';
case self::CIRCLES_CLOSED:
return 'Closed';
case self::CIRCLES_PUBLIC:
return 'Public';
case self::CIRCLES_ALL:
return 'All';
}
return 'none';
}
public function getTypeLongString() {
return self::typeLongString($this->getType());
}
public function getInfo() {
return $this->getTypeLongString();
}
/**
* @param bool $fullJson
*
* @return $this
*/
public function setFullJson(bool $fullJson): self {
$this->fullJson = $fullJson;
return $this;
}
public function jsonSerialize() {
$json = [
'id' => $this->getId(),
'name' => $this->getName(true),
'alt_name' => $this->getAltName(),
'owner' => $this->getOwner(),
'user' => $this->getViewer(),
'group' => $this->getGroupViewer(),
'viewer' => $this->getHigherViewer(),
'description' => $this->getDescription(),
'settings' => $this->getSettings(),
'type' => $this->getType(),
'creation' => $this->getCreation(),
'type_string' => $this->getTypeString(),
'type_long_string' => $this->getTypeLongString(),
'unique_id' => $this->getUniqueId($this->fullJson),
'members' => $this->getMembers(),
'groups' => $this->getGroups(),
'links' => $this->getLinks()
];
if ($this->lightJson) {
$json['members'] = [];
$json['description'] = '';
$json['links'] = [];
$json['groups'] = [];
$json['settings'] = [];
}
return $json;
}
public function getArray($full = false, $light = false) {
$json = $this->getJson($full, $light);
return json_decode($json, true);
}
public function getJson($full = false, $light = false) {
$this->fullJson = $full;
$this->lightJson = $light;
$json = json_encode($this);
$this->fullJson = false;
$this->lightJson = false;
return $json;
}
/**
* set all infos from an Array.
*
* @param $arr
* @param bool $allSettings
*
* @return $this
*/
public static function fromArray($arr, bool $allSettings = false) {
if ($arr === null || empty($arr)) {
return new DeprecatedCircle();
}
$circle = new DeprecatedCircle($arr['type'], $arr['name']);
if (array_key_exists('alt_name', $arr)) {
$circle->setAltName($arr['alt_name']);
}
$circle->setId($arr['id']);
$circle->setUniqueId($arr['unique_id']);
$circle->setDescription($arr['description']);
$circle->setSettings(self::getSettingsFromArray($arr), $allSettings);
$circle->setLinks(self::getLinksFromArray($arr));
$circle->setCreation($arr['creation']);
$circle->setViewer(self::getMemberFromArray($arr, 'user'));
$circle->setOwner(self::getMemberFromArray($arr, 'owner'));
if (array_key_exists('members', $arr) && is_array($arr['members'])) {
$members = [];
foreach ($arr['members'] as $item) {
$members[] = DeprecatedMember::fromArray($item);
}
$circle->setMembers($members);
}
return $circle;
}
/**
* @param array $arr
* @param $key
* @param int $type
*
* @return null|DeprecatedMember
*/
private static function getMemberFromArray($arr, $key, $type = DeprecatedMember::TYPE_USER) {
// TODO: 0.15.0 - remove condition is null
if (key_exists($key, $arr) && $arr[$key] !== null) {
$viewer = DeprecatedMember::fromArray($arr[$key]);
$viewer->setType($type);
return $viewer;
}
return null;
}
/**
* @param array $arr
*
* @return array
*/
private static function getLinksFromArray($arr) {
$links = [];
if (key_exists('links', $arr)) {
$links = $arr['links'];
}
return $links;
}
/**
* @param array $arr
*
* @return array
*/
private static function getSettingsFromArray($arr) {
$settings = [];
if (key_exists('settings', $arr)) {
$settings = $arr['settings'];
}
return $settings;
}
/**
* @param $json
*
* @return DeprecatedCircle
*/
public static function fromJSON($json) {
return self::fromArray(json_decode($json, true));
}
/**
* @throws CircleTypeNotValidException
*/
public function cantBePersonal() {
if ($this->getType() === self::CIRCLES_PERSONAL) {
throw new CircleTypeNotValidException(
$this->l10n->t("This feature is not available for personal circles")
);
}
}
/**
* @throws FederatedCircleNotAllowedException
*/
public function hasToBeFederated() {
if ($this->getSetting('allow_links') !== 'true') {
throw new FederatedCircleNotAllowedException(
$this->l10n->t('The circle is not federated')
);
}
}
/**
* @param $type
*
* @return string
*/
public static function typeLongString($type) {
switch ($type) {
case self::CIRCLES_PERSONAL:
return 'Personal circle';
case self::CIRCLES_SECRET:
return 'Secret circle';
case self::CIRCLES_CLOSED:
return 'Closed circle';
case self::CIRCLES_PUBLIC:
return 'Public circle';
case self::CIRCLES_ALL:
return 'All circles';
}
return 'none';
}
/**
* convert old type to new config (nc22)
*
* @param int $type
*
* @return int
*/
public static function convertTypeToConfig(int $type): int {
switch ($type) {
case DeprecatedCircle::CIRCLES_PERSONAL:
return 2;
case DeprecatedCircle::CIRCLES_SECRET:
return 16;
case DeprecatedCircle::CIRCLES_CLOSED:
return 120;
case DeprecatedCircle::CIRCLES_PUBLIC:
return 8;
}
return 0;
}
}
@@ -0,0 +1,254 @@
<?php
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use OCA\Circles\Exceptions\CircleTypeNotValidException;
use OCA\Circles\Exceptions\MemberAlreadyExistsException;
use OCA\Circles\Exceptions\MemberCantJoinCircleException;
use OCA\Circles\Exceptions\MemberDoesNotExistException;
use OCA\Circles\Exceptions\MemberIsBlockedException;
use OCA\Circles\Exceptions\MemberIsNotModeratorException;
use OCA\Circles\Exceptions\MemberIsOwnerException;
use OCA\Circles\Exceptions\MemberTypeCantEditLevelException;
use OCA\Circles\Exceptions\ModeratorIsNotHighEnoughException;
class DeprecatedMember extends BaseMember {
public function inviteToCircle($circleType) {
if ($circleType === 0) {
throw new CircleTypeNotValidException('Invalid circle type');
}
if ($circleType === DeprecatedCircle::CIRCLES_CLOSED) {
return $this->inviteIntoClosedCircle();
}
return $this->addMemberToCircle();
}
/**
* @param int $circleType
*
* @throws MemberCantJoinCircleException
*/
public function joinCircle($circleType) {
switch ($circleType) {
case DeprecatedCircle::CIRCLES_SECRET:
case DeprecatedCircle::CIRCLES_PUBLIC:
return $this->addMemberToCircle();
case DeprecatedCircle::CIRCLES_CLOSED:
return $this->joinClosedCircle();
}
throw new MemberCantJoinCircleException($this->l10n->t('You cannot join this circle'));
}
/**
* Update status of member like he joined a public circle.
*/
public function addMemberToCircle() {
if ($this->getStatus() === DeprecatedMember::STATUS_NONMEMBER
|| $this->getStatus() === DeprecatedMember::STATUS_KICKED
) {
$this->setAsAMember(DeprecatedMember::LEVEL_MEMBER);
}
}
/**
* Update status of member like he joined a closed circle
* (invite/request)
*/
private function joinClosedCircle() {
switch ($this->getStatus()) {
case DeprecatedMember::STATUS_NONMEMBER:
case DeprecatedMember::STATUS_KICKED:
$this->setStatus(DeprecatedMember::STATUS_REQUEST);
break;
case DeprecatedMember::STATUS_INVITED:
$this->setAsAMember(DeprecatedMember::LEVEL_MEMBER);
break;
}
}
private function inviteIntoClosedCircle() {
switch ($this->getStatus()) {
case DeprecatedMember::STATUS_NONMEMBER:
case DeprecatedMember::STATUS_KICKED:
$this->setStatus(DeprecatedMember::STATUS_INVITED);
break;
case DeprecatedMember::STATUS_REQUEST:
$this->setAsAMember(DeprecatedMember::LEVEL_MEMBER);
break;
}
}
/**
* @throws MemberIsNotModeratorException
*/
public function hasToBeModerator() {
if ($this->getLevel() < self::LEVEL_MODERATOR) {
throw new MemberIsNotModeratorException(
$this->l10n->t('This member is not a moderator')
);
}
}
/**
* @param $level
*
* @throws ModeratorIsNotHighEnoughException
*/
public function hasToBeHigherLevel($level) {
if ($this->getLevel() <= $level) {
throw new ModeratorIsNotHighEnoughException(
$this->l10n->t('Insufficient privileges')
);
}
}
/**
* @throws MemberDoesNotExistException
*/
public function hasToBeMember() {
if ($this->getLevel() < self::LEVEL_MEMBER) {
throw new MemberDoesNotExistException($this->l10n->t('This member does not exist'));
}
return true;
}
/**
* @throws MemberDoesNotExistException
*/
public function hasToBeMemberOrAlmost() {
if ($this->isAlmostMember() || $this->hasToBeMember()) {
return true;
}
throw new MemberDoesNotExistException($this->l10n->t('This member does not exist'));
}
/**
* @throws MemberIsOwnerException
*/
public function cantBeOwner() {
if ($this->getLevel() === self::LEVEL_OWNER) {
throw new MemberIsOwnerException(
$this->l10n->t('This member is the owner of the circle')
);
}
}
/**
* return if member already exists
*
* @return bool
*/
public function alreadyExistOrJoining() {
return ($this->getLevel() > DeprecatedMember::LEVEL_NONE
|| ($this->getStatus() !== DeprecatedMember::STATUS_NONMEMBER
&& $this->getStatus() !== DeprecatedMember::STATUS_REQUEST)
);
}
/**
* @param bool $able
*/
public function broadcasting($able) {
$this->broadcasting = $able;
}
/**
* @return bool
*/
public function isBroadcasting() {
return $this->broadcasting;
}
/**
* @throws MemberTypeCantEditLevelException
*/
public function levelHasToBeEditable() {
if ($this->getType() !== self::TYPE_USER) {
throw new MemberTypeCantEditLevelException(
$this->l10n->t('Level cannot be changed for this type of member')
);
}
}
/**
* @throws MemberAlreadyExistsException
* @throws MemberIsBlockedException
*/
public function hasToBeAbleToJoinTheCircle() {
if ($this->getLevel() > 0) {
throw new MemberAlreadyExistsException(
$this->l10n->t("You are already a member of this circle")
);
}
if ($this->getStatus() === DeprecatedMember::STATUS_BLOCKED) {
throw new MemberIsBlockedException(
$this->l10n->t("You have been blocked from this circle")
);
}
}
/**
* @throws MemberAlreadyExistsException
*/
public function hasToBeInviteAble() {
if ($this->getLevel() > 0) {
throw new MemberAlreadyExistsException(
$this->l10n->t("The account is already a member of this circle")
);
}
if ($this->getStatus() === DeprecatedMember::STATUS_INVITED) {
throw new MemberAlreadyExistsException(
$this->l10n->t("The account has already been invited into this circle")
);
}
}
}
@@ -0,0 +1,327 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model\Federated;
use OCA\Circles\Tools\Db\IQueryRow;
use OCA\Circles\Tools\Exceptions\InvalidItemException;
use OCA\Circles\Tools\Model\SimpleDataStore;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
/**
* Class EventWrapper
*
* @package OCA\Circles\Model\Remote
*/
class EventWrapper implements IQueryRow, JsonSerializable {
use TArrayTools;
public const STATUS_INIT = 0;
public const STATUS_FAILED = 1;
public const STATUS_DONE = 8;
public const STATUS_OVER = 9;
/** @var string */
private $token = '';
/** @var FederatedEvent */
private $event;
/** @var SimpleDataStore */
private $result;
/** @var string */
private $instance = '';
/** @var int */
private $interface = 0;
/** @var int */
private $severity = FederatedEvent::SEVERITY_LOW;
/** @var int */
private $retry = 0;
/** @var int */
private $status = 0;
/** @var int */
private $creation;
public function __construct() {
$this->result = new SimpleDataStore();
}
/**
* @return string
*/
public function getToken(): string {
return $this->token;
}
/**
* @param string $token
*
* @return self
*/
public function setToken(string $token): self {
$this->token = $token;
return $this;
}
/**
* @return FederatedEvent
*/
public function getEvent(): FederatedEvent {
return $this->event;
}
/**
* @param FederatedEvent $event
*
* @return self
*/
public function setEvent(FederatedEvent $event): self {
$this->event = $event;
return $this;
}
/**
* @return bool
*/
public function hasEvent(): bool {
return ($this->event !== null);
}
/**
* @param SimpleDataStore $result
*
* @return $this
*/
public function setResult(SimpleDataStore $result): self {
$this->result = $result;
return $this;
}
/**
* @return SimpleDataStore
*/
public function getResult(): SimpleDataStore {
return $this->result;
}
/**
* @return string
*/
public function getInstance(): string {
return $this->instance;
}
/**
* @param string $instance
*
* @return self
*/
public function setInstance(string $instance): self {
$this->instance = $instance;
return $this;
}
/**
* @return int
*/
public function getInterface(): int {
return $this->interface;
}
/**
* @param int $interface
*
* @return self
*/
public function setInterface(int $interface): self {
$this->interface = $interface;
return $this;
}
/**
* @return int
*/
public function getSeverity(): int {
return $this->severity;
}
/**
* @param int $severity
*
* @return self
*/
public function setSeverity(int $severity): self {
$this->severity = $severity;
return $this;
}
/**
* @param int $retry
*
* @return EventWrapper
*/
public function setRetry(int $retry): self {
$this->retry = $retry;
return $this;
}
/**
* @return int
*/
public function getRetry(): int {
return $this->retry;
}
/**
* @return int
*/
public function getStatus(): int {
return $this->status;
}
/**
* @param int $status
*
* @return self
*/
public function setStatus(int $status): self {
$this->status = $status;
return $this;
}
/**
* @return int
*/
public function getCreation(): int {
return $this->creation;
}
/**
* @param int $creation
*
* @return self
*/
public function setCreation(int $creation): self {
$this->creation = $creation;
return $this;
}
/**
* @param array $data
*
* @return self
* @throws InvalidItemException
*/
public function import(array $data): self {
$this->setToken($this->get('token', $data));
$this->setInstance($this->get('instance', $data));
$this->setInterface($this->getInt('interface', $data));
$this->setSeverity($this->getInt('severity', $data, FederatedEvent::SEVERITY_LOW));
$this->setStatus($this->getInt('status', $data, self::STATUS_INIT));
$event = new FederatedEvent();
$event->import($this->getArray('event', $data));
$this->setEvent($event);
$this->setResult(new SimpleDataStore($this->getArray('result', $data)));
$this->setCreation($this->getInt('creation', $data));
return $this;
}
/**
* @return array
*/
public function jsonSerialize(): array {
return [
'token' => $this->getToken(),
'instance' => $this->getInstance(),
'interface' => $this->getInterface(),
'event' => $this->getEvent(),
'result' => $this->getResult(),
'severity' => $this->getSeverity(),
'status' => $this->getStatus()
// 'creation' => $this->getCreation()
];
}
/**
* @param array $data
*
* @return IQueryRow
* @throws InvalidItemException
*/
public function importFromDatabase(array $data): IQueryRow {
$this->setToken($this->get('token', $data));
$this->setInstance($this->get('instance', $data));
$this->setInterface($this->getInt('interface', $data));
$this->setSeverity($this->getInt('severity', $data, FederatedEvent::SEVERITY_LOW));
$this->setStatus($this->getInt('status', $data, self::STATUS_INIT));
$event = new FederatedEvent();
$event->import($this->getArray('event', $data));
$this->setEvent($event);
$this->setResult(new SimpleDataStore($this->getArray('result', $data)));
return $this;
}
}
@@ -0,0 +1,643 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model\Federated;
use OCA\Circles\Tools\Exceptions\InvalidItemException;
use OCA\Circles\Tools\Model\SimpleDataStore;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;
/**
* Class FederatedEvent
*
* @package OCA\Circles\Model\Federated
*/
class FederatedEvent implements JsonSerializable {
public const SEVERITY_LOW = 1;
public const SEVERITY_HIGH = 3;
public const BYPASS_CIRCLE = 1;
public const BYPASS_LOCALCIRCLECHECK = 2;
public const BYPASS_LOCALMEMBERCHECK = 4;
public const BYPASS_INITIATORCHECK = 8;
public const BYPASS_INITIATORMEMBERSHIP = 16;
use TArrayTools;
/** @var string */
private $class;
/** @var string */
private $origin = '';
/** @var Circle */
private $circle;
/** @var string */
private $itemId = '';
/** @var string */
private $itemSource = '';
/** @var Member */
private $member;
/** @var Member[] */
private $members = [];
/** @var SimpleDataStore */
private $params;
/** @var SimpleDataStore */
private $internal;
/** @var SimpleDataStore */
private $data;
/** @var int */
private $severity = self::SEVERITY_LOW;
/** @var array */
private $outcome = [];
/** @var SimpleDataStore */
private $result;
/** @var bool */
private $async = false;
/** @var bool */
private $limitedToInstanceWithMember = false;
/** @var bool */
private $dataRequestOnly = false;
/** @var string */
private $sender = '';
/** @var string */
private $wrapperToken = '';
/** @var int */
private $bypass = 0;
/**
* FederatedEvent constructor.
*
* @param string $class
*/
public function __construct(string $class = '') {
$this->class = $class;
$this->params = new SimpleDataStore();
$this->internal = new SimpleDataStore();
$this->data = new SimpleDataStore();
$this->result = new SimpleDataStore();
}
/**
* @return string
*/
public function getClass(): string {
return $this->class;
}
/**
* @param mixed $class
*
* @return self
*/
public function setClass($class): self {
$this->class = $class;
return $this;
}
/**
* Origin of the event.
*
* @return string
*/
public function getOrigin(): string {
return $this->origin;
}
/**
* @param string $origin
*
* @return self
*/
public function setOrigin(string $origin): self {
$this->origin = $origin;
return $this;
}
/**
* @return bool
*/
public function isAsync(): bool {
return $this->async;
}
/**
* @param bool $async
*
* @return self
*/
public function setAsync(bool $async): self {
$this->async = $async;
return $this;
}
/**
* @return bool
*/
public function isLimitedToInstanceWithMember(): bool {
return $this->limitedToInstanceWithMember;
}
/**
* @param bool $limitedToInstanceWithMember
*
* @return self
*/
public function setLimitedToInstanceWithMember(bool $limitedToInstanceWithMember): self {
$this->limitedToInstanceWithMember = $limitedToInstanceWithMember;
return $this;
}
/**
* @return bool
*/
public function isDataRequestOnly(): bool {
return $this->dataRequestOnly;
}
/**
* @param bool $dataRequestOnly
*
* @return self
*/
public function setDataRequestOnly(bool $dataRequestOnly): self {
$this->dataRequestOnly = $dataRequestOnly;
return $this;
}
/**
*
* Origin of the request
*
* @param string $sender
*
* @return self
*/
public function setSender(string $sender): self {
$this->sender = $sender;
return $this;
}
/**
* @return string
*/
public function getSender(): string {
return $this->sender;
}
/**
* @param string $wrapperToken
*
* @return FederatedEvent
*/
public function setWrapperToken(string $wrapperToken): self {
$this->wrapperToken = $wrapperToken;
return $this;
}
/**
* @return string
*/
public function getWrapperToken(): string {
return $this->wrapperToken;
}
/**
* @return bool
*/
public function hasCircle(): bool {
return ($this->circle !== null);
}
/**
* @param Circle $circle
*
* @return self
*/
public function setCircle(Circle $circle): self {
$this->circle = $circle;
return $this;
}
/**
* @return Circle
*/
public function getCircle(): Circle {
return $this->circle;
}
/**
* @param string $itemId
*
* @return self
*/
public function setItemId(string $itemId): self {
$this->itemId = $itemId;
return $this;
}
/**
* @return string
*/
public function getItemId(): string {
return $this->itemId;
}
/**
* @param string $itemSource
*
* @return self
*/
public function setItemSource(string $itemSource): self {
$this->itemSource = $itemSource;
return $this;
}
/**
* @return string
*/
public function getItemSource(): string {
return $this->itemSource;
}
/**
* @return Member
*/
public function getMember(): Member {
return $this->member;
}
/**
* @param Member|null $member
*
* @return self
*/
public function setMember(?Member $member): self {
$this->member = $member;
return $this;
}
/**
* @return bool
*/
public function hasMember(): bool {
return ($this->member !== null);
}
/**
* @return Member[]
*/
public function getMembers(): array {
return $this->members;
}
/**
* @param Member[] $members
*
* @return self
*/
public function setMembers(array $members): self {
$this->members = $members;
return $this;
}
/**
* @param SimpleDataStore $params
*
* @return self
*/
public function setParams(SimpleDataStore $params): self {
$this->params = $params;
return $this;
}
/**
* @return SimpleDataStore
*/
public function getParams(): SimpleDataStore {
return $this->params;
}
/**
* @param SimpleDataStore $internal
*
* @return self
*/
public function setInternal(SimpleDataStore $internal): self {
$this->internal = $internal;
return $this;
}
/**
* @return SimpleDataStore
*/
public function getInternal(): SimpleDataStore {
return $this->internal;
}
/**
* @return $this
*/
public function resetInternal(): self {
$this->internal = new SimpleDataStore();
return $this;
}
/**
* @param SimpleDataStore $data
*
* @return self
*/
public function setData(SimpleDataStore $data): self {
$this->data = $data;
return $this;
}
/**
* @return SimpleDataStore
*/
public function getData(): SimpleDataStore {
return $this->data;
}
/**
* @return $this
*/
public function resetData(): self {
$this->resetInternal();
$this->data = new SimpleDataStore();
return $this;
}
/**
* @return int
*/
public function getSeverity(): int {
return $this->severity;
}
/**
* @param int $severity
*
* @return self
*/
public function setSeverity(int $severity): self {
$this->severity = $severity;
return $this;
}
/**
* @return array
*/
public function getOutcome(): array {
return $this->outcome;
}
/**
* @param array $data
*
* @return $this
*/
public function setOutcome(array $data): self {
$this->outcome = $data;
return $this;
}
/**
* @return SimpleDataStore
*/
public function getResult(): SimpleDataStore {
return $this->result;
}
/**
* @param SimpleDataStore $result
*
* @return self
*/
public function setResult(SimpleDataStore $result): self {
$this->result = $result;
return $this;
}
/**
* @return $this
*/
public function resetResult(): self {
$this->result = new SimpleDataStore();
return $this;
}
/**
* @param string $key
* @param array $result
*
* @return $this
*/
public function setResultEntry(string $key, array $result): self {
if (is_null($this->result)) {
$this->result = new SimpleDataStore();
}
$this->result->sData($key, new SimpleDataStore($result));
return $this;
}
/**
* @param string $key
* @param array $result
*
* @return $this
*/
public function addResultEntry(string $key, array $result): self {
if (is_null($this->result)) {
$this->result = new SimpleDataStore();
}
$this->result->aData($key, new SimpleDataStore($result));
return $this;
}
/**
* @param int $flag
*
* @return FederatedEvent
*/
public function bypass(int $flag): self {
if (!$this->canBypass($flag)) {
$this->bypass += $flag;
}
return $this;
}
/**
* @param int $flag
*
* @return bool
*/
public function canBypass(int $flag): bool {
return (($this->bypass & $flag) !== 0);
}
/**
* @param array $data
*
* @return self
* @throws InvalidItemException
*/
public function import(array $data): self {
$this->setClass($this->get('class', $data));
$this->setSeverity($this->getInt('severity', $data));
$this->setParams(new SimpleDataStore($this->getArray('params', $data)));
$this->setInternal(new SimpleDataStore($this->getArray('internal', $data)));
$this->setData(new SimpleDataStore($this->getArray('data', $data)));
$this->setResult(new SimpleDataStore($this->getArray('result', $data)));
$this->setOrigin($this->get('origin', $data));
$this->setItemId($this->get('itemId', $data));
try {
$circle = new Circle();
$circle->import($this->getArray('circle', $data));
$this->setCircle($circle);
} catch (InvalidItemException $e) {
}
if (array_key_exists('member', $data)) {
$member = new Member();
$member->import($this->getArray('member', $data));
$this->setMember($member);
}
$members = [];
foreach ($this->getArray('members', $data) as $item) {
$member = new Member();
$members[] = $member->import($item);
}
$this->setMembers($members);
return $this;
}
/**
* @return array
*/
public function jsonSerialize(): array {
$arr = [
'class' => $this->getClass(),
'severity' => $this->getSeverity(),
'params' => $this->getParams(),
'internal' => $this->getInternal(),
'data' => $this->getData(),
'result' => $this->getResult(),
'origin' => $this->getOrigin(),
'sender' => $this->getSender(),
'itemId' => $this->getItemId(),
'outcome' => $this->getOutcome(),
'members' => $this->getMembers()
];
if ($this->hasCircle()) {
$arr['circle'] = $this->getCircle();
}
if ($this->hasMember()) {
$arr['member'] = $this->getMember();
}
return $arr;
}
}
@@ -0,0 +1,225 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model\Federated;
use OCA\Circles\Tools\Db\IQueryRow;
use OCA\Circles\Tools\IDeserializable;
use OCA\Circles\Tools\Model\SimpleDataStore;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
use OCA\Circles\IFederatedModel;
use OCA\Circles\Model\ManagedModel;
/**
* Class FederatedShare
*
* @package OCA\Circles\Model\Federated
*/
class FederatedShare extends ManagedModel implements IFederatedModel, JsonSerializable, IQueryRow, IDeserializable {
use TArrayTools;
/** @var int */
private $id = 0;
/** @var string */
private $itemId = '';
/** @var string */
private $circleId = '';
/** @var string */
private $instance = '';
/** @var string */
private $lockStatus = '';
/** @var SimpleDataStore */
private $data;
/**
* FederatedShare constructor.
*/
public function __construct() {
}
/**
* @param int $id
*
* @return FederatedShare
*/
public function setId(int $id): self {
$this->id = $id;
return $this;
}
/**
* @return int
*/
public function getId(): int {
return $this->id;
}
/**
* @param string $itemId
*
* @return FederatedShare
*/
public function setItemId(string $itemId): self {
$this->itemId = $itemId;
return $this;
}
/**
* @return string
*/
public function getItemId(): string {
return $this->itemId;
}
/**
* @param string $circleId
*
* @return FederatedShare
*/
public function setCircleId(string $circleId): self {
$this->circleId = $circleId;
return $this;
}
/**
* @return string
*/
public function getCircleId(): string {
return $this->circleId;
}
/**
* @param string $instance
*
* @return FederatedShare
*/
public function setInstance(string $instance): self {
$this->instance = $instance;
return $this;
}
/**
* @param string $lockStatus
*
* @return FederatedShare
*/
public function setLockStatus(string $lockStatus): self {
$this->lockStatus = $lockStatus;
return $this;
}
/**
* @return string
*/
public function getLockStatus(): string {
return $this->lockStatus;
}
/**
* @return string
*/
public function getInstance(): string {
return $this->instance;
}
/**
* @return bool
*/
public function isLocal(): bool {
return $this->getManager()->isLocalInstance($this->getInstance());
}
/**
* @param array $data
*
* @return IDeserializable
*/
public function import(array $data): IDeserializable {
$this->setId($this->getInt('id', $data));
$this->setItemId($this->get('itemId', $data));
$this->setCircleId($this->get('circleId', $data));
$this->setInstance($this->get('instance', $data));
return $this;
}
/**
* @param array $data
*
* @return IQueryRow
*/
public function importFromDatabase(array $data): IQueryRow {
$this->setId($this->getInt('id', $data));
$this->setItemId($this->get('item_id', $data));
$this->setCircleId($this->get('circle_id', $data));
$this->setInstance($this->get('instance', $data));
if ($this->getInstance() === '') {
$this->setInstance($this->getManager()->getLocalInstance());
}
return $this;
}
/**
* @return array
*/
public function jsonSerialize(): array {
return [
'id' => $this->getId(),
'itemId' => $this->getItemId(),
'circleId' => $this->getCircleId(),
'instance' => $this->getInstance()
];
}
}
@@ -0,0 +1,562 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model\Federated;
use OCA\Circles\Tools\Db\IQueryRow;
use OCA\Circles\Tools\Model\NCSignatory;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
use OCA\Circles\Exceptions\RemoteNotFoundException;
use OCA\Circles\Exceptions\RemoteUidException;
/**
* Class AppService
*
* @package OCA\Circles\Model
*/
class RemoteInstance extends NCSignatory implements IQueryRow, JsonSerializable {
use TArrayTools;
public const TYPE_UNKNOWN = 'Unknown'; // not trusted
public const TYPE_PASSIVE = 'Passive'; // Minimum information about Federated Circles are broadcasted if a member belongs to the circle.
public const TYPE_EXTERNAL = 'External'; // info about Federated Circles and their members are broadcasted if a member belongs to the circle.
public const TYPE_TRUSTED = 'Trusted'; // everything about Federated Circles are broadcasted.
public const TYPE_GLOBALSCALE = 'GlobalScale'; // every Circle is broadcasted,
public static $LIST_TYPE = [
self::TYPE_UNKNOWN,
self::TYPE_PASSIVE,
self::TYPE_EXTERNAL,
self::TYPE_TRUSTED,
self::TYPE_GLOBALSCALE
];
public const ROOT = 'root';
public const TEST = 'test';
public const ALIASES = 'aliases';
public const INCOMING = 'incoming';
public const EVENT = 'event';
public const CIRCLES = 'circles';
public const CIRCLE = 'circle';
public const MEMBERS = 'members';
public const MEMBER = 'member';
public const MEMBERSHIPS = 'memberships';
public const INHERITED = 'inherited';
public const UID = 'uid';
public const AUTH_SIGNED = 'auth-signed';
/** @var int */
private $dbId = 0;
/** @var string */
private $type = self::TYPE_UNKNOWN;
/** @var int */
private $interface = 0;
/** @var string */
private $test = '';
/** @var array */
private $aliases = [];
/** @var string */
private $incoming = '';
/** @var string */
private $root = '';
/** @var string */
private $event = '';
/** @var string */
private $circles = '';
/** @var string */
private $circle = '';
/** @var string */
private $members = '';
/** @var string */
private $member = '';
/** @var string */
private $inherited = '';
/** @var string */
private $memberships = '';
/** @var string */
private $uid = '';
/** @var string */
private $authSigned = '';
/** @var bool */
private $identityAuthed = false;
/**
* @param int $dbId
*
* @return self
*/
public function setDbId(int $dbId): self {
$this->dbId = $dbId;
return $this;
}
/**
* @return int
*/
public function getDbId(): int {
return $this->dbId;
}
/**
* @param string $type
*
* @return $this
*/
public function setType(string $type): self {
$this->type = $type;
return $this;
}
/**
* @return string
*/
public function getType(): string {
return $this->type;
}
/**
* @param int $interface
*
* @return RemoteInstance
*/
public function setInterface(int $interface): self {
$this->interface = $interface;
return $this;
}
/**
* @return int
*/
public function getInterface(): int {
return $this->interface;
}
/**
* @param array $aliases
*
* @return RemoteInstance
*/
public function setAliases(array $aliases): self {
$this->aliases = $aliases;
return $this;
}
/**
* @return array
*/
public function getAliases(): array {
return $this->aliases;
}
/**
* @return string
*/
public function getIncoming(): string {
return $this->incoming;
}
/**
* @param string $incoming
*
* @return self
*/
public function setIncoming(string $incoming): self {
$this->incoming = $incoming;
return $this;
}
/**
* @return string
*/
public function getRoot(): string {
return $this->root;
}
/**
* @param string $root
*
* @return $this
*/
public function setRoot(string $root): self {
$this->root = $root;
return $this;
}
/**
* @return string
*/
public function getEvent(): string {
return $this->event;
}
/**
* @param string $event
*
* @return self
*/
public function setEvent(string $event): self {
$this->event = $event;
return $this;
}
/**
* @param string $test
*
* @return RemoteInstance
*/
public function setTest(string $test): self {
$this->test = $test;
return $this;
}
/**
* @return string
*/
public function getTest(): string {
return $this->test;
}
/**
* @return string
*/
public function getCircles(): string {
return $this->circles;
}
/**
* @param string $circles
*
* @return self
*/
public function setCircles(string $circles): self {
$this->circles = $circles;
return $this;
}
/**
* @return string
*/
public function getCircle(): string {
return $this->circle;
}
/**
* @param string $circle
*
* @return self
*/
public function setCircle(string $circle): self {
$this->circle = $circle;
return $this;
}
/**
* @return string
*/
public function getMembers(): string {
return $this->members;
}
/**
* @param string $members
*
* @return self
*/
public function setMembers(string $members): self {
$this->members = $members;
return $this;
}
/**
* @return string
*/
public function getInherited(): string {
return $this->inherited;
}
/**
* @param string $inherited
*
* @return self
*/
public function setInherited(string $inherited): self {
$this->inherited = $inherited;
return $this;
}
/**
* @return string
*/
public function getMemberships(): string {
return $this->memberships;
}
/**
* @param string $memberships
*
* @return self
*/
public function setMemberships(string $memberships): self {
$this->memberships = $memberships;
return $this;
}
/**
* @return string
*/
public function getMember(): string {
return $this->member;
}
/**
* @param string $member
*
* @return self
*/
public function setMember(string $member): self {
$this->member = $member;
return $this;
}
/**
* @return $this
*/
public function setUidFromKey(): self {
$this->setUid(hash('sha512', $this->getPublicKey()));
return $this;
}
/**
* @param string $uid
*
* @return RemoteInstance
*/
public function setUid(string $uid): self {
$this->uid = $uid;
return $this;
}
/**
* @param bool $shorten
*
* @return string
*/
public function getUid(bool $shorten = false): string {
if ($shorten) {
return substr($this->uid, 0, 18);
}
return $this->uid;
}
/**
* @param string $authSigned
*
* @return RemoteInstance
*/
public function setAuthSigned(string $authSigned): self {
$this->authSigned = $authSigned;
return $this;
}
/**
* @return string
*/
public function getAuthSigned(): string {
return $this->authSigned;
}
/**
* @param bool $identityAuthed
*
* @return RemoteInstance
*/
public function setIdentityAuthed(bool $identityAuthed): self {
$this->identityAuthed = $identityAuthed;
return $this;
}
/**
* @return bool
*/
public function isIdentityAuthed(): bool {
return $this->identityAuthed;
}
/**
* @throws RemoteUidException
*/
public function mustBeIdentityAuthed(): void {
if (!$this->isIdentityAuthed()) {
throw new RemoteUidException('identity not authed');
}
}
/**
* @param array $data
*
* @return NCSignatory
*/
public function import(array $data): NCSignatory {
parent::import($data);
$this->setTest($this->get(self::TEST, $data))
->setAliases($this->getArray(self::ALIASES, $data))
->setEvent($this->get(self::EVENT, $data))
->setRoot($this->get(self::ROOT, $data))
->setIncoming($this->get(self::INCOMING, $data))
->setCircles($this->get(self::CIRCLES, $data))
->setCircle($this->get(self::CIRCLE, $data))
->setMembers($this->get(self::MEMBERS, $data))
->setMember($this->get(self::MEMBER, $data))
->setInherited($this->get(self::INHERITED, $data))
->setMemberships($this->get(self::MEMBERSHIPS, $data))
->setUid($this->get(self::UID, $data));
$algo = '';
$authSigned = trim($this->get(self::AUTH_SIGNED, $data), ':');
if (strpos($authSigned, ':') > 0) {
[$algo, $authSigned] = explode(':', $authSigned);
}
$this->setAuthSigned($authSigned)
->setAlgorithm($algo);
return $this;
}
/**
* @return array
*/
public function jsonSerialize(): array {
$data = [
self::UID => $this->getUid(true),
self::ROOT => $this->getRoot(),
self::EVENT => $this->getEvent(),
self::INCOMING => $this->getIncoming(),
self::TEST => $this->getTest(),
self::CIRCLES => $this->getCircles(),
self::CIRCLE => $this->getCircle(),
self::MEMBERS => $this->getMembers(),
self::MEMBER => $this->getMember(),
self::INHERITED => $this->getInherited(),
self::MEMBERSHIPS => $this->getMemberships()
];
if ($this->getAuthSigned() !== '') {
$data[self::AUTH_SIGNED] = $this->getAlgorithm() . ':' . $this->getAuthSigned();
}
if (!empty($this->getAliases())) {
$data[self::ALIASES] = $this->getAliases();
}
return array_filter(array_merge($data, parent::jsonSerialize()));
}
/**
* @param array $data
* @param string $prefix
*
* @return self
* @throws RemoteNotFoundException
*/
public function importFromDatabase(array $data, string $prefix = ''): IQueryRow {
if ($this->getInt($prefix . 'id', $data) === 0) {
throw new RemoteNotFoundException();
}
$this->setDbId($this->getInt($prefix . 'id', $data));
$this->import($this->getArray($prefix . 'item', $data));
$this->setOrigData($this->getArray($prefix . 'item', $data));
$this->setType($this->get($prefix . 'type', $data));
$this->setInterface($this->getInt($prefix . 'interface', $data));
$this->setInstance($this->get($prefix . 'instance', $data));
$this->setId($this->get($prefix . 'href', $data));
return $this;
}
}
@@ -0,0 +1,426 @@
<?php
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use OCA\Circles\Exceptions\FederatedCircleStatusUpdateException;
class FederatedLink implements \JsonSerializable {
public const STATUS_ERROR = -1;
public const STATUS_LINK_REMOVE = 0;
public const STATUS_LINK_DOWN = 1;
public const STATUS_LINK_SETUP = 2;
public const STATUS_REQUEST_DECLINED = 4;
public const STATUS_REQUEST_SENT = 5;
public const STATUS_LINK_REQUESTED = 6;
public const STATUS_LINK_UP = 9;
public const SHORT_UNIQUE_ID_LENGTH = 12;
/** @var int */
private $id;
/** @var string */
private $token;
/** @var string */
private $address;
/** @var string */
private $localAddress;
/** @var int */
private $status;
/** @var int */
private $creation;
/** @var int */
private $circleUniqueId;
/** @var string */
private $uniqueId = '';
/** @var string */
private $remoteCircleName;
/** @var string */
private $localCircleName;
/** @var bool */
private $fullJson = false;
public function __construct() {
}
/**
* @param int $id
*
* @return FederatedLink
*/
public function setId($id) {
$this->id = (int)$id;
return $this;
}
/**
* @return int
*/
public function getId() {
return $this->id;
}
/**
* @param $token
*
* @return $this
*/
public function setToken($token) {
$this->token = (string)$token;
return $this;
}
/**
* @param bool $full
*
* @return string
*/
public function getToken($full = false) {
if ($full) {
return $this->token;
}
return substr($this->token, 0, FederatedLink::SHORT_UNIQUE_ID_LENGTH);
}
/**
* @return string
*/
public function generateToken() {
$token = bin2hex(openssl_random_pseudo_bytes(24));
$this->setToken($token);
return $token;
}
/**
* @param string $address
*
* @return FederatedLink
*/
public function setAddress($address) {
$this->address = (string)$address;
return $this;
}
/**
* @return string
*/
public function getAddress() {
return $this->address;
}
/**
* @param string $address
*
* @return FederatedLink
*/
public function setLocalAddress($address) {
$this->localAddress = (string)$address;
return $this;
}
/**
* @return string
*/
public function getLocalAddress() {
return $this->localAddress;
}
/**
* @param string $circleUniqueId
*
* @return FederatedLink
*/
public function setCircleId($circleUniqueId) {
$this->circleUniqueId = $circleUniqueId;
return $this;
}
/**
* @param bool $full
*
* @return string
*/
public function getCircleId($full = false) {
if ($full) {
return $this->circleUniqueId;
}
return substr($this->circleUniqueId, 0, DeprecatedCircle::SHORT_UNIQUE_ID_LENGTH);
}
/**
* @param string $uniqueId
*
* @return FederatedLink
*/
public function setUniqueId($uniqueId) {
$this->uniqueId = (string)$uniqueId;
return $this;
}
/**
* @param bool $full
*
* @return string
*/
public function getUniqueId($full = false) {
if ($full) {
return $this->uniqueId;
}
return substr($this->uniqueId, 0, FederatedLink::SHORT_UNIQUE_ID_LENGTH);
}
/**
* @param string $circleName
*
* @return FederatedLink
*/
public function setRemoteCircleName($circleName) {
$this->remoteCircleName = (string)$circleName;
return $this;
}
/**
* @return string
*/
public function getRemoteCircleName() {
return $this->remoteCircleName;
}
/**
* @param string $circleName
*
* @return FederatedLink
*/
public function setCircleName($circleName) {
$this->localCircleName = (string)$circleName;
return $this;
}
/**
* @return string
*/
public function getCircleName() {
return $this->localCircleName;
}
/**
* @param int $status
*
* @return FederatedLink
*/
public function setStatus($status) {
$this->status = (int)$status;
return $this;
}
/**
* @return int
*/
public function getStatus() {
return $this->status;
}
/**
* @param int $creation
*
* @return FederatedLink
*/
public function setCreation($creation) {
if ($creation === null) {
return $this;
}
$this->creation = $creation;
return $this;
}
/**
* @return int
*/
public function getCreation() {
return $this->creation;
}
public function hasToBeValidStatusUpdate($status) {
try {
$this->hasToBeValidStatusUpdateWhileLinkDown($status);
$this->hasToBeValidStatusUpdateWhileRequestDeclined($status);
$this->hasToBeValidStatusUpdateWhileLinkRequested($status);
$this->hasToBeValidStatusUpdateWhileRequestSent($status);
} catch (FederatedCircleStatusUpdateException $e) {
throw new FederatedCircleStatusUpdateException('The status could not be updated');
}
}
/**
* @param $status
*
* @throws FederatedCircleStatusUpdateException
*/
private function hasToBeValidStatusUpdateWhileLinkDown($status) {
if ($this->getStatus() === self::STATUS_LINK_DOWN) {
return;
}
if ($status !== self::STATUS_LINK_REMOVE) {
throw new FederatedCircleStatusUpdateException();
}
}
/**
* @param $status
*
* @throws FederatedCircleStatusUpdateException
*/
private function hasToBeValidStatusUpdateWhileRequestDeclined($status) {
if ($this->getStatus() !== self::STATUS_REQUEST_DECLINED
&& $this->getStatus() !== self::STATUS_LINK_SETUP) {
return;
}
if ($status !== self::STATUS_LINK_REMOVE) {
throw new FederatedCircleStatusUpdateException();
}
}
/**
* @param $status
*
* @throws FederatedCircleStatusUpdateException
*/
private function hasToBeValidStatusUpdateWhileLinkRequested($status) {
if ($this->getStatus() !== self::STATUS_LINK_REQUESTED) {
return;
}
if ($status !== self::STATUS_LINK_REMOVE && $status !== self::STATUS_LINK_UP) {
throw new FederatedCircleStatusUpdateException();
}
}
/**
* @param $status
*
* @throws FederatedCircleStatusUpdateException
*/
private function hasToBeValidStatusUpdateWhileRequestSent($status) {
if ($this->getStatus() !== self::STATUS_REQUEST_SENT
&& $this->getStatus() !== self::STATUS_LINK_UP
) {
return;
}
if ($status !== self::STATUS_LINK_REMOVE) {
throw new FederatedCircleStatusUpdateException();
}
}
public function jsonSerialize() {
return [
'id' => $this->getId(),
'token' => $this->getToken($this->fullJson),
'address' => $this->getAddress(),
'status' => $this->getStatus(),
'circle_id' => $this->getCircleId(),
'unique_id' => $this->getUniqueId($this->fullJson),
'creation' => $this->getCreation()
];
}
public function getJson($full = false) {
$this->fullJson = $full;
$json = json_encode($this);
$this->fullJson = false;
return $json;
}
public static function fromArray($arr) {
if ($arr === null) {
return null;
}
$link = new FederatedLink();
$link->setId($arr['id']);
$link->setToken($arr['token']);
$link->setAddress($arr['address']);
$link->setStatus($arr['status']);
$link->setCircleId($arr['circle_id']);
$link->setUniqueId($arr['unique_id']);
$link->setCreation($arr['creation']);
return $link;
}
public static function fromJSON($json) {
return self::fromArray(json_decode($json, true));
}
}
@@ -0,0 +1,484 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use OCA\Circles\Tools\Db\IQueryRow;
use OCA\Circles\Tools\Exceptions\InvalidItemException;
use OCA\Circles\Tools\IDeserializable;
use OCA\Circles\Tools\Traits\TDeserialize;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
use OCA\Circles\Exceptions\FederatedUserNotFoundException;
use OCA\Circles\Exceptions\MembershipNotFoundException;
use OCA\Circles\Exceptions\OwnerNotFoundException;
use OCA\Circles\Exceptions\RequestBuilderException;
use OCA\Circles\Exceptions\UnknownInterfaceException;
use OCA\Circles\IFederatedUser;
use OCA\Circles\IEntity;
/**
* Class FederatedUser
*
* @package OCA\Circles\Model
*/
class FederatedUser extends ManagedModel implements
IFederatedUser,
IEntity,
IDeserializable,
IQueryRow,
JsonSerializable {
use TArrayTools;
use TDeserialize;
/** @var string */
private $singleId = '';
/** @var string */
private $userId;
/** @var int */
private $userType;
/** @var string */
private $displayName = '';
/** @var Circle */
private $basedOn;
/** @var int */
private $config = 0;
/** @var string */
private $instance;
/** @var Membership */
private $inheritance;
/** @var Membership[] */
private $memberships = null;
/**
* FederatedUser constructor.
*/
public function __construct() {
}
/**
* @param string $userId
* @param string $instance
* @param int $type
* @param string $displayName
* @param Circle|null $basedOn
*
* @return $this
*/
public function set(
string $userId,
string $instance = '',
int $type = Member::TYPE_USER,
string $displayName = '',
?Circle $basedOn = null
): self {
$this->userId = $userId;
$this->setInstance($instance);
$this->userType = $type;
$this->displayName = ($displayName === '') ? $userId : $displayName;
$this->basedOn = $basedOn;
return $this;
}
/**
* @param string $singleId
*
* @return self
*/
public function setSingleId(string $singleId): self {
$this->singleId = $singleId;
return $this;
}
/**
* @return string
*/
public function getSingleId(): string {
return $this->singleId;
}
/**
* @param string $userId
*
* @return self
*/
public function setUserId(string $userId): self {
$this->userId = $userId;
return $this;
}
/**
* @return string
*/
public function getUserId(): string {
return $this->userId;
}
/**
* @param int $userType
*
* @return self
*/
public function setUserType(int $userType): self {
$this->userType = $userType;
return $this;
}
/**
* @return int
*/
public function getUserType(): int {
return $this->userType;
}
/**
* @param string $displayName
*
* @return FederatedUser
*/
public function setDisplayName(string $displayName): self {
$this->displayName = $displayName;
return $this;
}
/**
* @return string
*/
public function getDisplayName(): string {
return $this->displayName;
}
/**
* @return bool
*/
public function hasBasedOn(): bool {
return !is_null($this->basedOn);
}
/**
* @param Circle|null $basedOn
*
* @return $this
*/
public function setBasedOn(Circle $basedOn): self {
$this->basedOn = $basedOn;
return $this;
}
/**
* @return Circle
*/
public function getBasedOn(): Circle {
return $this->basedOn;
}
/**
* @param int $config
*
* @return self
*/
public function setConfig(int $config): self {
$this->config = $config;
return $this;
}
/**
* @return int
*/
public function getConfig(): int {
return $this->config;
}
/**
* @param string $instance
*
* @return self
*/
public function setInstance(string $instance): self {
if ($instance === '') {
// TODO: is it needed ?
$instance = $this->getManager()->getLocalInstance();
}
$this->instance = $instance;
return $this;
}
/**
* @return string
*/
public function getInstance(): string {
return $this->instance;
}
/**
* @return bool
*/
public function isLocal(): bool {
return $this->getManager()->isLocalInstance($this->getInstance());
}
/**
* @return bool
*/
public function hasInheritance(): bool {
return !is_null($this->inheritance);
}
/**
* @param Membership $inheritance
*
* @return $this
*/
public function setInheritance(Membership $inheritance): self {
$this->inheritance = $inheritance;
return $this;
}
/**
* @return Membership
*/
public function getInheritance(): Membership {
return $this->inheritance;
}
/**
* @return bool
*/
public function hasMemberships(): bool {
return !is_null($this->memberships);
}
/**
* @param array $memberships
*
* @return self
*/
public function setMemberships(array $memberships): IEntity {
$this->memberships = $memberships;
return $this;
}
/**
* @return Membership[]
*/
public function getMemberships(): array {
if (!$this->hasMemberships()) {
$this->getManager()->getMemberships($this);
}
return $this->memberships;
}
/**
* @param string $singleId
* @param bool $detailed
*
* @return Membership
* @throws MembershipNotFoundException
* @throws RequestBuilderException
*/
public function getLink(string $singleId, bool $detailed = false): Membership {
return $this->getManager()->getLink($this, $singleId, $detailed);
}
/**
* @param array $data
*
* @return $this
* @throws InvalidItemException
*/
public function import(array $data): IDeserializable {
if ($this->get('userId', $data) === '') {
throw new InvalidItemException();
}
$this->setSingleId($this->get('id', $data));
$this->setUserId($this->get('userId', $data));
$this->setUserType($this->getInt('userType', $data));
$this->setDisplayName($this->get('displayName', $data));
$this->setInstance($this->get('instance', $data));
//$this->setMemberships($this->getArray('memberships'));
try {
/** @var Circle $circle */
$circle = $this->deserialize($this->getArray('basedOn', $data), Circle::class);
$this->setBasedOn($circle);
} catch (InvalidItemException $e) {
}
try {
/** @var Membership $membership */
$membership = $this->deserialize($this->getArray('membership', $data), Membership::class);
$this->setInheritance($membership);
} catch (InvalidItemException $e) {
}
return $this;
}
/**
* @param Circle $circle
*
* @return FederatedUser
* @throws OwnerNotFoundException
*/
public function importFromCircle(Circle $circle): self {
if (!$circle->hasOwner()) {
throw new OwnerNotFoundException();
}
$this->setSingleId($circle->getSingleId());
if ($circle->isConfig(Circle::CFG_SINGLE)) {
$owner = $circle->getOwner();
$this->set(
$owner->getUserId(),
$owner->getInstance(),
$owner->getUserType(),
$owner->getDisplayName(),
$circle
);
} else {
$this->set(
$circle->getDisplayName(),
$circle->getInstance(),
Member::TYPE_CIRCLE,
$circle->getDisplayName(),
$circle
);
}
return $this;
}
/**
* @param array $data
* @param string $prefix
*
* @return IQueryRow
* @throws FederatedUserNotFoundException
*/
public function importFromDatabase(array $data, string $prefix = ''): IQueryRow {
if ($this->get($prefix . 'single_id', $data) === '') {
throw new FederatedUserNotFoundException();
}
$this->setSingleId($this->get($prefix . 'single_id', $data));
$this->setUserId($this->get($prefix . 'user_id', $data));
$this->setUserType($this->getInt($prefix . 'user_type', $data));
$this->setDisplayName($this->get($prefix . 'cached_name', $data));
$this->setInstance($this->get($prefix . 'instance', $data));
$this->getManager()->manageImportFromDatabase($this, $data, $prefix);
return $this;
}
/**
* @return string[]
* @throws UnknownInterfaceException
*/
public function jsonSerialize(): array {
$arr = [
'id' => $this->getSingleId(),
'userId' => $this->getUserId(),
'userType' => $this->getUserType(),
'displayName' => $this->getDisplayName(),
'instance' => $this->getManager()->fixInstance($this->getInstance())
];
if ($this->hasBasedOn()) {
$arr['basedOn'] = $this->getBasedOn();
}
if ($this->hasInheritance()) {
$arr['inheritance'] = $this->getInheritance();
}
if (!is_null($this->memberships)) {
$arr['memberships'] = $this->getMemberships();
}
return $arr;
}
/**
* @param IFederatedUser $member
*
* @return bool
*/
public function compareWith(IFederatedUser $member): bool {
$local = ($this->getManager()->isLocalInstance($this->getInstance())
&& $this->getManager()->isLocalInstance($member->getInstance()));
return !($this->getSingleId() !== $member->getSingleId()
|| $this->getUserId() !== $member->getUserId()
|| $this->getUserType() <> $member->getUserType()
|| (!$local && $this->getInstance() !== $member->getInstance()));
}
}
@@ -0,0 +1,563 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use JsonSerializable;
use OCA\Circles\Db\CoreQueryBuilder;
use OCA\Circles\Exceptions\FileCacheNotFoundException;
use OCA\Circles\Tools\Db\IQueryRow;
use OCA\Circles\Tools\Exceptions\InvalidItemException;
use OCA\Circles\Tools\IDeserializable;
use OCA\Circles\Tools\Traits\TArrayTools;
/**
* Class FileCacheWrapper
*
* @package OCA\Circles\Model
*/
class FileCacheWrapper extends ManagedModel implements IQueryRow, IDeserializable, JsonSerializable {
use TArrayTools;
/** @var int */
private $id = 0;
/** @var string */
private $path = '';
/** @var int */
private $permissions = 0;
/** @var int */
private $storageId = 0;
/** @var string */
private $pathHash = '';
/** @var int */
private $parent = 0;
/** @var string */
private $name = '';
/** @var int */
private $mimeType = 0;
/** @var int */
private $mimePart = 0;
/** @var int */
private $size = 0;
/** @var int */
private $mTime = 0;
/** @var int */
private $storageMTime = 0;
/** @var bool */
private $encrypted = false;
/** @var int */
private $unencryptedSize = 0;
/** @var string */
private $etag = '';
/** @var string */
private $checksum = '';
/** @var string */
private $storage = '';
/**
* @param int $id
*
* @return FileCacheWrapper
*/
public function setId(int $id): self {
$this->id = $id;
return $this;
}
/**
* @return int
*/
public function getId(): int {
return $this->id;
}
/**
* @param string $path
*
* @return FileCacheWrapper
*/
public function setPath(string $path): self {
$this->path = $path;
return $this;
}
/**
* @return string
*/
public function getPath(): string {
return $this->path;
}
/**
* @param string $pathHash
*
* @return FileCacheWrapper
*/
public function setPathHash(string $pathHash): self {
$this->pathHash = $pathHash;
return $this;
}
/**
* @return string
*/
public function getPathHash(): string {
return $this->pathHash;
}
/**
* @param string $name
*
* @return FileCacheWrapper
*/
public function setName(string $name): self {
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getName(): string {
return $this->name;
}
/**
* @param int $storageMTime
*
* @return FileCacheWrapper
*/
public function setStorageMTime(int $storageMTime): self {
$this->storageMTime = $storageMTime;
return $this;
}
/**
* @return int
*/
public function getStorageMTime(): int {
return $this->storageMTime;
}
/**
* @param bool $encrypted
*
* @return FileCacheWrapper
*/
public function setEncrypted(bool $encrypted): self {
$this->encrypted = $encrypted;
return $this;
}
/**
* @return bool
*/
public function isEncrypted(): bool {
return $this->encrypted;
}
/**
* @param int $unencryptedSize
*
* @return FileCacheWrapper
*/
public function setUnencryptedSize(int $unencryptedSize): self {
$this->unencryptedSize = $unencryptedSize;
return $this;
}
/**
* @return int
*/
public function getUnencryptedSize(): int {
return $this->unencryptedSize;
}
/**
* @param string $etag
*
* @return FileCacheWrapper
*/
public function setEtag(string $etag): self {
$this->etag = $etag;
return $this;
}
/**
* @return string
*/
public function getEtag(): string {
return $this->etag;
}
/**
* @param string $checksum
*
* @return FileCacheWrapper
*/
public function setChecksum(string $checksum): self {
$this->checksum = $checksum;
return $this;
}
/**
* @return string
*/
public function getChecksum(): string {
return $this->checksum;
}
/**
* @param int $size
*
* @return FileCacheWrapper
*/
public function setSize(int $size): self {
$this->size = $size;
return $this;
}
/**
* @return int
*/
public function getSize(): int {
return $this->size;
}
/**
* @param int $mTime
*
* @return FileCacheWrapper
*/
public function setMTime(int $mTime): self {
$this->mTime = $mTime;
return $this;
}
/**
* @return int
*/
public function getMTime(): int {
return $this->mTime;
}
/**
* @param int $mimeType
*
* @return FileCacheWrapper
*/
public function setMimeType(int $mimeType): self {
$this->mimeType = $mimeType;
return $this;
}
/**
* @return int
*/
public function getMimeType(): int {
return $this->mimeType;
}
/**
* @param int $mimePart
*
* @return FileCacheWrapper
*/
public function setMimePart(int $mimePart): self {
$this->mimePart = $mimePart;
return $this;
}
/**
* @return int
*/
public function getMimePart(): int {
return $this->mimePart;
}
/**
* @param int $storageId
*
* @return FileCacheWrapper
*/
public function setStorageId(int $storageId): self {
$this->storageId = $storageId;
return $this;
}
/**
* @return int
*/
public function getStorageId(): int {
return $this->storageId;
}
/**
* @param string $storage
*
* @return FileCacheWrapper
*/
public function setStorage(string $storage): self {
$this->storage = $storage;
return $this;
}
/**
* @return string
*/
public function getStorage(): string {
return $this->storage;
}
/**
* @param int $permissions
*
* @return FileCacheWrapper
*/
public function setPermissions(int $permissions): self {
$this->permissions = $permissions;
return $this;
}
/**
* @return int
*/
public function getPermissions(): int {
return $this->permissions;
}
/**
* @param int $parent
*
* @return FileCacheWrapper
*/
public function setParent(int $parent): self {
$this->parent = $parent;
return $this;
}
/**
* @return int
*/
public function getParent(): int {
return $this->parent;
}
/**
* @return array
*/
public function toCache(): array {
return [
'fileid' => $this->getId(),
'path' => $this->getPath(),
'permissions' => $this->getPermissions(),
'storage' => $this->getStorageId(), // strange, it is not !?
'path_hash' => $this->getPathHash(),
'parent' => $this->getParent(),
'name' => $this->getName(),
'mimetype' => $this->getMimeType(),
'mimepart' => $this->getMimePart(),
'size' => $this->getSize(),
'mtime' => $this->getMTime(),
'storage_mtime' => $this->getStorageMTime(),
'encrypted' => $this->isEncrypted(),
'unencrypted_size' => $this->getUnencryptedSize(),
'etag' => $this->getEtag(),
'checksum' => $this->getChecksum()
];
}
/**
* Returns whether the given database result can be interpreted as
* a share with accessible file (not trashed, not deleted)
*
* @return bool
*/
public function isAccessible(): bool {
if ($this->getId() === 0) {
return false;
}
$path = $this->getPath();
[$storageType,] = explode('::', $this->getStorage(), 2);
if ($path === '') {
// we only accept empty path on external storage
return (in_array($storageType, ['local', 'webdav', 'ftp', 'sftp', 'swift', 'smb', 'amazon']));
}
return !(explode('/', $path, 2)[0] !== 'files' && $storageType === 'home');
}
/**
* @param array $data
*
* @return self
* @throws InvalidItemException
*/
public function import(array $data): IDeserializable {
if ($this->getInt('id', $data) === 0) {
throw new InvalidItemException();
}
$this->setId($this->getInt('id', $data))
->setPath($this->get('path', $data))
->setPermissions($this->getInt('permissions', $data))
->setStorage($this->get('storage', $data))
->setStorageId($this->getInt('storageId', $data))
->setPathHash($this->get('pathHash', $data))
->setParent($this->getInt('parent', $data))
->setName($this->get('name', $data))
->setMimeType($this->getInt('mimeType', $data))
->setMimePart($this->getInt('mimePart', $data))
->setSize($this->getInt('size', $data))
->setMTime($this->getInt('mTime', $data))
->setStorageMTime($this->getInt('storageMTime', $data))
->setEncrypted($this->getBool('encrypted', $data))
->setUnencryptedSize($this->getInt('unencryptedSize', $data))
->setEtag($this->get('etag', $data))
->setChecksum($this->get('checksum', $data));
return $this;
}
/**
* @param array $data
* @param string $prefix
*
* @return IQueryRow
* @throws FileCacheNotFoundException
*/
public function importFromDatabase(array $data, string $prefix = ''): IQueryRow {
if ($this->getInt($prefix . 'fileid', $data) === 0) {
throw new FileCacheNotFoundException();
}
$this->setId($this->getInt($prefix . 'fileid', $data));
$this->setPath($this->get($prefix . 'path', $data));
$this->setPermissions($this->getInt($prefix . 'permissions', $data));
$this->setStorageId($this->getInt($prefix . 'storage', $data));
$this->setPathHash($this->get($prefix . 'path_hash', $data));
$this->setParent($this->getInt($prefix . 'parent', $data));
$this->setName($this->get($prefix . 'name', $data));
$this->setMimeType($this->getInt($prefix . 'mimetype', $data));
$this->setMimePart($this->getInt($prefix . 'mimepart', $data));
$this->setSize($this->getInt($prefix . 'size', $data));
$this->setMTime($this->getInt($prefix . 'mtime', $data));
$this->setStorageMTime($this->getInt($prefix . 'storage_mtime', $data));
$this->setEncrypted($this->getBool($prefix . 'encrypted', $data));
$this->setUnencryptedSize($this->getInt($prefix . 'unencrypted_size', $data));
$this->setEtag($this->get($prefix . 'etag', $data));
$this->setChecksum($this->get($prefix . 'checksum', $data));
// small hack as there is no reason to call a recursive method for a single entry from the table
$this->setStorage($this->get($prefix . CoreQueryBuilder::STORAGES . '_id', $data));
return $this;
}
/**
* @return string[]
*/
public function jsonSerialize(): array {
return [
'id' => $this->getId(),
'path' => $this->getPath(),
'permissions' => $this->getPermissions(),
'storage' => $this->getStorage(),
'storageId' => $this->getStorageId(),
'pathHash' => $this->getPathHash(),
'parent' => $this->getParent(),
'name' => $this->getName(),
'mimeType' => $this->getMimeType(),
'mimePart' => $this->getMimePart(),
'size' => $this->getSize(),
'mTime' => $this->getMTime(),
'storageMTime' => $this->getStorageMTime(),
'encrypted' => $this->isEncrypted(),
'unencryptedSize' => $this->getUnencryptedSize(),
'etag' => $this->getEtag(),
'checksum' => $this->getChecksum()
];
}
}
@@ -0,0 +1,472 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model\GlobalScale;
use JsonSerializable;
use OCA\Circles\Exceptions\JsonException;
use OCA\Circles\Exceptions\ModelException;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\DeprecatedCircle;
use OCA\Circles\Model\DeprecatedMember;
use OCA\Circles\Tools\Model\SimpleDataStore;
use OCA\Circles\Tools\Traits\TArrayTools;
/**
* Class GSEvent
*
* @package OCA\Circles\Model\GlobalScale
*/
class GSEvent implements JsonSerializable {
public const SEVERITY_LOW = 1;
public const SEVERITY_HIGH = 3;
public const TEST = '\OCA\Circles\GlobalScale\Test';
public const CIRCLE_STATUS = '\OCA\Circles\GlobalScale\CircleStatus';
public const CIRCLE_CREATE = '\OCA\Circles\GlobalScale\CircleCreate';
public const MEMBER_ADD = '\OCA\Circles\GlobalScale\MemberAdd';
public const MEMBER_JOIN = '\OCA\Circles\GlobalScale\MemberJoin';
public const MEMBER_LEAVE = '\OCA\Circles\GlobalScale\MemberLeave';
public const MEMBER_LEVEL = '\OCA\Circles\GlobalScale\MemberLevel';
public const MEMBER_UPDATE = '\OCA\Circles\GlobalScale\MemberUpdate';
public const MEMBER_REMOVE = '\OCA\Circles\GlobalScale\MemberRemove';
public const USER_DELETED = '\OCA\Circles\GlobalScale\UserDeleted';
public const FILE_SHARE = '\OCA\Circles\GlobalScale\FileShare';
public const FILE_UNSHARE = '\OCA\Circles\GlobalScale\FileUnshare';
use TArrayTools;
/** @var string */
private $type = '';
/** @var string */
private $source = '';
/** @var DeprecatedCircle */
private $deprecatedCircle;
/** @var Circle */
private $circle;
/** @var DeprecatedMember */
private $member;
/** @var SimpleDataStore */
private $data;
/** @var int */
private $severity = self::SEVERITY_LOW;
/** @var SimpleDataStore */
private $result;
/** @var string */
private $key = '';
/** @var bool */
private $local = false;
/** @var bool */
private $force = false;
/** @var bool */
private $async = false;
/** @var bool */
private $checked = false;
/**
* GSEvent constructor.
*
* @param string $type
* @param bool $local
* @param bool $force
*/
public function __construct(string $type = '', bool $local = false, bool $force = false) {
$this->type = $type;
$this->local = $local;
$this->force = $force;
$this->data = new SimpleDataStore();
$this->result = new SimpleDataStore();
}
/**
* @return string
*/
public function getType(): string {
return $this->type;
}
/**
* @param mixed $type
*
* @return GSEvent
*/
public function setType($type): self {
$this->type = $type;
return $this;
}
/**
* @return string
*/
public function getSource(): string {
return $this->source;
}
/**
* @param string $source
*
* @return GSEvent
*/
public function setSource(string $source): self {
$this->source = $source;
if ($this->hasMember() && $this->member->getInstance() === '') {
$this->member->setInstance($source);
}
if ($this->hasCircle()
&& $this->getDeprecatedCircle()
->hasViewer()
&& $this->getDeprecatedCircle()
->getViewer()
->getInstance() === '') {
$this->getDeprecatedCircle()
->getViewer()
->setInstance($source);
}
return $this;
}
/**
* @return bool
*/
public function isLocal(): bool {
return $this->local;
}
/**
* @param bool $local
*
* @return GSEvent
*/
public function setLocal(bool $local): self {
$this->local = $local;
return $this;
}
/**
* @return bool
*/
public function isForced(): bool {
return $this->force;
}
/**
* @param bool $force
*
* @return GSEvent
*/
public function setForced(bool $force): self {
$this->force = $force;
return $this;
}
/**
* @return bool
*/
public function isAsync(): bool {
return $this->async;
}
/**
* @param bool $async
*
* @return GSEvent
*/
public function setAsync(bool $async): self {
$this->async = $async;
return $this;
}
/**
* @return DeprecatedCircle
* @deprecated
*/
public function getDeprecatedCircle(): DeprecatedCircle {
return $this->deprecatedCircle;
}
/**
* @param DeprecatedCircle $deprecatedCircle
*
* @return GSEvent
* @deprecated
*/
public function setDeprecatedCircle(DeprecatedCircle $deprecatedCircle): self {
$this->deprecatedCircle = $deprecatedCircle;
return $this;
}
/**
* @return bool
*/
public function hasCircle(): bool {
return ($this->deprecatedCircle !== null || $this->circle !== null);
}
/**
* @param Circle $circle
*
* @return GSEvent
*/
public function setCircle(Circle $circle): self {
$this->circle = $circle;
return $this;
}
/**
* @return Circle
*/
public function getCircle(): Circle {
return $this->circle;
}
/**
* @return DeprecatedMember
*/
public function getMember(): DeprecatedMember {
return $this->member;
}
/**
* @param DeprecatedMember $member
*
* @return GSEvent
*/
public function setMember(DeprecatedMember $member): self {
$this->member = $member;
return $this;
}
/**
* @return bool
*/
public function hasMember(): bool {
return ($this->member !== null);
}
/**
* @param SimpleDataStore $data
*
* @return GSEvent
*/
public function setData(SimpleDataStore $data): self {
$this->data = $data;
return $this;
}
/**
* @return SimpleDataStore
*/
public function getData(): SimpleDataStore {
return $this->data;
}
/**
* @return int
*/
public function getSeverity(): int {
return $this->severity;
}
/**
* @param int $severity
*
* @return GSEvent
*/
public function setSeverity(int $severity): self {
$this->severity = $severity;
return $this;
}
/**
* @return SimpleDataStore
*/
public function getResult(): SimpleDataStore {
return $this->result;
}
/**
* @param SimpleDataStore $result
*
* @return GSEvent
*/
public function setResult(SimpleDataStore $result): self {
$this->result = $result;
return $this;
}
/**
* @return string
*/
public function getKey(): string {
return $this->key;
}
/**
* @param string $key
*
* @return GSEvent
*/
public function setKey(string $key): self {
$this->key = $key;
return $this;
}
/**
* @return bool
*/
public function isValid(): bool {
if ($this->getType() === '') {
return false;
}
return true;
}
/**
* @param string $json
*
* @return GSEvent
* @throws JsonException
* @throws ModelException
*/
public function importFromJson(string $json): self {
$data = json_decode($json, true);
if (!is_array($data)) {
throw new JsonException('invalid JSON');
}
return $this->import($data);
}
/**
* @param array $data
*
* @return GSEvent
* @throws ModelException
*/
public function import(array $data): self {
$this->setType($this->get('type', $data));
$this->setSeverity($this->getInt('severity', $data));
$this->setData(new SimpleDataStore($this->getArray('data', $data)));
$this->setResult(new SimpleDataStore($this->getArray('result', $data)));
$this->setSource($this->get('source', $data));
$this->setKey($this->get('key', $data));
$this->setForced($this->getBool('force', $data));
$this->setAsync($this->getBool('async', $data));
if (array_key_exists('circle', $data)) {
$this->setDeprecatedCircle(DeprecatedCircle::fromArray($data['circle']));
}
if (array_key_exists('member', $data)) {
$this->setMember(DeprecatedMember::fromArray($data['member']));
}
if (!$this->isValid()) {
throw new ModelException('invalid GSEvent');
}
return $this;
}
/**
* @return array
*/
public function jsonSerialize(): array {
$arr = [
'type' => $this->getType(),
'severity' => $this->getSeverity(),
'data' => $this->getData(),
'result' => $this->getResult(),
'key' => $this->getKey(),
'source' => $this->getSource(),
'force' => $this->isForced(),
'async' => $this->isAsync()
];
if ($this->hasCircle()) {
$arr['circle'] = $this->getDeprecatedCircle();
}
if ($this->hasMember()) {
$arr['member'] = $this->getMember();
}
$this->cleanArray($arr);
return $arr;
}
}
@@ -0,0 +1,318 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model\GlobalScale;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
/**
* Class GSShare
*
* @package OCA\Circles\Model\GlobalScale
*/
class GSShare implements JsonSerializable {
use TArrayTools;
/** @var int */
private $id = 0;
/** @var string */
private $circleId = '';
/** @var string */
private $defaultMountPoint = '';
/** @var string */
private $mountPoint = '';
/** @var int */
private $parent = -1;
/** @var string */
private $owner = '';
/** @var string */
private $instance = '';
/** @var string */
private $token = '';
/** @var string */
private $password = '';
/**
* GSShare constructor.
*
* @param string $circleId
* @param string $token
*/
public function __construct(string $circleId = '', string $token = '') {
$this->circleId = $circleId;
$this->token = $token;
}
/**
* @return int
*/
public function getId(): int {
return $this->id;
}
public function setId(int $id): self {
$this->id = $id;
return $this;
}
/**
*
* @return string
*/
public function getCircleId(): string {
return $this->circleId;
}
/**
* @param string $circleId
*
* @return GSShare
*/
public function setCircleId(string $circleId): self {
$this->circleId = $circleId;
return $this;
}
/**
* @return string
*/
public function getDefaultMountPoint(): string {
return $this->defaultMountPoint;
}
/**
* @param string $mountPoint
*
* @return GSShare
*/
public function setDefaultMountPoint(string $mountPoint): self {
$this->defaultMountPoint = $mountPoint;
return $this;
}
/**
* @param string $userId
*
* @return string
*/
public function getMountPoint(string $userId = ''): string {
$mountPoint = $this->mountPoint;
if ($mountPoint === '') {
$mountPoint = $this->defaultMountPoint;
}
if ($userId === '') {
return $mountPoint;
}
return '/' . $userId . '/files/' . ltrim($mountPoint, '/');
}
/**
* @param string $mountPoint
*
* @return GSShare
*/
public function setMountPoint(string $mountPoint): self {
$this->mountPoint = $mountPoint;
return $this;
}
/**
* @return int
*/
public function getParent(): int {
return $this->parent;
}
/**
* @param int $parent
*
* @return GSShare
*/
public function setParent(int $parent): self {
$this->parent = $parent;
return $this;
}
/**
* @return string
*/
public function getOwner(): string {
return $this->owner;
}
/**
* @param string $owner
*
* @return GSShare
*/
public function setOwner(string $owner): self {
$this->owner = $owner;
return $this;
}
/**
* @return string
*/
public function getInstance(): string {
return $this->instance;
}
/**
* @param string $instance
*
* @return GSShare
*/
public function setInstance(string $instance): self {
$this->instance = $instance;
return $this;
}
/**
* @return string
*/
public function getToken(): string {
return $this->token;
}
/**
* @param string $token
*
* @return GSShare
*/
public function setToken(string $token): self {
$this->token = $token;
return $this;
}
/**
* @return string
*/
public function getPassword(): string {
return $this->password;
}
/**
* @param string $password
*
* @return GSShare
*/
public function setPassword(string $password): self {
$this->password = $password;
return $this;
}
/**
* @param array $data
*
* @return GSShare
*/
public function importFromDatabase(array $data): self {
$this->setId($this->getInt('id', $data));
$this->setCircleId($this->get('circle_id', $data));
$this->setOwner($this->get('owner', $data));
$this->setInstance($this->get('instance', $data));
$this->setToken($this->get('token', $data));
$this->setParent($this->getInt('parent', $data));
$this->setMountPoint($this->get('gsshares_mountpoint', $data));
$this->setDefaultMountPoint($this->get('mountpoint', $data));
return $this;
}
/**
* @param string $userId
* @param string $protocol
*
* @return array
*/
public function toMount(string $userId, string $protocol = 'https'): array {
return [
'owner' => $this->getOwner(),
'remote' => $protocol . '://' . $this->getInstance(),
'token' => $this->getToken(),
'share_token' => $this->getToken(),
'password' => $this->getPassword(),
'mountpoint' => $this->getMountPoint($userId)
];
}
/**
* @return array
*/
public function jsonSerialize(): array {
return [
'id' => $this->getId(),
'defaultMountPoint' => $this->getDefaultMountPoint(),
'mountPoint' => $this->getMountPoint(),
'parent' => $this->getParent(),
'owner' => $this->getOwner(),
'instance' => $this->getInstance(),
'token' => $this->getToken(),
'password' => $this->getPassword()
];
}
}
@@ -0,0 +1,151 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model\GlobalScale;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
/**
* Class GSShare
*
* @package OCA\Circles\Model\GlobalScale
*/
class GSShareMountpoint implements JsonSerializable {
use TArrayTools;
/** @var int */
private $shareId = 0;
/** @var string */
private $userId = '';
/** @var string */
private $mountPoint = '';
/**
* GSShareMountpoint constructor.
*
* @param int $shareId
* @param string $userId
* @param string $mountPoint
*/
public function __construct(int $shareId = 0, string $userId = '', string $mountPoint = '') {
$this->shareId = $shareId;
$this->userId = $userId;
$this->mountPoint = $mountPoint;
}
/**
* @return string
*/
public function getUserId(): string {
return $this->userId;
}
/**
* @param string $userId
*
* @return GSShareMountpoint
*/
public function setUserId(string $userId): self {
$this->userId = $userId;
return $this;
}
/**
* @return int
*/
public function getShareId(): int {
return $this->shareId;
}
/**
* @param int $shareId
*
* @return $this
*/
public function setShareId(int $shareId): self {
$this->shareId = $shareId;
return $this;
}
/**
* @return string
*/
public function getMountPoint(): string {
return $this->mountPoint;
}
/**
* @param string $mountPoint
*
* @return GSShareMountpoint
*/
public function setMountPoint(string $mountPoint): self {
$this->mountPoint = $mountPoint;
return $this;
}
/**
* @param array $data
*
* @return GSShareMountpoint
*/
public function importFromDatabase(array $data): self {
$this->setShareId($this->getInt('share_id', $data));
$this->setUserId($this->get('user_id', $data));
$this->setMountPoint($this->get('mountpoint', $data));
return $this;
}
/**
* @return array
*/
public function jsonSerialize(): array {
return [
'userId' => $this->getUserId(),
'shareId' => $this->getShareId(),
'mountPoint' => $this->getMountPoint(),
];
}
}
@@ -0,0 +1,238 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model\GlobalScale;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
use OCA\Circles\Exceptions\JsonException;
use OCA\Circles\Exceptions\ModelException;
/**
* Class GSEvent
*
* @package OCA\Circles\Model\GlobalScale
*/
class GSWrapper implements JsonSerializable {
use TArrayTools;
public const STATUS_INIT = 0;
public const STATUS_FAILED = 1;
public const STATUS_DONE = 8;
public const STATUS_OVER = 9;
/** @var string */
private $token = '';
/** @var GSEvent */
private $event;
/** @var string */
private $instance = '';
/** @var int */
private $severity = GSEvent::SEVERITY_LOW;
/** @var int */
private $status = 0;
/** @var int */
private $creation;
public function __construct() {
}
/**
* @return string
*/
public function getToken(): string {
return $this->token;
}
/**
* @param string $token
*
* @return GSWrapper
*/
public function setToken(string $token): self {
$this->token = $token;
return $this;
}
/**
* @return GSEvent
*/
public function getEvent(): GSEvent {
return $this->event;
}
/**
* @param GSEvent $event
*
* @return GSWrapper
*/
public function setEvent(GSEvent $event): self {
$this->event = $event;
return $this;
}
/**
* @return bool
*/
public function hasEvent(): bool {
return ($this->event !== null);
}
/**
* @return string
*/
public function getInstance(): string {
return $this->instance;
}
/**
* @param string $instance
*
* @return GSWrapper
*/
public function setInstance(string $instance): self {
$this->instance = $instance;
return $this;
}
/**
* @return int
*/
public function getSeverity(): int {
return $this->severity;
}
/**
* @param int $severity
*
* @return GSWrapper
*/
public function setSeverity(int $severity): self {
$this->severity = $severity;
return $this;
}
/**
* @return int
*/
public function getStatus(): int {
return $this->status;
}
/**
* @param int $status
*
* @return GSWrapper
*/
public function setStatus(int $status): self {
$this->status = $status;
return $this;
}
/**
* @return int
*/
public function getCreation(): int {
return $this->creation;
}
/**
* @param int $creation
*
* @return GSWrapper
*/
public function setCreation(int $creation): self {
$this->creation = $creation;
return $this;
}
/**
* @param array $data
*
* @return GSWrapper
* @throws JsonException
* @throws ModelException
*/
public function import(array $data): self {
$this->setToken($this->get('token', $data));
$this->setInstance($this->get('instance', $data));
$this->setSeverity($this->getInt('severity', $data, GSEvent::SEVERITY_LOW));
$this->setStatus($this->getInt('status', $data, GSWrapper::STATUS_INIT));
$event = new GSEvent();
$event->importFromJson($this->get('event', $data));
$this->setEvent($event);
$this->setCreation($this->getInt('creation', $data));
return $this;
}
/**
* @return array
*/
public function jsonSerialize(): array {
$arr = [
'id' => $this->getToken(),
'event' => $this->getEvent(),
'severity' => $this->getSeverity(),
'status' => $this->getStatus(),
'creation' => $this->getCreation()
];
$this->cleanArray($arr);
return $arr;
}
}
@@ -0,0 +1,186 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model\Helpers;
use OCA\Circles\Tools\Traits\TArrayTools;
use OCA\Circles\Exceptions\MemberHelperException;
use OCA\Circles\Exceptions\MemberLevelException;
use OCA\Circles\Exceptions\ParseMemberLevelException;
use OCA\Circles\Model\Member;
/**
* Class MemberHelper
*
* @method void mustBeMember() @throws MemberHelperException, MemberLevelException
* @method void mustBeModerator() @throws MemberHelperException, MemberLevelException
* @method void mustBeAdmin() @throws MemberHelperException, MemberLevelException
* @method void mustBeOwner() @throws MemberHelperException, MemberLevelException
* @method void cannotBeMember() @throws MemberHelperException, MemberLevelException
* @method void cannotBeModerator() @throws MemberHelperException, MemberLevelException
* @method void cannotBeAdmin() @throws MemberHelperException, MemberLevelException
* @method void cannotBeOwner() @throws MemberHelperException, MemberLevelException
*
* @package OCA\Circles\Model\Helpers
*/
class MemberHelper {
use TArrayTools;
/** @var Member */
private $member;
/**
* Member constructor.
*
* @param Member $member
*/
public function __construct(Member $member) {
$this->member = $member;
}
/**
* @param string $name
* @param array $arguments
*
* @throws MemberHelperException
* @throws MemberLevelException
*/
public function __call(string $name, array $arguments): void {
if (substr(strtolower($name), 0, 8) === 'cannotbe') {
$this->cannotBe(substr($name, 8), $arguments);
return;
}
if (substr(strtolower($name), 0, 6) === 'mustbe') {
$this->mustBe(substr($name, 6), $arguments);
return;
}
throw new MemberHelperException('unknown method call');
}
/**
* @param string $levelString
* @param array $arguments
*
* @throws MemberHelperException
* @throws MemberLevelException
*/
private function mustBe(string $levelString, array $arguments): void {
try {
$level = Member::parseLevelString($levelString);
} catch (ParseMemberLevelException $e) {
throw new MemberHelperException('method ' . $levelString . ' not found');
}
$this->mustHaveLevelEqualOrAbove($level);
}
/**
* @param string $levelString
* @param array $arguments
*
* @throws MemberHelperException
* @throws MemberLevelException
*/
private function cannotBe(string $levelString, array $arguments): void {
try {
$level = Member::parseLevelString($levelString);
} catch (ParseMemberLevelException $e) {
throw new MemberHelperException('method ' . $levelString . ' not found');
}
if ($this->member->getLevel() >= $level) {
throw new MemberLevelException('Member cannot be ' . $levelString);
}
}
/**
* @param int $level
*
* @throws MemberLevelException
*/
public function mustHaveLevelAbove(int $level) {
if ($this->member->getLevel() <= $level) {
throw new MemberLevelException('Insufficient rights');
}
}
/**
* @param int $level
*
* @throws MemberLevelException
*/
public function mustHaveLevelAboveOrEqual(int $level) {
if ($this->member->getLevel() < $level) {
throw new MemberLevelException('Insufficient rights');
}
}
/**
* @param int $level
*
* @throws MemberLevelException
*/
public function mustHaveLevelEqualOrAbove(int $level) {
if ($this->member->getLevel() < $level) {
throw new MemberLevelException('Insufficient rights');
}
}
/**
* @param Member $compare
*
* @throws MemberLevelException
*/
public function mustBeHigherLevelThan(Member $compare) {
$this->mustHaveLevelAbove($compare->getLevel());
}
/**
* @param Member $compare
*
* @throws MemberLevelException
*/
public function mustBeHigherOrSameLevelThan(Member $compare) {
$this->mustHaveLevelEqualOrAbove($compare->getLevel());
}
}
@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use OC;
use OCA\Circles\IFederatedUser;
/**
* Class ManagedModel
*
* @package OCA\Circles\Model
*/
class ManagedModel {
public const ID_LENGTH = 31;
/** @var ModelManager */
private $modelManager;
/**
* @return ModelManager
*/
protected function getManager(): ModelManager {
if ($this->modelManager === null) {
$this->modelManager = OC::$server->get(ModelManager::class);
}
return $this->modelManager;
}
/** @noinspection PhpPossiblePolymorphicInvocationInspection */
public function importFromIFederatedUser(IFederatedUser $orig): void {
if (!($this instanceof IFederatedUser)) {
return;
}
// TODO : move those methods to this class ?
$this->setSingleId($orig->getSingleId());
$this->setUserId($orig->getUserId());
$this->setUserType($orig->getUserType());
$this->setDisplayName($orig->getDisplayName());
if ($orig->hasBasedOn()) {
$this->setBasedOn($orig->getBasedOn());
}
$this->setInstance($orig->getInstance());
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,343 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use JsonSerializable;
use OCA\Circles\Exceptions\MembershipNotFoundException;
use OCA\Circles\Tools\Db\IQueryRow;
use OCA\Circles\Tools\Exceptions\InvalidItemException;
use OCA\Circles\Tools\IDeserializable;
use OCA\Circles\Tools\Traits\TArrayTools;
/**
* Class Membership
*
* @package OCA\Circles\Model
*/
class Membership extends ManagedModel implements IDeserializable, IQueryRow, JsonSerializable {
use TArrayTools;
/** @var string */
private $singleId = '';
/** @var string */
private $circleId = '';
/** @var int */
private $circleConfig = 0;
/** @var int */
private $level = 0;
/** @var string */
private $inheritanceFirst = '';
/** @var string */
private $inheritanceLast = '';
/** @var array */
private $inheritancePath = [];
/** @var int */
private $inheritanceDepth = 0;
/** @var array */
private $inheritanceDetails = [];
/**
* Membership constructor.
*
* @param string $singleId
* @param Member|null $member
* @param string $inheritanceLast
*/
public function __construct(
string $singleId = '',
string $inheritanceLast = '',
?Member $member = null
) {
if (is_null($member)) {
return;
}
$circle = $member->getCircle();
$this->setSingleId($singleId);
$this->setCircleId($circle->getSingleId());
$this->setInheritanceFirst($member->getSingleId());
$this->setInheritanceLast($inheritanceLast ?: $member->getCircleId());
$this->setLevel($member->getLevel());
}
/**
* @param string $singleId
*
* @return self
*/
public function setSingleId(string $singleId): self {
$this->singleId = $singleId;
return $this;
}
/**
* @return string
*/
public function getSingleId(): string {
return $this->singleId;
}
/**
* @param string $circleId
*
* @return Membership
*/
public function setCircleId(string $circleId): self {
$this->circleId = $circleId;
return $this;
}
/**
* @return string
*/
public function getCircleId(): string {
return $this->circleId;
}
/**
* @param int $circleConfig
*
* @return Membership
*/
public function setCircleConfig(int $circleConfig): self {
$this->circleConfig = $circleConfig;
return $this;
}
/**
* @return int
*/
public function getCircleConfig(): int {
return $this->circleConfig;
}
/**
* @param int $level
*
* @return Membership
*/
public function setLevel(int $level): self {
$this->level = $level;
return $this;
}
/**
* @return int
*/
public function getLevel(): int {
return $this->level;
}
/**
* @param string $inheritanceFirst
*
* @return Membership
*/
public function setInheritanceFirst(string $inheritanceFirst): self {
$this->inheritanceFirst = $inheritanceFirst;
return $this;
}
/**
* @return string
*/
public function getInheritanceFirst(): string {
return $this->inheritanceFirst;
}
/**
* @param string $inheritanceLast
*
* @return Membership
*/
public function setInheritanceLast(string $inheritanceLast): self {
$this->inheritanceLast = $inheritanceLast;
return $this;
}
/**
* @return string
*/
public function getInheritanceLast(): string {
return $this->inheritanceLast;
}
/**
* @param array $inheritancePath
*
* @return Membership
*/
public function setInheritancePath(array $inheritancePath): self {
$this->inheritancePath = $inheritancePath;
return $this;
}
/**
* @return array
*/
public function getInheritancePath(): array {
return $this->inheritancePath;
}
/**
* @param int $inheritanceDepth
*
* @return Membership
*/
public function setInheritanceDepth(int $inheritanceDepth): self {
$this->inheritanceDepth = $inheritanceDepth;
return $this;
}
/**
* @return int
*/
public function getInheritanceDepth(): int {
return $this->inheritanceDepth;
}
/**
* @param array $inheritanceDetails
*
* @return Membership
*/
public function setInheritanceDetails(array $inheritanceDetails): self {
$this->inheritanceDetails = $inheritanceDetails;
return $this;
}
/**
* @return array
*/
public function getInheritanceDetails(): array {
return $this->inheritanceDetails;
}
/**
* @param array $data
*
* @return IDeserializable
* @throws InvalidItemException
*/
public function import(array $data): IDeserializable {
if ($this->get('singleId', $data) === '') {
throw new InvalidItemException();
}
$this->setSingleId($this->get('singleId', $data));
$this->setCircleId($this->get('circleId', $data));
$this->setCircleConfig($this->getInt('circleConfig', $data));
$this->setLevel($this->getInt('level', $data));
$this->setInheritanceFirst($this->get('inheritanceFirst', $data));
$this->setInheritanceLast($this->get('inheritanceLast', $data));
$this->setInheritancePath($this->getArray('inheritancePath', $data));
$this->setInheritanceDepth($this->getInt('inheritanceDepth', $data));
return $this;
}
/**
* @param array $data
* @param string $prefix
*
* @return IQueryRow
* @throws MembershipNotFoundException
*/
public function importFromDatabase(array $data, string $prefix = ''): IQueryRow {
if ($this->get($prefix . 'single_id', $data) === '') {
throw new MembershipNotFoundException();
}
$this->setSingleId($this->get($prefix . 'single_id', $data));
$this->setCircleId($this->get($prefix . 'circle_id', $data));
$this->setLevel($this->getInt($prefix . 'level', $data));
$this->setCircleConfig($this->getInt($prefix . 'circle_config', $data));
$this->setInheritanceFirst($this->get($prefix . 'inheritance_first', $data));
$this->setInheritanceLast($this->get($prefix . 'inheritance_last', $data));
$this->setInheritancePath($this->getArray($prefix . 'inheritance_path', $data));
$this->setInheritanceDepth($this->getInt($prefix . 'inheritance_depth', $data));
return $this;
}
/**
* @return array
*/
public function jsonSerialize(): array {
$result = [
'singleId' => $this->getSingleId(),
'circleId' => $this->getCircleId(),
'circleConfig' => $this->getCircleConfig(),
'level' => $this->getLevel(),
'inheritanceFirst' => $this->getInheritanceFirst(),
'inheritanceLast' => $this->getInheritanceLast(),
'inheritancePath' => $this->getInheritancePath(),
'inheritanceDepth' => $this->getInheritanceDepth()
];
if (!empty($this->getInheritanceDetails())) {
$result['inheritanceDetails'] = $this->getInheritanceDetails();
}
return $result;
}
}
@@ -0,0 +1,577 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\Db\CircleRequest;
use OCA\Circles\Db\CoreQueryBuilder;
use OCA\Circles\Db\MemberRequest;
use OCA\Circles\Db\MembershipRequest;
use OCA\Circles\Exceptions\CircleNotFoundException;
use OCA\Circles\Exceptions\FederatedItemException;
use OCA\Circles\Exceptions\FederatedUserNotFoundException;
use OCA\Circles\Exceptions\FileCacheNotFoundException;
use OCA\Circles\Exceptions\MemberNotFoundException;
use OCA\Circles\Exceptions\MembershipNotFoundException;
use OCA\Circles\Exceptions\OwnerNotFoundException;
use OCA\Circles\Exceptions\RemoteInstanceException;
use OCA\Circles\Exceptions\RemoteNotFoundException;
use OCA\Circles\Exceptions\RemoteResourceNotFoundException;
use OCA\Circles\Exceptions\RequestBuilderException;
use OCA\Circles\Exceptions\ShareTokenNotFoundException;
use OCA\Circles\Exceptions\UnknownInterfaceException;
use OCA\Circles\Exceptions\UnknownRemoteException;
use OCA\Circles\IEntity;
use OCA\Circles\Model\Federated\RemoteInstance;
use OCA\Circles\Service\ConfigService;
use OCA\Circles\Service\InterfaceService;
use OCA\Circles\Service\MembershipService;
use OCA\Circles\Service\RemoteService;
use OCA\Circles\Tools\Traits\TNCLogger;
use OCP\App\IAppManager;
use OCP\IURLGenerator;
/**
* Class ModelManager
*
* @package OCA\Circles\Model
*/
class ModelManager {
use TNCLogger;
private IURLGenerator $urlGenerator;
private IAppManager $appManager;
private CoreQueryBuilder $coreRequestBuilder;
private CircleRequest $circleRequest;
private MemberRequest $memberRequest;
private MembershipRequest $membershipRequest;
private InterfaceService $interfaceService;
private MembershipService $membershipService;
private RemoteService $remoteService;
private ConfigService $configService;
private bool $fullDetails = false;
private bool $pathLinkGenerated = false;
private string $pathLinkGeneration = '';
/**
* ModelManager constructor.
*
* @param IURLGenerator $urlGenerator
* @param IAppManager $appManager
* @param CoreQueryBuilder $coreRequestBuilder
* @param CircleRequest $circleRequest
* @param MemberRequest $memberRequest
* @param MembershipRequest $membershipRequest
* @param InterfaceService $interfaceService
* @param MembershipService $membershipService
* @param RemoteService $remoteService
* @param ConfigService $configService
*/
public function __construct(
IURLGenerator $urlGenerator,
IAppManager $appManager,
CoreQueryBuilder $coreRequestBuilder,
CircleRequest $circleRequest,
MemberRequest $memberRequest,
MembershipRequest $membershipRequest,
InterfaceService $interfaceService,
MembershipService $membershipService,
RemoteService $remoteService,
ConfigService $configService
) {
$this->urlGenerator = $urlGenerator;
$this->appManager = $appManager;
$this->coreRequestBuilder = $coreRequestBuilder;
$this->circleRequest = $circleRequest;
$this->memberRequest = $memberRequest;
$this->membershipRequest = $membershipRequest;
$this->interfaceService = $interfaceService;
$this->membershipService = $membershipService;
$this->remoteService = $remoteService;
$this->configService = $configService;
$this->setup('app', Application::APP_ID);
}
/**
* @return ConfigService
*/
public function getConfigService(): ConfigService {
return $this->configService;
}
/**
* @param Circle $circle
*/
public function getMembers(Circle $circle): void {
try {
$circle->setMembers($this->memberRequest->getMembers($circle->getSingleId()));
} catch (RequestBuilderException $e) {
// TODO: debug log
}
}
/**
* @param Circle $circle
* @param bool $detailed
*/
public function getInheritedMembers(Circle $circle, bool $detailed = false): void {
try {
$circle->setInheritedMembers(
$this->memberRequest->getInheritedMembers($circle->getSingleId(), $detailed),
$detailed
);
} catch (RequestBuilderException $e) {
// TODO: debug log
}
}
/**
* @param Circle $circle
* @param bool $detailed
*
* @throws RemoteNotFoundException
* @throws RequestBuilderException
* @throws FederatedItemException
* @throws RemoteInstanceException
* @throws RemoteResourceNotFoundException
* @throws UnknownRemoteException
*/
public function getRemoteInheritedMembers(Circle $circle, bool $detailed = false): void {
foreach ($circle->getInheritedMembers() as $inherited) {
if ($inherited->getUserType() === Member::TYPE_CIRCLE
&& !$this->configService->isLocalInstance($inherited->getInstance())) {
try {
$this->circleRequest->getCircle($inherited->getSingleId());
} catch (CircleNotFoundException $e) {
$remote = $this->remoteService->getInheritedFromInstance(
$inherited->getSingleId(),
$inherited->getInstance()
);
$circle->addInheritedMembers($remote);
}
}
}
}
/**
* @param IEntity $member
*/
public function getMemberships(IEntity $member): void {
$memberships = $this->membershipRequest->getMemberships($member->getSingleId());
$member->setMemberships($memberships);
}
/**
* @param IEntity $member
* @param string $circleId
* @param bool $detailed
*
* @return Membership
* @throws MembershipNotFoundException
* @throws RequestBuilderException
*/
public function getLink(IEntity $member, string $circleId, bool $detailed = false): Membership {
return $this->membershipService->getMembership($circleId, $member->getSingleId(), $detailed);
}
/**
* @param ManagedModel $model
* @param array $data
* @param string $base
*/
public function manageImportFromDatabase(ManagedModel $model, array $data, string $base): void {
if ($model instanceof Circle) {
if ($base === '') {
$base = CoreQueryBuilder::CIRCLE;
}
}
if ($model instanceof Member) {
if ($base === '') {
$base = CoreQueryBuilder::MEMBER;
}
}
if ($model instanceof ShareWrapper) {
if ($base === '') {
$base = CoreQueryBuilder::SHARE;
}
}
if ($model instanceof Mount) {
if ($base === '') {
$base = CoreQueryBuilder::MOUNT;
}
}
foreach ($this->coreRequestBuilder->getAvailablePath($base) as $path => $prefix) {
$this->importBasedOnPath($model, $data, $path, $prefix);
}
}
private function importBasedOnPath(ManagedModel $model, array $data, string $path, string $prefix) {
if ($model instanceof Circle) {
$this->importIntoCircle($model, $data, $path, $prefix);
}
if ($model instanceof Member) {
$this->importIntoMember($model, $data, $path, $prefix);
}
if ($model instanceof FederatedUser) {
$this->importIntoFederatedUser($model, $data, $path, $prefix);
}
if ($model instanceof ShareWrapper) {
$this->importIntoShareWrapper($model, $data, $path, $prefix);
}
if ($model instanceof Mount) {
$this->importIntoMount($model, $data, $path, $prefix);
}
}
/**
* @param Circle $circle
* @param array $data
* @param string $path
* @param string $prefix
*/
private function importIntoCircle(Circle $circle, array $data, string $path, string $prefix): void {
switch ($path) {
case CoreQueryBuilder::OWNER:
try {
$owner = new Member();
$owner->importFromDatabase($data, $prefix);
$circle->setOwner($owner);
} catch (MemberNotFoundException $e) {
}
break;
case CoreQueryBuilder::INITIATOR:
try {
$initiator = new Member();
$initiator->importFromDatabase($data, $prefix);
$circle->setInitiator($initiator);
} catch (MemberNotFoundException $e) {
}
break;
case CoreQueryBuilder::DIRECT_INITIATOR:
try {
$directInitiator = new Member();
$directInitiator->importFromDatabase($data, $prefix);
$circle->setDirectInitiator($directInitiator);
} catch (MemberNotFoundException $e) {
}
break;
}
}
/**
* @param Member $member
* @param array $data
* @param string $path
* @param string $prefix
*/
private function importIntoMember(Member $member, array $data, string $path, string $prefix): void {
switch ($path) {
case CoreQueryBuilder::CIRCLE:
try {
$circle = new Circle();
$circle->importFromDatabase($data, $prefix);
$member->setCircle($circle);
} catch (CircleNotFoundException $e) {
}
break;
case CoreQueryBuilder::BASED_ON:
try {
$circle = new Circle();
$circle->importFromDatabase($data, $prefix);
$member->setBasedOn($circle);
} catch (CircleNotFoundException $e) {
}
break;
case CoreQueryBuilder::INHERITED_BY:
try {
$inheritedBy = new FederatedUser();
$inheritedBy->importFromDatabase($data, $prefix);
$member->setInheritedBy($inheritedBy);
} catch (FederatedUserNotFoundException $e) {
}
break;
case CoreQueryBuilder::INVITED_BY:
try {
$invitedByCircle = new Circle();
$invitedByCircle->importFromDatabase($data, $prefix);
$invitedBy = new FederatedUser();
$invitedBy->importFromCircle($invitedByCircle);
$member->setInvitedBy($invitedBy);
} catch (CircleNotFoundException | OwnerNotFoundException $e) {
}
break;
case CoreQueryBuilder::INHERITANCE_FROM:
try {
$inheritanceFrom = new Member();
$inheritanceFrom->importFromDatabase($data, $prefix);
$member->setInheritanceFrom($inheritanceFrom);
} catch (MemberNotFoundException $e) {
}
break;
case CoreQueryBuilder::REMOTE:
try {
$remoteInstance = new RemoteInstance();
$remoteInstance->importFromDatabase($data, $prefix);
$member->setRemoteInstance($remoteInstance);
} catch (RemoteNotFoundException $e) {
}
break;
}
}
/**
* @param FederatedUser $federatedUser
* @param array $data
* @param string $path
* @param string $prefix
*/
private function importIntoFederatedUser(
FederatedUser $federatedUser,
array $data,
string $path,
string $prefix
): void {
switch ($path) {
case CoreQueryBuilder::MEMBERSHIPS:
try {
$membership = new Membership();
$membership->importFromDatabase($data, $prefix);
$federatedUser->setInheritance($membership);
} catch (MembershipNotFoundException $e) {
}
break;
}
}
/**
* @param ShareWrapper $shareWrapper
* @param array $data
* @param string $path
* @param string $prefix
*/
private function importIntoShareWrapper(
ShareWrapper $shareWrapper,
array $data,
string $path,
string $prefix
): void {
switch ($path) {
case CoreQueryBuilder::CIRCLE:
try {
$circle = new Circle();
$circle->importFromDatabase($data, $prefix);
$shareWrapper->setCircle($circle);
} catch (CircleNotFoundException $e) {
}
break;
case CoreQueryBuilder::INITIATOR:
try {
$initiator = new Member();
$initiator->importFromDatabase($data, $prefix);
$shareWrapper->setInitiator($initiator);
} catch (MemberNotFoundException $e) {
}
break;
case CoreQueryBuilder::INHERITED_BY:
try {
$inheritedBy = new Member();
$inheritedBy->importFromDatabase($data, $prefix);
$shareWrapper->setInitiator($inheritedBy);
} catch (MemberNotFoundException $e) {
}
break;
case CoreQueryBuilder::FILE_CACHE:
try {
$fileCache = new FileCacheWrapper();
$fileCache->importFromDatabase($data, $prefix);
$shareWrapper->setFileCache($fileCache);
} catch (FileCacheNotFoundException $e) {
}
break;
case CoreQueryBuilder::TOKEN:
try {
$token = new ShareToken();
$token->importFromDatabase($data, $prefix);
$shareWrapper->setShareToken($token);
} catch (ShareTokenNotFoundException $e) {
}
break;
}
}
/**
* @param Mount $mount
* @param array $data
* @param string $path
* @param string $prefix
*/
private function importIntoMount(
Mount $mount,
array $data,
string $path,
string $prefix
): void {
switch ($path) {
case CoreQueryBuilder::MEMBER:
try {
$member = new Member();
$member->importFromDatabase($data, $prefix);
$mount->setOwner($member);
} catch (MemberNotFoundException $e) {
}
break;
case CoreQueryBuilder::INITIATOR:
try {
$initiator = new Member();
$initiator->importFromDatabase($data, $prefix);
$mount->setInitiator($initiator);
} catch (MemberNotFoundException $e) {
}
break;
}
}
/**
* @return string
*/
public function getLocalInstance(): string {
return $this->interfaceService->getLocalInstance();
}
/**
* @param string $instance
*
* @return bool
*/
public function isLocalInstance(string $instance): bool {
return $this->configService->isLocalInstance($instance);
}
/**
* @param string $instance
*
* @return string
* @throws UnknownInterfaceException
*/
public function fixInstance(string $instance): string {
if (!$this->interfaceService->hasCurrentInterface()) {
return $instance;
}
if (!$this->configService->isLocalInstance($instance)) {
return $instance;
}
return $this->interfaceService->getCloudInstance();
}
/**
* @param string $singleId
*
* @return string
*/
public function generateLinkToCircle(string $singleId): string {
if (!$this->pathLinkGenerated) {
$this->pathLinkGenerated = true;
$path = $this->configService->getAppValue(ConfigService::ROUTE_TO_CIRCLE);
$pos = strpos($path, '.');
if (!$pos) {
return '';
}
if ($this->appManager->isInstalled(substr($path, 0, $pos))) {
$this->pathLinkGeneration = $path;
}
}
if ($this->pathLinkGeneration === '') {
return '';
}
return $this->urlGenerator->linkToRoute($this->pathLinkGeneration, ['singleId' => $singleId]);
}
/**
* @param bool $full
*/
public function setFullDetails(bool $full): void {
$this->fullDetails = $full;
}
/**
* @return bool
*/
public function isFullDetails(): bool {
return $this->fullDetails;
}
}
@@ -0,0 +1,500 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use OCA\Circles\Tools\Db\IQueryRow;
use OCA\Circles\Tools\IDeserializable;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
use OCA\Circles\Exceptions\CircleNotFoundException;
use OCA\Circles\MountManager\CircleMountManager;
use OCP\Federation\ICloudIdManager;
use OCP\Http\Client\IClientService;
/**
* Class Mount
*
* @package OCA\Circles\Model
*/
class Mount extends ManagedModel implements IDeserializable, IQueryRow, JsonSerializable {
use TArrayTools;
/** @var int */
private $id = 0;
/** @var string */
private $mountId = '';
/** @var string */
private $circleId = '';
//
// /** @var string */
// private $singleId = '';
/** @var Member */
private $owner;
/** @var Member */
private $initiator;
/** @var int */
private $parent = -1;
/** @var string */
private $token = '';
/** @var string */
private $password = '';
/** @var string */
private $mountPoint = '';
/** @var string */
private $mountPointHash = '';
/** @var string */
private $storage;
/** @var ICloudIdManager */
private $cloudIdManager;
/** @var IClientService */
private $httpClientService;
/** @var CircleMountManager */
private $mountManager;
/**
* Mount constructor.
*/
public function __construct() {
}
/**
* @return int
*/
public function getId(): int {
return $this->id;
}
public function setId(int $id): self {
$this->id = $id;
return $this;
}
/**
*
* @return string
*/
public function getMountId(): string {
return $this->mountId;
}
/**
* @param string $mountId
*
* @return Mount
*/
public function setMountId(string $mountId): self {
$this->mountId = $mountId;
return $this;
}
/**
*
* @return string
*/
public function getCircleId(): string {
return $this->circleId;
}
/**
* @param string $circleId
*
* @return Mount
*/
public function setCircleId(string $circleId): self {
$this->circleId = $circleId;
return $this;
}
//
// /**
// *
// * @return string
// */
// public function getSingleId(): string {
// return $this->singleId;
// }
//
// /**
// * @param string $singleId
// *
// * @return Mount
// */
// public function setSingleId(string $singleId): self {
// $this->singleId = $singleId;
//
// return $this;
// }
/**
* @param bool $raw
*
* @return string
*/
public function getMountPoint(bool $raw = true): string {
if ($raw) {
return $this->mountPoint;
}
return '/' . $this->getInitiator()->getUserId() . '/files/' . ltrim($this->mountPoint, '/');
}
/**
* @param string $mountPoint
*
* @return Mount
*/
public function setMountPoint(string $mountPoint): self {
$this->mountPoint = $mountPoint;
return $this;
}
/**
* @return string
*/
public function getMountPointHash(): string {
return $this->mountPointHash;
}
/**
* @param string $mountPointHash
*
* @return Mount
*/
public function setMountPointHash(string $mountPointHash): self {
$this->mountPointHash = $mountPointHash;
return $this;
}
/**
* @return int
*/
public function getParent(): int {
return $this->parent;
}
/**
* @param int $parent
*
* @return Mount
*/
public function setParent(int $parent): self {
$this->parent = $parent;
return $this;
}
/**
* @return Member
*/
public function getOwner(): Member {
return $this->owner;
}
/**
* @param Member $owner
*
* @return Mount
*/
public function setOwner(Member $owner): self {
$this->owner = $owner;
return $this;
}
/**
* @return bool
*/
public function hasInitiator(): bool {
return !is_null($this->initiator);
}
/**
* @return Member
*/
public function getInitiator(): Member {
return $this->initiator;
}
/**
* @param Member $initiator
*
* @return Mount
*/
public function setInitiator(Member $initiator): self {
$this->initiator = $initiator;
return $this;
}
/**
* @return string
*/
public function getToken(): string {
return $this->token;
}
/**
* @param string $token
*
* @return Mount
*/
public function setToken(string $token): self {
$this->token = $token;
return $this;
}
/**
* @return string
*/
public function getPassword(): string {
return $this->password;
}
/**
* @param string $password
*
* @return Mount
*/
public function setPassword(string $password): self {
$this->password = $password;
return $this;
}
/**
* @param ICloudIdManager $cloudIdManager
*
* @return Mount
*/
public function setCloudIdManager(ICloudIdManager $cloudIdManager): self {
$this->cloudIdManager = $cloudIdManager;
return $this;
}
/**
* @return ICloudIdManager
*/
public function getCloudIdManager(): ICloudIdManager {
return $this->cloudIdManager;
}
/**
* @param IClientService $httpClientService
*
* @return Mount
*/
public function setHttpClientService(IClientService $httpClientService): self {
$this->httpClientService = $httpClientService;
return $this;
}
/**
* @return IClientService
*/
public function getHttpClientService(): IClientService {
return $this->httpClientService;
}
/**
* @param CircleMountManager $mountManager
*
* @return Mount
*/
public function setMountManager(CircleMountManager $mountManager): self {
$this->mountManager = $mountManager;
return $this;
}
/**
* @return CircleMountManager
*/
public function getMountManager(): CircleMountManager {
return $this->mountManager;
}
//
// /**
// * @param string $storage
// *
// * @return Mount
// */
// public function setStorage(string $storage): self {
// $this->storage = $storage;
//
// return $this;
// }
//
// /**
// * @return string
// */
// public function getStorage(): string {
// return $this->storage;
// }
/**
* @return array
*/
public function toMount(): array {
$member = $this->getOwner();
return [
'owner' => $member->getUserId(),
'remote' => $member->getRemoteInstance()->getRoot(),
'token' => $this->getToken(),
'password' => $this->getPassword(),
'mountpoint' => $this->getMountPoint(false),
// 'manager' => $this->getMountManager(),
'HttpClientService' => $this->getHttpClientService(),
'manager' => $this->getMountManager(),
'cloudId' => $this->getCloudIdManager()->getCloudId(
$member->getUserId(),
$member->getRemoteInstance()->getRoot()
)
];
}
/**
* @param ShareWrapper $wrappedShare
*
* @throws CircleNotFoundException
*/
public function fromShare(ShareWrapper $wrappedShare) {
if (!$wrappedShare->hasCircle()) {
throw new CircleNotFoundException('ShareWrapper has no Circle');
}
$circle = $wrappedShare->getCircle();
$this->setCircleId($circle->getSingleId());
$this->setOwner($wrappedShare->getOwner());
$this->setToken($wrappedShare->getToken());
$this->setParent(-1);
$this->setMountPoint($wrappedShare->getFileTarget());
$this->setMountPointHash(md5($wrappedShare->getFileTarget()));
}
/**
* @param array $data
*
* @return IDeserializable
*/
public function import(array $data): IDeserializable {
return $this;
}
/**
* @param array $data
* @param string $prefix
*
* @return Mount
*/
public function importFromDatabase(array $data, string $prefix = ''): IQueryRow {
$this->setId($this->getInt('id', $data));
$this->setCircleId($this->get('circle_id', $data));
$this->setToken($this->get('token', $data));
$this->setParent($this->getInt('parent', $data));
$this->setMountPoint($this->get('mountpoint', $data));
$this->setMountPointHash($this->get('mountpoint_hash', $data));
// $this->setDefaultMountPoint($this->get('mountpoint', $data));
$this->getManager()->manageImportFromDatabase($this, $data, $prefix);
return $this;
}
/**
* @return array
*/
public function jsonSerialize(): array {
$arr = [
'id' => $this->getId(),
'circleId' => $this->getCircleId(),
'mountId' => $this->getMountId(),
'parent' => $this->getParent(),
'owner' => $this->getOwner(),
'token' => $this->getToken(),
'password' => $this->getPassword(),
'mountPoint' => $this->getMountPoint(),
'mountPointHash' => $this->getMountPointHash(),
];
if ($this->hasInitiator()) {
$arr['initiator'] = $this->getInitiator();
$arr['toMount'] = $this->toMount();
}
return $arr;
}
}
@@ -0,0 +1,151 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
/**
* Class Mountpoint
*
* @package OCA\Circles\Model
*/
class Mountpoint implements JsonSerializable {
use TArrayTools;
/** @var int */
private $shareId = 0;
/** @var string */
private $userId = '';
/** @var string */
private $mountPoint = '';
/**
* GSShareMountpoint constructor.
*
* @param int $shareId
* @param string $userId
* @param string $mountPoint
*/
public function __construct(int $shareId = 0, string $userId = '', string $mountPoint = '') {
$this->shareId = $shareId;
$this->userId = $userId;
$this->mountPoint = $mountPoint;
}
/**
* @return string
*/
public function getUserId(): string {
return $this->userId;
}
/**
* @param string $userId
*
* @return Mountpoint
*/
public function setUserId(string $userId): self {
$this->userId = $userId;
return $this;
}
/**
* @return int
*/
public function getShareId(): int {
return $this->shareId;
}
/**
* @param int $shareId
*
* @return $this
*/
public function setShareId(int $shareId): self {
$this->shareId = $shareId;
return $this;
}
/**
* @return string
*/
public function getMountPoint(): string {
return $this->mountPoint;
}
/**
* @param string $mountPoint
*
* @return Mountpoint
*/
public function setMountPoint(string $mountPoint): self {
$this->mountPoint = $mountPoint;
return $this;
}
/**
* @param array $data
*
* @return Mountpoint
*/
public function importFromDatabase(array $data): self {
$this->setShareId($this->getInt('share_id', $data));
$this->setUserId($this->get('user_id', $data));
$this->setMountPoint($this->get('mountpoint', $data));
return $this;
}
/**
* @return array
*/
public function jsonSerialize(): array {
return [
'userId' => $this->getUserId(),
'shareId' => $this->getShareId(),
'mountPoint' => $this->getMountPoint(),
];
}
}
@@ -0,0 +1,283 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model\Probes;
use OCA\Circles\IQueryProbe;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Federated\RemoteInstance;
use OCA\Circles\Model\Member;
/**
* Class BasicProbe
*
* @package OCA\Circles\Model\Probes
*/
class BasicProbe implements IQueryProbe {
public const DETAILS_NONE = 0;
public const DETAILS_POPULATION = 32;
public const DETAILS_ALL = 127;
/** @var int */
private $itemsOffset = 0;
/** @var int */
private $itemsLimit = -1;
/** @var int */
private $details = 0;
/** @var Circle */
private $filterCircle;
/** @var Member */
private $filterMember;
/** @var RemoteInstance */
private $filterRemoteInstance;
/** @var array */
private $options = [];
/**
* @param int $itemsOffset
*
* @return BasicProbe
*/
public function setItemsOffset(int $itemsOffset): self {
$this->itemsOffset = $itemsOffset;
return $this;
}
/**
* @return int
*/
public function getItemsOffset(): int {
return $this->itemsOffset;
}
/**
* @param int $itemsLimit
*
* @return BasicProbe
*/
public function setItemsLimit(int $itemsLimit): self {
$this->itemsLimit = $itemsLimit;
return $this;
}
/**
* @return int
*/
public function getItemsLimit(): int {
return $this->itemsLimit;
}
/**
* @param int $details
*
* @return $this
*/
public function setDetails(int $details): self {
$this->details = $details;
}
/**
* @return int
*/
public function getDetails(): int {
return $this->details;
}
/**
* @param int $detail
*
* @return $this
*/
public function addDetail(int $detail): self {
$this->details |= $detail;
return $this;
}
/**
* @param int $detail
*
* @return bool
*/
public function showDetail(int $detail): bool {
return (($this->getDetails() & $detail) !== 0);
}
/**
* @param Circle $filterCircle
*
* @return CircleProbe
*/
public function setFilterCircle(Circle $filterCircle): self {
$this->filterCircle = $filterCircle;
return $this;
}
/**
* @return Circle
*/
public function getFilterCircle(): Circle {
return $this->filterCircle;
}
/**
* @return bool
*/
public function hasFilterCircle(): bool {
return !is_null($this->filterCircle);
}
/**
* @param Member $filterMember
*
* @return CircleProbe
*/
public function setFilterMember(Member $filterMember): self {
$this->filterMember = $filterMember;
return $this;
}
/**
* @return Member
*/
public function getFilterMember(): Member {
return $this->filterMember;
}
/**
* @return bool
*/
public function hasFilterMember(): bool {
return !is_null($this->filterMember);
}
/**
* @param RemoteInstance $filterRemoteInstance
*
* @return CircleProbe
*/
public function setFilterRemoteInstance(RemoteInstance $filterRemoteInstance): self {
$this->filterRemoteInstance = $filterRemoteInstance;
return $this;
}
/**
* @return RemoteInstance
*/
public function getFilterRemoteInstance(): RemoteInstance {
return $this->filterRemoteInstance;
}
/**
* @return bool
*/
public function hasFilterRemoteInstance(): bool {
return !is_null($this->filterRemoteInstance);
}
/**
* @param string $key
* @param string $value
*
* @return $this
*/
public function addOption(string $key, string $value): self {
$this->options[$key] = $value;
return $this;
}
/**
* @param string $key
* @param int $value
*
* @return $this
*/
public function addOptionInt(string $key, int $value): self {
$this->options[$key] = $value;
return $this;
}
/**
* @param string $key
* @param bool $value
*
* @return $this
*/
public function addOptionBool(string $key, bool $value): self {
$this->options[$key] = $value;
return $this;
}
/**
* @return array
*/
public function getAsOptions(): array {
return array_merge(
$this->options,
[
'offset' => $this->getItemsOffset(),
'limit' => $this->getItemsLimit(),
'details' => $this->getDetails(),
'detailsAll' => ($this->getDetails() === self::DETAILS_ALL)
]
);
}
/**
* @return array
*/
public function JsonSerialize(): array {
return $this->getAsOptions();
}
}
@@ -0,0 +1,399 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model\Probes;
use OCA\Circles\Model\Circle;
/**
* Class CircleProbe
*
* @package OCA\Circles\Model\Probes
*/
class CircleProbe extends MemberProbe {
private int $include = 0;
private int $filter = Circle::CFG_SINGLE;
private bool $includeNonVisible = false;
private bool $visitSingleCircles = false;
private int $limitConfig = 0;
/**
* CircleProbe constructor.
*/
public function __construct() {
}
/**
* Configure whether personal circles are included in the probe
*
* @param bool $include
*
* @return $this
*/
public function includePersonalCircles(bool $include = true): self {
if ($include) {
$this->include |= Circle::CFG_PERSONAL;
} else {
$this->include &= ~Circle::CFG_PERSONAL;
}
return $this;
}
/**
* Configure whether single circles are included in the probe
*
* @param bool $include
*
* @return $this
*/
public function includeSingleCircles(bool $include = true): self {
if ($include) {
$this->include |= Circle::CFG_SINGLE;
} else {
$this->include &= ~Circle::CFG_SINGLE;
}
return $this;
}
/**
* Configure whether system circles are included in the probe
*
* @param bool $include
*
* @return $this
*/
public function includeSystemCircles(bool $include = true): self {
if ($include) {
$this->include |= Circle::CFG_SYSTEM;
} else {
$this->include &= ~Circle::CFG_SYSTEM;
}
return $this;
}
/**
* Configure whether hidden circles are included in the probe
*
* @param bool $include
*
* @return $this
*/
public function includeHiddenCircles(bool $include = true): self {
if ($include) {
$this->include |= Circle::CFG_HIDDEN;
} else {
$this->include &= ~Circle::CFG_HIDDEN;
}
return $this;
}
/**
* Configure whether backend circles are included in the probe
*
* @param bool $include
*
* @return $this
*/
public function includeBackendCircles(bool $include = true): self {
if ($include) {
$this->include |= Circle::CFG_BACKEND;
} else {
$this->include &= ~Circle::CFG_BACKEND;
}
return $this;
}
/**
* Configure whether non-visible circles are included in the probe
*
* @param bool $include
*
* @return $this
*/
public function includeNonVisibleCircles(bool $include = true): self {
$this->includeNonVisible = $include;
return $this;
}
/**
* Return whether non-visible circles are included in the probe
*
* @return bool
*/
public function nonVisibleCirclesIncluded(): bool {
return $this->includeNonVisible;
}
/**
* Configure whether single circles are visited in the probe
*
* @param bool $visit
*
* @return $this
*/
public function visitSingleCircles(bool $visit = true): self {
$this->visitSingleCircles = $visit;
return $this;
}
/**
* Return whether single circles are visited in the probe
*
* @return bool
*/
public function visitingSingleCircles(): bool {
return $this->visitSingleCircles;
}
/**
* Return the include value
*
* @return int
*/
public function included(): int {
return $this->include;
}
/**
* Return whether a config is included in the probe (bitwise comparison)
*
* @param int $config
*
* @return bool
*/
public function isIncluded(int $config): bool {
return (($this->included() & $config) !== 0);
}
/**
* limit to a specific config
*
* @param int $config
*
* @return $this
*/
public function limitConfig(int $config = 0): self {
$this->limitConfig = $config;
return $this;
}
public function hasLimitConfig(): bool {
return ($this->limitConfig > 0);
}
public function getLimitConfig(): int {
return $this->limitConfig;
}
/**
* Configure whether personal circles are filtered in the probe
*
* @param bool $filter
*
* @return $this
*/
public function filterPersonalCircles(bool $filter = true): self {
if ($filter) {
$this->filter |= Circle::CFG_PERSONAL;
} else {
$this->filter &= ~Circle::CFG_PERSONAL;
}
return $this;
}
/**
* Configure whether single circles are filtered in the probe
*
* @param bool $filter
*
* @return $this
*/
public function filterSingleCircles(bool $filter = true): self {
if ($filter) {
$this->filter |= Circle::CFG_SINGLE;
} else {
$this->filter &= ~Circle::CFG_SINGLE;
}
return $this;
}
/**
* Configure whether system circles are filtered in the probe
*
* @param bool $filter
*
* @return $this
*/
public function filterSystemCircles(bool $filter = true): self {
if ($filter) {
$this->filter |= Circle::CFG_SYSTEM;
} else {
$this->filter &= ~Circle::CFG_SYSTEM;
}
return $this;
}
/**
* Configure whether hidden circles are filtered in the probe
*
* @param bool $filter
*
* @return $this
*/
public function filterHiddenCircles(bool $filter = true): self {
if ($filter) {
$this->filter |= Circle::CFG_HIDDEN;
} else {
$this->filter &= ~Circle::CFG_HIDDEN;
}
return $this;
}
/**
* Configure whether backend circles are filtered in the probe
*
* @param bool $filter
*
* @return $this
*/
public function filterBackendCircles(bool $filter = true): self {
if ($filter) {
$this->filter |= Circle::CFG_BACKEND;
} else {
$this->filter &= ~Circle::CFG_BACKEND;
}
return $this;
}
/**
* Add a config to the probe filter
*
* @param int $config
* @param bool $filter
*
* @return $this
*/
public function filterConfig(int $config, bool $filter = true): self {
if ($filter) {
$this->filter |= $config;
} else {
$this->filter &= ~$config;
}
return $this;
}
/**
* Return the filtered value
*
* @return int
*/
public function filtered(): int {
return $this->filter;
}
/**
* Return whether a config is filtered in the probe (bitwise comparison)
*
* @param int $config
*
* @return bool
*/
public function isFiltered(int $config): bool {
return (($this->filtered() & $config) !== 0);
}
/**
* Return an array with includes as options
*
* @return array
*/
public function getAsOptions(): array {
return array_merge(
[
'included' => $this->included(),
'includeHiddenCircles' => $this->isIncluded(Circle::CFG_HIDDEN),
'includeSingleCircles' => $this->isIncluded(Circle::CFG_SINGLE),
'includeBackendCircles' => $this->isIncluded(Circle::CFG_BACKEND),
'includeSystemCircles' => $this->isIncluded(Circle::CFG_SYSTEM),
'includePersonalCircles' => $this->isIncluded(Circle::CFG_PERSONAL),
'includeNonVisibleCircles' => $this->nonVisibleCirclesIncluded(),
'visitingSingleCircles' => $this->visitingSingleCircles(),
'limitConfig' => $this->getLimitConfig(),
'filtered' => $this->included(),
'filterHiddenCircles' => $this->isIncluded(Circle::CFG_HIDDEN),
'filterSingleCircles' => $this->isIncluded(Circle::CFG_SINGLE),
'filterBackendCircles' => $this->isIncluded(Circle::CFG_BACKEND),
'filterSystemCircles' => $this->isIncluded(Circle::CFG_SYSTEM),
'filterPersonalCircles' => $this->isIncluded(Circle::CFG_PERSONAL),
],
parent::getAsOptions()
);
}
/**
* @return string
*/
public function getChecksum(): string {
return md5(json_encode($this->getAsOptions()));
}
/**
* Return a JSON object with includes as options
*
* @return array
*/
public function JsonSerialize(): array {
return $this->getAsOptions();
}
}
@@ -0,0 +1,111 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2022
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model\Probes;
use OCA\Circles\Db\CoreQueryBuilder;
/**
* Class CircleProbe
*
* @package OCA\Circles\Model\Probes
*/
class DataProbe extends BasicProbe {
public const OWNER = CoreQueryBuilder::OWNER;
public const MEMBER = CoreQueryBuilder::MEMBER;
public const BASED_ON = CoreQueryBuilder::BASED_ON;
public const MEMBERSHIPS = CoreQueryBuilder::MEMBERSHIPS;
public const CONFIG = CoreQueryBuilder::CONFIG;
public const INITIATOR = CoreQueryBuilder::INITIATOR;
public const INHERITED_BY = CoreQueryBuilder::INHERITED_BY;
private array $path = [];
public function __construct() {
}
/**
* @param string $key
* @param array $path
*
* @return $this
*/
public function add(string $key, array $path = []): self {
$this->path[$key] = $path;
return $this;
}
/**
* @param string $key
*
* @return bool
*/
public function has(string $key): bool {
return (array_key_exists($key, $this->path));
}
/**
* @return array
*/
public function getPath(): array {
return $this->path;
}
/**
* Return an array with includes as options
*
* @return array
*/
public function getAsOptions(): array {
return array_merge(
[
'path' => $this->getPath()
],
parent::getAsOptions()
);
}
/**
* Return a JSON object with includes as options
*
* @return array
*/
public function JsonSerialize(): array {
return $this->getAsOptions();
}
}
@@ -0,0 +1,173 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model\Probes;
use OCA\Circles\Model\Member;
/**
* Class MemberProbe
*
* @package OCA\Circles\Model\Probes
*/
class MemberProbe extends BasicProbe {
private int $minimumLevel = Member::LEVEL_NONE;
private bool $emulateVisitor = false;
private bool $requestingMembership = false;
private bool $initiatorDirectMember = false;
/**
* allow the initiator as a requesting member
*
* @param bool $can
*
* @return $this
*/
public function canBeRequestingMembership(bool $can = true): self {
$this->requestingMembership = $can;
return $this;
}
/**
* @return bool
*/
public function isRequestingMembership(): bool {
return $this->requestingMembership;
}
/**
* @param bool $include
*
* @return $this
*/
public function initiatorAsDirectMember(bool $include = true): self {
$this->initiatorDirectMember = $include;
return $this;
}
/**
* @return bool
*/
public function directMemberInitiator(): bool {
return $this->initiatorDirectMember;
}
/**
* force the generation an initiator if visitor
*
* @return $this
*/
public function emulateVisitor(): self {
$this->emulateVisitor = true;
return $this;
}
public function isEmulatingVisitor(): bool {
return $this->emulateVisitor;
}
/**
* @return int
*/
public function getMinimumLevel(): int {
return $this->minimumLevel;
}
/**
* @return $this
*/
public function mustBeMember(bool $must = true): self {
if ($must) {
$this->minimumLevel = Member::LEVEL_MEMBER;
} else {
$this->minimumLevel = Member::LEVEL_NONE;
}
return $this;
}
/**
* @return $this
*/
public function mustBeModerator(): self {
$this->minimumLevel = Member::LEVEL_MODERATOR;
return $this;
}
/**
* @return $this
*/
public function mustBeAdmin(): self {
$this->minimumLevel = Member::LEVEL_ADMIN;
return $this;
}
/**
* @return $this
*/
public function mustBeOwner(): self {
$this->minimumLevel = Member::LEVEL_OWNER;
return $this;
}
/**
* @return array
*/
public function getAsOptions(): array {
return array_merge(
[
'minimumLevel' => $this->getMinimumLevel(),
'emulateVisitor' => $this->isEmulatingVisitor(),
'allowRequestingMembership' => $this->isRequestingMembership(),
'initiatorDirectMember' => $this->directMemberInitiator(),
],
parent::getAsOptions()
);
}
/**
* @return array
*/
public function JsonSerialize(): array {
return $this->getAsOptions();
}
}
@@ -0,0 +1,144 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use OCA\Circles\Tools\IDeserializable;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
/**
* Class Report
*
* @package OCA\Circles\Model
*/
class Report implements IDeserializable, JsonSerializable {
use TArrayTools;
/** @var string */
private $source = '';
/** @var Circle[] */
private $circles = [];
/** @var array */
private $obfuscated = [];
/**
* Report constructor.
*/
public function __construct() {
}
/**
* @param string $source
*
* @return Report
*/
public function setSource(string $source): self {
$this->source = $source;
return $this;
}
/**
* @return string
*/
public function getSource(): string {
return $this->source;
}
/**
* @param Circle[] $circles
*
* @return $this
*/
public function setCircles(array $circles): self {
$this->circles = $circles;
return $this;
}
/**
* @return Circle[]
*/
public function getCircles(): array {
return $this->circles;
}
/**
* @param array $obfuscated
*
* @return $this
*/
public function setObfuscated(array $obfuscated): self {
$this->obfuscated = $obfuscated;
return $this;
}
/**
* @return array
*/
public function getObfuscated(): array {
return $this->obfuscated;
}
/**
* @param array $data
*
* @return IDeserializable
*/
public function import(array $data): IDeserializable {
$this->setSource($this->get('source', $data));
$this->setCircles($this->getArray('circles', $data));
$this->setObfuscated($this->getArray('obfuscated', $data));
return $this;
}
/**
* @return array
*/
public function jsonSerialize(): array {
return [
'source' => $this->getSource(),
'circles' => $this->getCircles(),
'obfuscated' => $this->getObfuscated()
];
}
}
@@ -0,0 +1,139 @@
<?php
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
class SearchResult implements \JsonSerializable {
/** @var string */
private $ident;
/** @var int */
private $type;
/** @var string */
private $instance = '';
/** @var array */
private $data = [];
/**
* SearchResult constructor.
*
* @param string $ident
* @param int $type
* @param string $instance
* @param array $data
*/
public function __construct($ident = '', $type = 0, $instance = '', $data = []) {
$this->setIdent($ident);
$this->setType($type);
$this->setInstance($instance);
$this->setData($data);
}
/**
* @param string $ident
*/
public function setIdent($ident) {
$this->ident = $ident;
}
/**
* @return string
*/
public function getIdent() {
return $this->ident;
}
/**
* @param string $instance
*/
public function setInstance($instance) {
$this->instance = $instance;
}
/**
* @return string
*/
public function getInstance() {
return $this->instance;
}
/**
* @param int $type
*/
public function setType($type) {
$this->type = $type;
}
/**
* @return int
*/
public function getType() {
return $this->type;
}
/**
* @param array $data
*/
public function setData($data) {
$this->data = $data;
}
/**
* @return array
*/
public function getData() {
if (!key_exists('display', $this->data)) {
return ['display' => $this->getIdent()];
}
return $this->data;
}
/**
* Specify data which should be serialized to JSON
*
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize() {
return [
'ident' => $this->getIdent(),
'instance' => $this->getInstance(),
'type' => $this->getType(),
'data' => $this->getData()
];
}
}
@@ -0,0 +1,314 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use OCA\Circles\Tools\Db\IQueryRow;
use OCA\Circles\Tools\Exceptions\InvalidItemException;
use OCA\Circles\Tools\IDeserializable;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
use OCA\Circles\Exceptions\ShareTokenNotFoundException;
use OCP\Share\IShare;
class ShareToken implements IDeserializable, IQueryRow, JsonSerializable {
use TArrayTools;
/** @var int */
private $dbId = 0;
/** @var int */
private $shareId = 0;
/** @var string */
private $circleId = '';
/** @var string */
private $singleId = '';
/** @var string */
private $memberId = '';
/** @var string */
private $token = '';
/** @var string */
private $password = '';
/** @var int */
private $accepted = IShare::STATUS_PENDING;
/** @var string */
private $link = '';
/**
* ShareToken constructor.
*/
public function __construct() {
}
/**
* @param int $dbId
*
* @return ShareToken
*/
public function setDbId(int $dbId): self {
$this->dbId = $dbId;
return $this;
}
/**
* @return int
*/
public function getDbId(): int {
return $this->dbId;
}
/**
* @param int $shareId
*
* @return ShareToken
*/
public function setShareId(int $shareId): self {
$this->shareId = $shareId;
return $this;
}
/**
* @return int
*/
public function getShareId(): int {
return $this->shareId;
}
/**
* @param string $circleId
*
* @return ShareToken
*/
public function setCircleId(string $circleId): self {
$this->circleId = $circleId;
return $this;
}
/**
* @return string
*/
public function getCircleId(): string {
return $this->circleId;
}
/**
* @param string $singleId
*
* @return ShareToken
*/
public function setSingleId(string $singleId): self {
$this->singleId = $singleId;
return $this;
}
/**
* @return string
*/
public function getSingleId(): string {
return $this->singleId;
}
/**
* @param string $memberId
*
* @return ShareToken
*/
public function setMemberId(string $memberId): self {
$this->memberId = $memberId;
return $this;
}
/**
* @return string
*/
public function getMemberId(): string {
return $this->memberId;
}
/**
* @param string $token
*
* @return ShareToken
*/
public function setToken(string $token): self {
$this->token = $token;
return $this;
}
/**
* @return string
*/
public function getToken(): string {
return $this->token;
}
/**
* @param string $password
*
* @return ShareToken
*/
public function setPassword(string $password): self {
$this->password = $password;
return $this;
}
/**
* @return string
*/
public function getPassword(): string {
return $this->password;
}
/**
* @param int $accepted
*
* @return ShareToken
*/
public function setAccepted(int $accepted): self {
$this->accepted = $accepted;
return $this;
}
/**
* @return int
*/
public function getAccepted(): int {
return $this->accepted;
}
/**
* @param string $link
*
* @return ShareToken
*/
public function setLink(string $link): self {
$this->link = $link;
return $this;
}
/**
* @return string
*/
public function getLink(): string {
return $this->link;
}
/**
* @param array $data
*
* @return ShareToken
* @throws InvalidItemException
*/
public function import(array $data): IDeserializable {
if ($this->getInt('shareId', $data) === 0) {
throw new InvalidItemException();
}
$this->setShareId($this->getInt('shareId', $data));
$this->setCircleId($this->get('circleId', $data));
$this->setSingleId($this->get('singleId', $data));
$this->setMemberId($this->get('memberId', $data));
$this->setToken($this->get('token', $data));
$this->setPassword($this->get('password', $data));
$this->setAccepted($this->getInt('accepted', $data, IShare::STATUS_PENDING));
$this->setLink($this->get('link', $data));
return $this;
}
/**
* @param array $data
* @param string $prefix
*
* @return IQueryRow
* @throws ShareTokenNotFoundException
*/
public function importFromDatabase(array $data, string $prefix = ''): IQueryRow {
if ($this->get($prefix . 'token', $data) === '') {
throw new ShareTokenNotFoundException();
}
$this->setShareId($this->getInt($prefix . 'share_id', $data));
$this->setCircleId($this->get($prefix . 'circle_id', $data));
$this->setSingleId($this->get($prefix . 'single_id', $data));
$this->setMemberId($this->get($prefix . 'member_id', $data));
$this->setToken($this->get($prefix . 'token', $data));
$this->setPassword($this->get($prefix . 'password', $data));
$this->setAccepted($this->getInt($prefix . 'accepted', $data, IShare::STATUS_PENDING));
return $this;
}
/**
* @return array
*/
public function jsonSerialize(): array {
return [
'shareId' => $this->getShareId(),
'circleId' => $this->getCircleId(),
'singleId' => $this->getSingleId(),
'memberId' => $this->getMemberId(),
'token' => $this->getToken(),
'password' => $this->getPassword(),
'accepted' => $this->getAccepted(),
'link' => $this->getLink()
];
}
}
@@ -0,0 +1,660 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use DateTime;
use JsonSerializable;
use OC;
use OC\Files\Cache\Cache;
use OC\Share20\Share;
use OC\Share20\ShareAttributes;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\ShareByCircleProvider;
use OCA\Circles\Tools\Db\IQueryRow;
use OCA\Circles\Tools\Exceptions\InvalidItemException;
use OCA\Circles\Tools\IDeserializable;
use OCA\Circles\Tools\Traits\TArrayTools;
use OCA\Circles\Tools\Traits\TDeserialize;
use OCP\Files\IRootFolder;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Share\Exceptions\IllegalIDChangeException;
use OCP\Share\IAttributes;
use OCP\Share\IShare;
/**
* Class ShareWrapper
*
* @package OCA\Circles\Model
*/
class ShareWrapper extends ManagedModel implements IDeserializable, IQueryRow, JsonSerializable {
use TArrayTools;
use TDeserialize;
private string $id = '';
private int $permissions = 0;
private string $itemType = '';
private int $itemSource = 0;
private string $itemTarget = '';
private int $fileSource = 0;
private string $fileTarget = '';
private string $token = '';
private int $status = 0;
private string $providerId = '';
private DateTime $shareTime;
private string $sharedWith = '';
private string $sharedBy = '';
private ?DateTime $expirationDate = null;
private string $shareOwner = '';
private int $shareType = 0;
private ?Circle $circle = null;
private int $childId = 0;
private string $childFileTarget = '';
private int $childPermissions = 0;
private ?FileCacheWrapper $fileCache = null;
private ?Member $initiator = null;
private ?Member $owner = null;
private ?ShareToken $shareToken = null;
private ?IAttributes $attributes = null;
private bool $hideDownload = false;
public function __construct() {
$this->shareTime = new DateTime();
}
public function setId(string $id): self {
$this->id = $id;
return $this;
}
public function getId(): string {
return $this->id;
}
public function setPermissions(int $permissions): self {
$this->permissions = $permissions;
return $this;
}
public function getPermissions(): int {
return $this->permissions;
}
public function setItemType(string $itemType): self {
$this->itemType = $itemType;
return $this;
}
public function getItemType(): string {
return $this->itemType;
}
public function setItemSource(int $itemSource): self {
$this->itemSource = $itemSource;
return $this;
}
public function getItemSource(): int {
return $this->itemSource;
}
public function setItemTarget(string $itemTarget): self {
$this->itemTarget = $itemTarget;
return $this;
}
public function getItemTarget(): string {
return $this->itemTarget;
}
public function setFileSource(int $fileSource): self {
$this->fileSource = $fileSource;
return $this;
}
public function getFileSource(): int {
return $this->fileSource;
}
public function setFileTarget(string $fileTarget): self {
$this->fileTarget = $fileTarget;
return $this;
}
public function getFileTarget(): string {
return $this->fileTarget;
}
public function setToken(string $token): self {
$this->token = $token;
return $this;
}
public function getToken(): string {
return $this->token;
}
public function setStatus(int $status): self {
$this->status = $status;
return $this;
}
public function getStatus(): int {
return $this->status;
}
public function setProviderId(string $providerId): self {
$this->providerId = $providerId;
return $this;
}
public function getProviderId(): string {
return $this->providerId;
}
public function setShareTime(DateTime $shareTime): self {
$this->shareTime = $shareTime;
return $this;
}
public function getShareTime(): DateTime {
return $this->shareTime;
}
public function setSharedWith(string $sharedWith): self {
$this->sharedWith = $sharedWith;
return $this;
}
public function getSharedWith(): string {
return $this->sharedWith;
}
public function setSharedBy(string $sharedBy): self {
$this->sharedBy = $sharedBy;
return $this;
}
public function getExpirationDate(): ?DateTime {
return $this->expirationDate;
}
public function setExpirationDate(?DateTime $date):self {
$this->expirationDate = $date;
return $this;
}
public function getSharedBy(): string {
return $this->sharedBy;
}
public function setShareOwner(string $shareOwner): self {
$this->shareOwner = $shareOwner;
return $this;
}
public function getShareOwner(): string {
return $this->shareOwner;
}
public function setShareType(int $shareType): self {
$this->shareType = $shareType;
return $this;
}
public function getShareType(): int {
return $this->shareType;
}
public function setCircle(Circle $circle): self {
$this->circle = $circle;
return $this;
}
public function getCircle(): Circle {
return $this->circle;
}
public function hasCircle(): bool {
return (!is_null($this->circle));
}
public function setChildId(int $childId): self {
$this->childId = $childId;
return $this;
}
public function getChildId(): int {
return $this->childId;
}
public function setChildFileTarget(string $childFileTarget): self {
$this->childFileTarget = $childFileTarget;
return $this;
}
public function getChildFileTarget(): string {
return $this->childFileTarget;
}
public function setChildPermissions(int $childPermissions): self {
$this->childPermissions = $childPermissions;
return $this;
}
public function getChildPermissions(): int {
return $this->childPermissions;
}
public function setFileCache(FileCacheWrapper $fileCache): self {
$this->fileCache = $fileCache;
return $this;
}
public function getFileCache(): FileCacheWrapper {
return $this->fileCache;
}
public function hasFileCache(): bool {
return (!is_null($this->fileCache));
}
public function setInitiator(Member $initiator): self {
$this->initiator = $initiator;
return $this;
}
public function getInitiator(): Member {
return $this->initiator;
}
public function hasInitiator(): bool {
return (!is_null($this->initiator));
}
public function setOwner(Member $owner): self {
$this->owner = $owner;
return $this;
}
public function getOwner(): Member {
return $this->owner;
}
public function hasOwner(): bool {
return (!is_null($this->owner));
}
public function setShareToken(ShareToken $shareToken): self {
$this->shareToken = $shareToken;
return $this;
}
public function getShareToken(): ShareToken {
return $this->shareToken;
}
public function hasShareToken(): bool {
return !is_null($this->shareToken);
}
public function getAttributes(): ?IAttributes {
return $this->attributes;
}
public function setAttributes(?IAttributes $attributes): self {
$this->attributes = $attributes;
return $this;
}
public function getHideDownload(): bool {
return $this->hideDownload;
}
public function setHideDownload(bool $hideDownload): self {
$this->hideDownload = $hideDownload;
return $this;
}
/**
* @throws IllegalIDChangeException
*/
public function getShare(
IRootFolder $rootFolder,
IUserManager $userManager,
IURLGenerator $urlGenerator,
bool $nullOnMissingFileCache = false
): ?IShare {
$share = new Share($rootFolder, $userManager);
$share->setId($this->getId());
$share->setPermissions($this->getPermissions());
$share->setNodeType($this->getItemType());
$share->setNodeId($this->getFileSource());
$share->setTarget($this->getFileTarget());
$share->setProviderId($this->getProviderId());
$share->setStatus($this->getStatus());
$share->setHideDownload($this->getHideDownload());
$share->setAttributes($this->getAttributes());
if ($this->hasShareToken()) {
$password = $this->getShareToken()->getPassword();
if ($password !== '') {
$share->setPassword($password);
}
}
$share->setShareTime($this->getShareTime())
->setSharedWith($this->getSharedWith())
->setSharedBy($this->getSharedBy())
->setShareOwner($this->getShareOwner())
->setShareType($this->getShareType());
if ($this->getChildId() > 0) {
$share->setTarget($this->getChildFileTarget());
if ($this->getChildPermissions() < $this->getPermissions()) {
$share->setPermissions($this->getChildPermissions());
}
}
$this->setShareDisplay($share, $urlGenerator);
if ($this->hasFileCache()) {
if (!$this->getFileCache()->isAccessible()) {
return null;
}
$share->setNodeCacheEntry(
Cache::cacheEntryFromData($this->getFileCache()->toCache(), OC::$server->getMimeTypeLoader())
);
} elseif ($nullOnMissingFileCache) {
return null;
}
return $share;
}
private function setShareDisplay(IShare $share, IURLGenerator $urlGenerator): void {
if (!$this->hasCircle()) {
return;
}
$circle = $this->getCircle();
if ($circle->isConfig(Circle::CFG_PERSONAL)
&& $this->hasInitiator()
&& $circle->getOwner()->getSingleId() !== $this->getInitiator()->getSingleId()) {
$share->setSharedWithDisplayName(' ');
return;
}
$display = $circle->getDisplayName();
if ($circle->getSource() === Member::TYPE_CIRCLE) {
$l10n = \OCP\Server::get(IFactory::class)->get('circles');
$display = $l10n->t('%s (Circle owned by %s)', [$display, $circle->getOwner()->getDisplayName()]);
} else {
$display .= ' (' . Circle::$DEF_SOURCE[$circle->getSource()] . ')';
}
$share->setSharedWithDisplayName($display);
$icon = $urlGenerator->getAbsoluteURL(
$urlGenerator->imagePath(Application::APP_ID, 'circles.svg')
);
$share->setSharedWithAvatar($icon);
// if (array_key_exists('circle_type', $data)
// && method_exists($share, 'setSharedWithDisplayName')) {
// $name = $data['circle_name'];
// if ($data['circle_alt_name'] !== '') {
// $name = $data['circle_alt_name'];
// }
//
// $share->setSharedWithAvatar(CirclesService::getCircleIcon($data['circle_type']))
// ->setSharedWithDisplayName(
// sprintf(
// ' % s(%s, %s)', $name,
// $this->l10n->t(DeprecatedCircle::TypeLongString($data['circle_type'])),
// $this->miscService->getDisplayName($data['circle_owner'], true)
// )
// );
// }
}
/**
* @param array $data
*
* @throws InvalidItemException
*/
public function import(array $data): IDeserializable {
if ($this->getInt('id', $data) === 0) {
throw new InvalidItemException();
}
$shareTime = new DateTime();
$shareTime->setTimestamp($this->getInt('shareTime', $data));
$this->setId($this->get('id', $data))
->setShareType($this->getInt('shareType', $data))
->setPermissions($this->getInt('permissions', $data))
->setHideDownload($this->getBool('hideDownload', $data))
->setItemType($this->get('itemType', $data))
->setItemSource($this->getInt('itemSource', $data))
->setItemTarget($this->get('itemTarget', $data))
->setFileSource($this->getInt('fileSource', $data))
->setFileTarget($this->get('fileTarget', $data))
->setSharedWith($this->get('sharedWith', $data))
->setSharedBy($this->get('sharedBy', $data))
->setShareOwner($this->get('shareOwner', $data))
->setToken($this->get('token', $data))
->setShareTime($shareTime);
try {
$this->setExpirationDate(new DateTime($this->get('expiration', $data)));
} catch (\Exception $e) {
}
$this->setChildId($this->getInt('childId', $data))
->setChildFileTarget($this->get('childFileTarget', $data))
->setChildPermissions($this->getInt('childPermissions', $data))
->setProviderId(ShareByCircleProvider::IDENTIFIER)
->setStatus(Ishare::STATUS_ACCEPTED);
try {
$circle = new Circle();
$this->setCircle($circle->import($this->getArray('circle', $data)));
} catch (InvalidItemException $e) {
}
try {
$fileCache = new FileCacheWrapper();
$this->setFileCache($fileCache->import($this->getArray('fileCache', $data)));
} catch (InvalidItemException $e) {
}
try {
$owner = new Member();
$this->setOwner($owner->import($this->getArray('owner', $data)));
} catch (InvalidItemException $e) {
}
try {
$member = new Member();
$this->setInitiator($member->import($this->getArray('viewer', $data)));
} catch (InvalidItemException $e) {
}
try {
$shareToken = new ShareToken();
$this->setShareToken($shareToken->import($this->getArray('shareToken', $data)));
} catch (InvalidItemException $e) {
}
return $this;
}
public function importFromDatabase(array $data, string $prefix = ''): IQueryRow {
$shareTime = new DateTime();
$shareTime->setTimestamp($this->getInt($prefix . 'stime', $data));
$this->setId($this->get($prefix . 'id', $data))
->setShareType($this->getInt($prefix . 'share_type', $data))
->setPermissions($this->getInt($prefix . 'permissions', $data))
->setItemType($this->get($prefix . 'item_type', $data))
->setItemSource($this->getInt($prefix . 'item_source', $data))
->setItemTarget($this->get($prefix . 'item_target', $data))
->setFileSource($this->getInt($prefix . 'file_source', $data))
->setFileTarget($this->get($prefix . 'file_target', $data))
->setSharedWith($this->get($prefix . 'share_with', $data))
->setSharedBy($this->get($prefix . 'uid_initiator', $data))
->setShareOwner($this->get($prefix . 'uid_owner', $data))
->setToken($this->get($prefix . 'token', $data))
->setShareTime($shareTime);
$this->importAttributesFromDatabase($this->get('attributes', $data));
// if (($password = $this->get('personal_password', $data, '')) !== '') {
// $share->setPassword($this->get('personal_password', $data, ''));
// } else if (($password = $this->get('password', $data, '')) !== '') {
// $share->setPassword($this->get('password', $data, ''));
// }
$this->setChildId($this->getInt($prefix . 'child_id', $data))
->setChildFileTarget($this->get($prefix . 'child_file_target', $data))
->setChildPermissions($this->getInt($prefix . 'child_permissions', $data))
->setProviderId(ShareByCircleProvider::IDENTIFIER)
->setStatus(Ishare::STATUS_ACCEPTED);
$this->getManager()->manageImportFromDatabase($this, $data, $prefix);
return $this;
}
/**
* Load from database format (JSON string) to IAttributes
* based on \OC\Share20\DefaultShareProvider
*/
private function importAttributesFromDatabase(string $data): void {
if ($data === '') {
return;
}
$attributes = new ShareAttributes();
$compressedAttributes = json_decode($data, true);
if (!is_array($compressedAttributes)) {
return;
}
foreach ($compressedAttributes as $compressedAttribute) {
$attributes->setAttribute(...$compressedAttribute);
}
$this->setHideDownload(!($attributes->getAttribute('permissions', 'download') ?? true));
$this->setAttributes($attributes);
}
public function jsonSerialize(): array {
$arr = [
'id' => $this->getId(),
'shareType' => $this->getShareType(),
'providerId' => $this->getProviderId(),
'permissions' => $this->getPermissions(),
'attributes' => $this->getAttributes(),
'hideDownload' => $this->getHideDownload(),
'itemType' => $this->getItemType(),
'itemSource' => $this->getItemSource(),
'itemTarget' => $this->getItemTarget(),
'fileSource' => $this->getFileSource(),
'fileTarget' => $this->getFileTarget(),
'status' => $this->getStatus(),
'shareTime' => $this->getShareTime()->getTimestamp(),
'sharedWith' => $this->getSharedWith(),
'sharedBy' => $this->getSharedBy(),
'shareOwner' => $this->getShareOwner(),
'token' => $this->getToken(),
'childId' => $this->getChildId(),
'childFileTarget' => $this->getChildFileTarget(),
'childPermissions' => $this->getChildPermissions()
];
if ($this->hasOwner()) {
$arr['owner'] = $this->getOwner();
}
if ($this->hasCircle()) {
$arr['circle'] = $this->getCircle();
}
if ($this->hasInitiator()) {
$arr['viewer'] = $this->getInitiator();
}
if ($this->hasFileCache()) {
$arr['fileCache'] = $this->getFileCache();
}
if ($this->hasShareToken()) {
$arr['shareToken'] = $this->getShareToken();
}
return $arr;
}
}
@@ -0,0 +1,208 @@
<?php
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use OCA\Circles\Tools\Traits\TArrayTools;
use JsonSerializable;
use OCP\Share\IShare;
/**
* Class SharesToken
* @deprecated
* @package OCA\Circles\Model
*/
class SharesToken implements JsonSerializable {
use TArrayTools;
/** @var string */
private $circleId = '';
/** @var string */
private $memberId = '';
/** @var int */
private $accepted = IShare::STATUS_PENDING;
/** @var string */
private $userId = '';
/** @var int */
private $shareId = 0;
/** @var string */
private $token = '';
/**
* SharesToken constructor.
*/
public function __construct() {
}
/**
* @return string
*/
public function getCircleId(): string {
return $this->circleId;
}
/**
* @param string $circleId
*
* @return SharesToken
*/
public function setCircleId(string $circleId): self {
$this->circleId = $circleId;
return $this;
}
/**
* @return string
*/
public function getMemberId(): string {
return $this->memberId;
}
/**
* @param string $memberId
*
* @return SharesToken
*/
public function setMemberId(string $memberId): self {
$this->memberId = $memberId;
return $this;
}
/**
* @return string
*/
public function getUserId(): string {
return $this->userId;
}
/**
* @param string $userId
*
* @return SharesToken
*/
public function setUserId(string $userId): self {
$this->userId = $userId;
return $this;
}
/**
* @return int
*/
public function getShareId(): int {
return $this->shareId;
}
/**
* @param int $shareId
*
* @return SharesToken
*/
public function setShareId(int $shareId): self {
$this->shareId = $shareId;
return $this;
}
/**
* @return string
*/
public function getToken(): string {
return $this->token;
}
/**
* @param string $token
*
* @return SharesToken
*/
public function setToken(string $token): self {
$this->token = $token;
return $this;
}
/**
* @return int
*/
public function getAccepted(): int {
return $this->accepted;
}
/**
* @param int $accepted
*
* @return SharesToken
*/
public function setAccepted(int $accepted): self {
$this->accepted = $accepted;
return $this;
}
/**
* @param array $data
*/
public function import(array $data) {
$this->setCircleId($this->get('circle_id', $data, ''));
$this->setMemberId($this->get('member_id', $data, ''));
$this->setAccepted($this->getInt('accepted', $data, IShare::STATUS_PENDING));
$this->setUserId($this->get('user_id', $data, ''));
$this->setShareId($this->get('share_id', $data, ''));
$this->setToken($this->get('token', $data, ''));
}
/**
* @return array
*/
public function jsonSerialize(): array {
return [
'circleId' => $this->getCircleId(),
'memberId' => $this->getMemberId(),
'userId' => $this->getUserId(),
'shareId' => $this->getShareId(),
'token' => $this->getToken(),
'accepted' => $this->getAccepted()
];
}
}
@@ -0,0 +1,339 @@
<?php
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Model;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\Exceptions\SharingFrameSourceCannotBeAppCirclesException;
use OCA\Circles\Service\MiscService;
/**
* @deprecated
* Class SharingFrame
*
* @package OCA\Circles\Model
*/
class SharingFrame implements \JsonSerializable {
/** @var string */
private $source;
/** @var string */
private $type;
/** @var DeprecatedCircle */
private $circle;
/** @var string */
private $author;
/** @var string */
private $cloudId;
/** @var array */
private $payload;
/** @var array */
private $headers;
/** @var int */
private $creation;
/** @var string */
private $uniqueId;
public function __construct($source, $type) {
$this->source = (string)$source;
$this->type = (string)$type;
}
/**
* @return string
*/
public function getSource() {
return $this->source;
}
/**
* @return string
*/
public function getType() {
return $this->type;
}
/**
* @param DeprecatedCircle $circle
*/
public function setCircle($circle) {
$this->circle = $circle;
}
/**
* @return DeprecatedCircle
*/
public function getCircle() {
return $this->circle;
}
/**
* @param string $author
*/
public function setAuthor($author) {
$this->author = (string)$author;
}
/**
* @return string
*/
public function getAuthor() {
return $this->author;
}
/**
* @param string $cloudId
*/
public function setCloudId($cloudId) {
$this->cloudId = $cloudId;
}
/**
* @return string
*/
public function getCloudId() {
return $this->cloudId;
}
/**
* @param string $uniqueId
*
* @return SharingFrame
*/
public function setUniqueId($uniqueId) {
$this->uniqueId = (string)$uniqueId;
return $this;
}
/**
* @return string
*/
public function getUniqueId() {
return $this->uniqueId;
}
/**
* @return SharingFrame
*/
public function generateUniqueId() {
$uniqueId = bin2hex(openssl_random_pseudo_bytes(16));
$this->setUniqueId($uniqueId);
return $this;
}
/**
* @param array $payload
*/
public function setPayload($payload) {
$this->payload = $payload;
}
/**
* @param bool $asJson
*
* @return array|string
*/
public function getPayload($asJson = false) {
if ($asJson) {
return json_encode($this->payload);
}
return $this->payload;
}
/**
* @param array $headers
*/
public function setHeaders($headers) {
$this->headers = $headers;
}
/**
* @param bool $asJson
*
* @return array|string
*/
public function getHeaders($asJson = false) {
if ($asJson) {
return json_encode($this->headers);
}
return $this->headers;
}
/**
* @param string $k
*
* @return string
*/
public function getHeader($k) {
if ($this->headers === null) {
return null;
}
$k = (string)$k;
if (!key_exists($k, $this->headers)) {
return null;
}
return $this->headers[$k];
}
/**
* @param string $k
* @param string $v
*/
public function setHeader($k, $v) {
$this->headers[(string)$k] = $v;
}
/**
* @param int $creation
*/
public function setCreation($creation) {
if ($creation === null) {
return;
}
$this->creation = $creation;
}
/**
* @return int
*/
public function getCreation() {
return $this->creation;
}
/**
* @return bool
*/
public function isLocal() {
return ($this->getCloudId() === null);
}
/**
* @return bool
*/
public function is0Circle() {
return ($this->getCloudId() === null);
}
/**
* @throws SharingFrameSourceCannotBeAppCirclesException
*/
public function cannotBeFromCircles() {
if (strtolower($this->getSource()) === Application::APP_ID) {
throw new SharingFrameSourceCannotBeAppCirclesException();
}
}
public function jsonSerialize() {
return [
'unique_id' => $this->getUniqueId(),
'circle' => $this->getCircle()
->getArray(false, true),
'source' => $this->getSource(),
'type' => $this->getType(),
'author' => $this->getAuthor(),
'cloud_id' => $this->getCloudId(),
'headers' => $this->getHeaders(),
'payload' => $this->getPayload(),
'creation' => $this->getCreation(),
];
}
public static function fromJSON($json) {
$arr = json_decode($json, true);
return self::fromArray($arr);
}
public static function fromArray($arr) {
if (!is_array($arr) || !key_exists('source', $arr)) {
return null;
}
$share = new SharingFrame($arr['source'], $arr['type']);
$share->setCircle(self::getCircleFromArray($arr));
$share->setHeaders(self::getHeadersFromArray($arr));
if (key_exists('cloud_id', $arr)) {
$share->setCloudID($arr['cloud_id']);
}
$share->setUniqueId($arr['unique_id']);
$share->setAuthor($arr['author']);
$share->setPayload($arr['payload']);
$share->setCreation($arr['creation']);
return $share;
}
/**
* @param array $arr
*
* @return array
*/
private static function getHeadersFromArray($arr) {
$headers = [];
if (key_exists('headers', $arr)) {
$headers = $arr['headers'];
}
return $headers;
}
/**
* @param array $arr
*
* @return DeprecatedCircle
*/
private static function getCircleFromArray($arr) {
return DeprecatedCircle::fromArray(MiscService::get($arr, 'circle', null));
}
}