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
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,25 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Share20\Exception;
class BackendError extends \Exception {
}
@@ -0,0 +1,25 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Share20\Exception;
class InvalidShare extends \Exception {
}
@@ -0,0 +1,25 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Share20\Exception;
class ProviderException extends \Exception {
}
@@ -0,0 +1,32 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Share20;
class Hooks {
public static function post_deleteUser($arguments) {
\OC::$server->getShareManager()->userDeleted($arguments['uid']);
}
public static function post_deleteGroup($arguments) {
\OC::$server->getShareManager()->groupDeleted($arguments['gid']);
}
}
@@ -0,0 +1,164 @@
<?php
/**
* @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Pauli Järvinen <pauli.jarvinen@gmail.com>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @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 OC\Share20;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Share;
use OCP\Share\Events\BeforeShareCreatedEvent;
use OCP\Share\Events\BeforeShareDeletedEvent;
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\Events\ShareDeletedEvent;
use OCP\Share\Events\ShareDeletedFromSelfEvent;
use OCP\Share\IShare;
class LegacyHooks {
/** @var IEventDispatcher */
private $eventDispatcher;
public function __construct(IEventDispatcher $eventDispatcher) {
$this->eventDispatcher = $eventDispatcher;
$this->eventDispatcher->addListener(BeforeShareDeletedEvent::class, function (BeforeShareDeletedEvent $event) {
$this->preUnshare($event);
});
$this->eventDispatcher->addListener(ShareDeletedEvent::class, function (ShareDeletedEvent $event) {
$this->postUnshare($event);
});
$this->eventDispatcher->addListener(ShareDeletedFromSelfEvent::class, function (ShareDeletedFromSelfEvent $event) {
$this->postUnshareFromSelf($event);
});
$this->eventDispatcher->addListener(BeforeShareCreatedEvent::class, function (BeforeShareCreatedEvent $event) {
$this->preShare($event);
});
$this->eventDispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) {
$this->postShare($event);
});
}
public function preUnshare(BeforeShareDeletedEvent $e) {
$share = $e->getShare();
$formatted = $this->formatHookParams($share);
\OC_Hook::emit(Share::class, 'pre_unshare', $formatted);
}
public function postUnshare(ShareDeletedEvent $e) {
$share = $e->getShare();
$formatted = $this->formatHookParams($share);
$formatted['deletedShares'] = [$formatted];
\OC_Hook::emit(Share::class, 'post_unshare', $formatted);
}
public function postUnshareFromSelf(ShareDeletedFromSelfEvent $e) {
$share = $e->getShare();
$formatted = $this->formatHookParams($share);
$formatted['itemTarget'] = $formatted['fileTarget'];
$formatted['unsharedItems'] = [$formatted];
\OC_Hook::emit(Share::class, 'post_unshareFromSelf', $formatted);
}
private function formatHookParams(IShare $share) {
// Prepare hook
$shareType = $share->getShareType();
$sharedWith = '';
if ($shareType === IShare::TYPE_USER ||
$shareType === IShare::TYPE_GROUP ||
$shareType === IShare::TYPE_REMOTE) {
$sharedWith = $share->getSharedWith();
}
$hookParams = [
'id' => $share->getId(),
'itemType' => $share->getNodeType(),
'itemSource' => $share->getNodeId(),
'shareType' => $shareType,
'shareWith' => $sharedWith,
'itemparent' => method_exists($share, 'getParent') ? $share->getParent() : '',
'uidOwner' => $share->getSharedBy(),
'fileSource' => $share->getNodeId(),
'fileTarget' => $share->getTarget()
];
return $hookParams;
}
public function preShare(BeforeShareCreatedEvent $e) {
$share = $e->getShare();
// Pre share hook
$run = true;
$error = '';
$preHookData = [
'itemType' => $share->getNode() instanceof File ? 'file' : 'folder',
'itemSource' => $share->getNode()->getId(),
'shareType' => $share->getShareType(),
'uidOwner' => $share->getSharedBy(),
'permissions' => $share->getPermissions(),
'fileSource' => $share->getNode()->getId(),
'expiration' => $share->getExpirationDate(),
'token' => $share->getToken(),
'itemTarget' => $share->getTarget(),
'shareWith' => $share->getSharedWith(),
'run' => &$run,
'error' => &$error,
];
\OC_Hook::emit(Share::class, 'pre_shared', $preHookData);
if ($run === false) {
$e->setError($error);
$e->stopPropagation();
}
return $e;
}
public function postShare(ShareCreatedEvent $e) {
$share = $e->getShare();
$postHookData = [
'itemType' => $share->getNode() instanceof File ? 'file' : 'folder',
'itemSource' => $share->getNode()->getId(),
'shareType' => $share->getShareType(),
'uidOwner' => $share->getSharedBy(),
'permissions' => $share->getPermissions(),
'fileSource' => $share->getNode()->getId(),
'expiration' => $share->getExpirationDate(),
'token' => $share->getToken(),
'id' => $share->getId(),
'shareWith' => $share->getSharedWith(),
'itemTarget' => $share->getTarget(),
'fileTarget' => $share->getTarget(),
'path' => $share->getNode()->getPath(),
];
\OC_Hook::emit(Share::class, 'post_shared', $postHookData);
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,393 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Bjoern Schiessle <bjoern@schiessle.org>
* @author Björn Schießle <bjoern@schiessle.org>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Daniel Calviño Sánchez <danxuliu@gmail.com>
* @author Joas Schilling <coding@schilljs.com>
* @author John Molakvoæ <skjnldsv@protonmail.com>
* @author Julius Härtl <jus@bitgrid.net>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Maxence Lange <maxence@nextcloud.com>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Samuel <faust64@gmail.com>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Share20;
use OC\Share20\Exception\ProviderException;
use OCA\FederatedFileSharing\AddressHandler;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\FederatedFileSharing\Notifications;
use OCA\FederatedFileSharing\TokenHandler;
use OCA\ShareByMail\Settings\SettingsManager;
use OCA\ShareByMail\ShareByMailProvider;
use OCA\Talk\Share\RoomShareProvider;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Defaults;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IServerContainer;
use OCP\Share\IManager;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
use OCP\Share\IShareProvider;
use Psr\Log\LoggerInterface;
/**
* Class ProviderFactory
*
* @package OC\Share20
*/
class ProviderFactory implements IProviderFactory {
/** @var IServerContainer */
private $serverContainer;
/** @var DefaultShareProvider */
private $defaultProvider = null;
/** @var FederatedShareProvider */
private $federatedProvider = null;
/** @var ShareByMailProvider */
private $shareByMailProvider;
/** @var \OCA\Circles\ShareByCircleProvider */
private $shareByCircleProvider = null;
/** @var bool */
private $circlesAreNotAvailable = false;
/** @var \OCA\Talk\Share\RoomShareProvider */
private $roomShareProvider = null;
private $registeredShareProviders = [];
private $shareProviders = [];
/**
* IProviderFactory constructor.
*
* @param IServerContainer $serverContainer
*/
public function __construct(IServerContainer $serverContainer) {
$this->serverContainer = $serverContainer;
}
public function registerProvider(string $shareProviderClass): void {
$this->registeredShareProviders[] = $shareProviderClass;
}
/**
* Create the default share provider.
*
* @return DefaultShareProvider
*/
protected function defaultShareProvider() {
if ($this->defaultProvider === null) {
$this->defaultProvider = new DefaultShareProvider(
$this->serverContainer->getDatabaseConnection(),
$this->serverContainer->getUserManager(),
$this->serverContainer->getGroupManager(),
$this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getMailer(),
$this->serverContainer->query(Defaults::class),
$this->serverContainer->getL10NFactory(),
$this->serverContainer->getURLGenerator(),
$this->serverContainer->query(ITimeFactory::class),
);
}
return $this->defaultProvider;
}
/**
* Create the federated share provider
*
* @return FederatedShareProvider
*/
protected function federatedShareProvider() {
if ($this->federatedProvider === null) {
/*
* Check if the app is enabled
*/
$appManager = $this->serverContainer->getAppManager();
if (!$appManager->isEnabledForUser('federatedfilesharing')) {
return null;
}
/*
* TODO: add factory to federated sharing app
*/
$l = $this->serverContainer->getL10N('federatedfilesharing');
$addressHandler = new AddressHandler(
$this->serverContainer->getURLGenerator(),
$l,
$this->serverContainer->getCloudIdManager()
);
$notifications = new Notifications(
$addressHandler,
$this->serverContainer->getHTTPClientService(),
$this->serverContainer->query(\OCP\OCS\IDiscoveryService::class),
$this->serverContainer->getJobList(),
\OC::$server->getCloudFederationProviderManager(),
\OC::$server->getCloudFederationFactory(),
$this->serverContainer->query(IEventDispatcher::class),
$this->serverContainer->get(LoggerInterface::class),
);
$tokenHandler = new TokenHandler(
$this->serverContainer->getSecureRandom()
);
$this->federatedProvider = new FederatedShareProvider(
$this->serverContainer->getDatabaseConnection(),
$addressHandler,
$notifications,
$tokenHandler,
$l,
$this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getConfig(),
$this->serverContainer->getUserManager(),
$this->serverContainer->getCloudIdManager(),
$this->serverContainer->getGlobalScaleConfig(),
$this->serverContainer->getCloudFederationProviderManager(),
$this->serverContainer->get(LoggerInterface::class),
);
}
return $this->federatedProvider;
}
/**
* Create the federated share provider
*
* @return ShareByMailProvider
*/
protected function getShareByMailProvider() {
if ($this->shareByMailProvider === null) {
/*
* Check if the app is enabled
*/
$appManager = $this->serverContainer->getAppManager();
if (!$appManager->isEnabledForUser('sharebymail')) {
return null;
}
$settingsManager = new SettingsManager($this->serverContainer->getConfig());
$this->shareByMailProvider = new ShareByMailProvider(
$this->serverContainer->getConfig(),
$this->serverContainer->getDatabaseConnection(),
$this->serverContainer->getSecureRandom(),
$this->serverContainer->getUserManager(),
$this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getL10N('sharebymail'),
$this->serverContainer->get(LoggerInterface::class),
$this->serverContainer->getMailer(),
$this->serverContainer->getURLGenerator(),
$this->serverContainer->getActivityManager(),
$settingsManager,
$this->serverContainer->query(Defaults::class),
$this->serverContainer->getHasher(),
$this->serverContainer->get(IEventDispatcher::class),
$this->serverContainer->get(IManager::class)
);
}
return $this->shareByMailProvider;
}
/**
* Create the circle share provider
*
* @return FederatedShareProvider
*
* @suppress PhanUndeclaredClassMethod
*/
protected function getShareByCircleProvider() {
if ($this->circlesAreNotAvailable) {
return null;
}
if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') ||
!class_exists('\OCA\Circles\ShareByCircleProvider')
) {
$this->circlesAreNotAvailable = true;
return null;
}
if ($this->shareByCircleProvider === null) {
$this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider(
$this->serverContainer->getDatabaseConnection(),
$this->serverContainer->getSecureRandom(),
$this->serverContainer->getUserManager(),
$this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getL10N('circles'),
$this->serverContainer->getLogger(),
$this->serverContainer->getURLGenerator()
);
}
return $this->shareByCircleProvider;
}
/**
* Create the room share provider
*
* @return RoomShareProvider
*/
protected function getRoomShareProvider() {
if ($this->roomShareProvider === null) {
/*
* Check if the app is enabled
*/
$appManager = $this->serverContainer->getAppManager();
if (!$appManager->isEnabledForUser('spreed')) {
return null;
}
try {
/**
* @psalm-suppress UndefinedClass
*/
$this->roomShareProvider = $this->serverContainer->get(RoomShareProvider::class);
} catch (\Throwable $e) {
$this->serverContainer->get(LoggerInterface::class)->error(
$e->getMessage(),
['exception' => $e]
);
return null;
}
}
return $this->roomShareProvider;
}
/**
* @inheritdoc
*/
public function getProvider($id) {
$provider = null;
if (isset($this->shareProviders[$id])) {
return $this->shareProviders[$id];
}
if ($id === 'ocinternal') {
$provider = $this->defaultShareProvider();
} elseif ($id === 'ocFederatedSharing') {
$provider = $this->federatedShareProvider();
} elseif ($id === 'ocMailShare') {
$provider = $this->getShareByMailProvider();
} elseif ($id === 'ocCircleShare') {
$provider = $this->getShareByCircleProvider();
} elseif ($id === 'ocRoomShare') {
$provider = $this->getRoomShareProvider();
}
foreach ($this->registeredShareProviders as $shareProvider) {
try {
/** @var IShareProvider $instance */
$instance = $this->serverContainer->get($shareProvider);
$this->shareProviders[$instance->identifier()] = $instance;
} catch (\Throwable $e) {
$this->serverContainer->get(LoggerInterface::class)->error(
$e->getMessage(),
['exception' => $e]
);
}
}
if (isset($this->shareProviders[$id])) {
$provider = $this->shareProviders[$id];
}
if ($provider === null) {
throw new ProviderException('No provider with id .' . $id . ' found.');
}
return $provider;
}
/**
* @inheritdoc
*/
public function getProviderForType($shareType) {
$provider = null;
if ($shareType === IShare::TYPE_USER ||
$shareType === IShare::TYPE_GROUP ||
$shareType === IShare::TYPE_LINK
) {
$provider = $this->defaultShareProvider();
} elseif ($shareType === IShare::TYPE_REMOTE || $shareType === IShare::TYPE_REMOTE_GROUP) {
$provider = $this->federatedShareProvider();
} elseif ($shareType === IShare::TYPE_EMAIL) {
$provider = $this->getShareByMailProvider();
} elseif ($shareType === IShare::TYPE_CIRCLE) {
$provider = $this->getShareByCircleProvider();
} elseif ($shareType === IShare::TYPE_ROOM) {
$provider = $this->getRoomShareProvider();
} elseif ($shareType === IShare::TYPE_DECK) {
$provider = $this->getProvider('deck');
} elseif ($shareType === IShare::TYPE_SCIENCEMESH) {
$provider = $this->getProvider('sciencemesh');
}
if ($provider === null) {
throw new ProviderException('No share provider for share type ' . $shareType);
}
return $provider;
}
public function getAllProviders() {
$shares = [$this->defaultShareProvider(), $this->federatedShareProvider()];
$shareByMail = $this->getShareByMailProvider();
if ($shareByMail !== null) {
$shares[] = $shareByMail;
}
$shareByCircle = $this->getShareByCircleProvider();
if ($shareByCircle !== null) {
$shares[] = $shareByCircle;
}
$roomShare = $this->getRoomShareProvider();
if ($roomShare !== null) {
$shares[] = $roomShare;
}
foreach ($this->registeredShareProviders as $shareProvider) {
try {
/** @var IShareProvider $instance */
$instance = $this->serverContainer->get($shareProvider);
} catch (\Throwable $e) {
$this->serverContainer->get(LoggerInterface::class)->error(
$e->getMessage(),
['exception' => $e]
);
continue;
}
if (!isset($this->shareProviders[$instance->identifier()])) {
$this->shareProviders[$instance->identifier()] = $instance;
}
$shares[] = $this->shareProviders[$instance->identifier()];
}
return $shares;
}
}
@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Louis Chemineau <louis@chmn.me>
*
* @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 OC\Share20;
use Exception;
use OC\AppFramework\Bootstrap\Coordinator;
use OCA\Files_Sharing\DefaultPublicShareTemplateProvider;
use OCP\Server;
use OCP\Share\IPublicShareTemplateFactory;
use OCP\Share\IPublicShareTemplateProvider;
use OCP\Share\IShare;
class PublicShareTemplateFactory implements IPublicShareTemplateFactory {
public function __construct(
private Coordinator $coordinator,
private DefaultPublicShareTemplateProvider $defaultProvider,
) {
}
public function getProvider(IShare $share): IPublicShareTemplateProvider {
$context = $this->coordinator->getRegistrationContext();
if ($context === null) {
throw new Exception("Can't retrieve public share template providers as context is not defined");
}
$providers = array_map(
fn ($registration) => Server::get($registration->getService()),
$context->getPublicShareTemplateProviders()
);
$filteredProviders = array_filter(
$providers,
fn (IPublicShareTemplateProvider $provider) => $provider->shouldRespond($share)
);
if (count($filteredProviders) === 0) {
return $this->defaultProvider;
} else {
return array_shift($filteredProviders);
}
}
}
+623
View File
@@ -0,0 +1,623 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Bjoern Schiessle <bjoern@schiessle.org>
* @author Björn Schießle <bjoern@schiessle.org>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Daniel Calviño Sánchez <danxuliu@gmail.com>
* @author Joas Schilling <coding@schilljs.com>
* @author John Molakvoæ <skjnldsv@protonmail.com>
* @author Maxence Lange <maxence@nextcloud.com>
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Share20;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IUserManager;
use OCP\Share\Exceptions\IllegalIDChangeException;
use OCP\Share\IAttributes;
use OCP\Share\IShare;
class Share implements IShare {
/** @var string */
private $id;
/** @var string */
private $providerId;
/** @var Node */
private $node;
/** @var int */
private $fileId;
/** @var string */
private $nodeType;
/** @var int */
private $shareType;
/** @var string */
private $sharedWith;
/** @var string */
private $sharedWithDisplayName;
/** @var string */
private $sharedWithAvatar;
/** @var string */
private $sharedBy;
/** @var string */
private $shareOwner;
/** @var int */
private $permissions;
/** @var IAttributes */
private $attributes;
/** @var int */
private $status;
/** @var string */
private $note = '';
/** @var \DateTime */
private $expireDate;
/** @var string */
private $password;
private ?\DateTimeInterface $passwordExpirationTime = null;
/** @var bool */
private $sendPasswordByTalk = false;
/** @var string */
private $token;
/** @var int */
private $parent;
/** @var string */
private $target;
/** @var \DateTime */
private $shareTime;
/** @var bool */
private $mailSend;
/** @var string */
private $label = '';
/** @var IRootFolder */
private $rootFolder;
/** @var IUserManager */
private $userManager;
/** @var ICacheEntry|null */
private $nodeCacheEntry;
/** @var bool */
private $hideDownload = false;
public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
$this->rootFolder = $rootFolder;
$this->userManager = $userManager;
}
/**
* @inheritdoc
*/
public function setId($id) {
if (is_int($id)) {
$id = (string)$id;
}
if (!is_string($id)) {
throw new \InvalidArgumentException('String expected.');
}
if ($this->id !== null) {
throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share');
}
$this->id = trim($id);
return $this;
}
/**
* @inheritdoc
*/
public function getId() {
return $this->id;
}
/**
* @inheritdoc
*/
public function getFullId() {
if ($this->providerId === null || $this->id === null) {
throw new \UnexpectedValueException;
}
return $this->providerId . ':' . $this->id;
}
/**
* @inheritdoc
*/
public function setProviderId($id) {
if (!is_string($id)) {
throw new \InvalidArgumentException('String expected.');
}
if ($this->providerId !== null) {
throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share');
}
$this->providerId = trim($id);
return $this;
}
/**
* @inheritdoc
*/
public function setNode(Node $node) {
$this->fileId = null;
$this->nodeType = null;
$this->node = $node;
return $this;
}
/**
* @inheritdoc
*/
public function getNode() {
if ($this->node === null) {
if ($this->shareOwner === null || $this->fileId === null) {
throw new NotFoundException();
}
// for federated shares the owner can be a remote user, in this
// case we use the initiator
if ($this->userManager->userExists($this->shareOwner)) {
$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
} else {
$userFolder = $this->rootFolder->getUserFolder($this->sharedBy);
}
$nodes = $userFolder->getById($this->fileId);
if (empty($nodes)) {
throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId);
}
$this->node = $nodes[0];
}
return $this->node;
}
/**
* @inheritdoc
*/
public function setNodeId($fileId) {
$this->node = null;
$this->fileId = $fileId;
return $this;
}
/**
* @inheritdoc
*/
public function getNodeId() {
if ($this->fileId === null) {
$this->fileId = $this->getNode()->getId();
}
return $this->fileId;
}
/**
* @inheritdoc
*/
public function setNodeType($type) {
if ($type !== 'file' && $type !== 'folder') {
throw new \InvalidArgumentException();
}
$this->nodeType = $type;
return $this;
}
/**
* @inheritdoc
*/
public function getNodeType() {
if ($this->nodeType === null) {
if ($this->getNodeCacheEntry()) {
$info = $this->getNodeCacheEntry();
$this->nodeType = $info->getMimeType() === FileInfo::MIMETYPE_FOLDER ? 'folder' : 'file';
} else {
$node = $this->getNode();
$this->nodeType = $node instanceof File ? 'file' : 'folder';
}
}
return $this->nodeType;
}
/**
* @inheritdoc
*/
public function setShareType($shareType) {
$this->shareType = $shareType;
return $this;
}
/**
* @inheritdoc
*/
public function getShareType() {
return $this->shareType;
}
/**
* @inheritdoc
*/
public function setSharedWith($sharedWith) {
if (!is_string($sharedWith)) {
throw new \InvalidArgumentException();
}
$this->sharedWith = $sharedWith;
return $this;
}
/**
* @inheritdoc
*/
public function getSharedWith() {
return $this->sharedWith;
}
/**
* @inheritdoc
*/
public function setSharedWithDisplayName($displayName) {
if (!is_string($displayName)) {
throw new \InvalidArgumentException();
}
$this->sharedWithDisplayName = $displayName;
return $this;
}
/**
* @inheritdoc
*/
public function getSharedWithDisplayName() {
return $this->sharedWithDisplayName;
}
/**
* @inheritdoc
*/
public function setSharedWithAvatar($src) {
if (!is_string($src)) {
throw new \InvalidArgumentException();
}
$this->sharedWithAvatar = $src;
return $this;
}
/**
* @inheritdoc
*/
public function getSharedWithAvatar() {
return $this->sharedWithAvatar;
}
/**
* @inheritdoc
*/
public function setPermissions($permissions) {
//TODO checks
$this->permissions = $permissions;
return $this;
}
/**
* @inheritdoc
*/
public function getPermissions() {
return $this->permissions;
}
/**
* @inheritdoc
*/
public function newAttributes(): IAttributes {
return new ShareAttributes();
}
/**
* @inheritdoc
*/
public function setAttributes(?IAttributes $attributes) {
$this->attributes = $attributes;
return $this;
}
/**
* @inheritdoc
*/
public function getAttributes(): ?IAttributes {
return $this->attributes;
}
/**
* @inheritdoc
*/
public function setStatus(int $status): IShare {
$this->status = $status;
return $this;
}
/**
* @inheritdoc
*/
public function getStatus(): int {
return $this->status;
}
/**
* @inheritdoc
*/
public function setNote($note) {
$this->note = $note;
return $this;
}
/**
* @inheritdoc
*/
public function getNote() {
if (is_string($this->note)) {
return $this->note;
}
return '';
}
/**
* @inheritdoc
*/
public function setLabel($label) {
$this->label = $label;
return $this;
}
/**
* @inheritdoc
*/
public function getLabel() {
return $this->label;
}
/**
* @inheritdoc
*/
public function setExpirationDate($expireDate) {
//TODO checks
$this->expireDate = $expireDate;
return $this;
}
/**
* @inheritdoc
*/
public function getExpirationDate() {
return $this->expireDate;
}
/**
* @inheritdoc
*/
public function isExpired() {
return $this->getExpirationDate() !== null &&
$this->getExpirationDate() <= new \DateTime();
}
/**
* @inheritdoc
*/
public function setSharedBy($sharedBy) {
if (!is_string($sharedBy)) {
throw new \InvalidArgumentException();
}
//TODO checks
$this->sharedBy = $sharedBy;
return $this;
}
/**
* @inheritdoc
*/
public function getSharedBy() {
//TODO check if set
return $this->sharedBy;
}
/**
* @inheritdoc
*/
public function setShareOwner($shareOwner) {
if (!is_string($shareOwner)) {
throw new \InvalidArgumentException();
}
//TODO checks
$this->shareOwner = $shareOwner;
return $this;
}
/**
* @inheritdoc
*/
public function getShareOwner() {
//TODO check if set
return $this->shareOwner;
}
/**
* @inheritdoc
*/
public function setPassword($password) {
$this->password = $password;
return $this;
}
/**
* @inheritdoc
*/
public function getPassword() {
return $this->password;
}
/**
* @inheritdoc
*/
public function setPasswordExpirationTime(?\DateTimeInterface $passwordExpirationTime = null): IShare {
$this->passwordExpirationTime = $passwordExpirationTime;
return $this;
}
/**
* @inheritdoc
*/
public function getPasswordExpirationTime(): ?\DateTimeInterface {
return $this->passwordExpirationTime;
}
/**
* @inheritdoc
*/
public function setSendPasswordByTalk(bool $sendPasswordByTalk) {
$this->sendPasswordByTalk = $sendPasswordByTalk;
return $this;
}
/**
* @inheritdoc
*/
public function getSendPasswordByTalk(): bool {
return $this->sendPasswordByTalk;
}
/**
* @inheritdoc
*/
public function setToken($token) {
$this->token = $token;
return $this;
}
/**
* @inheritdoc
*/
public function getToken() {
return $this->token;
}
/**
* Set the parent of this share
*
* @param int parent
* @return IShare
* @deprecated The new shares do not have parents. This is just here for legacy reasons.
*/
public function setParent($parent) {
$this->parent = $parent;
return $this;
}
/**
* Get the parent of this share.
*
* @return int
* @deprecated The new shares do not have parents. This is just here for legacy reasons.
*/
public function getParent() {
return $this->parent;
}
/**
* @inheritdoc
*/
public function setTarget($target) {
$this->target = $target;
return $this;
}
/**
* @inheritdoc
*/
public function getTarget() {
return $this->target;
}
/**
* @inheritdoc
*/
public function setShareTime(\DateTime $shareTime) {
$this->shareTime = $shareTime;
return $this;
}
/**
* @inheritdoc
*/
public function getShareTime() {
return $this->shareTime;
}
/**
* @inheritdoc
*/
public function setMailSend($mailSend) {
$this->mailSend = $mailSend;
return $this;
}
/**
* @inheritdoc
*/
public function getMailSend() {
return $this->mailSend;
}
/**
* @inheritdoc
*/
public function setNodeCacheEntry(ICacheEntry $entry) {
$this->nodeCacheEntry = $entry;
}
/**
* @inheritdoc
*/
public function getNodeCacheEntry() {
return $this->nodeCacheEntry;
}
public function setHideDownload(bool $hide): IShare {
$this->hideDownload = $hide;
return $this;
}
public function getHideDownload(): bool {
return $this->hideDownload;
}
}
@@ -0,0 +1,72 @@
<?php
/**
* @author Piotr Mrowczynski <piotr@owncloud.com>
*
* @copyright Copyright (c) 2019, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Share20;
use OCP\Share\IAttributes;
class ShareAttributes implements IAttributes {
/** @var array */
private $attributes;
public function __construct() {
$this->attributes = [];
}
/**
* @inheritdoc
*/
public function setAttribute($scope, $key, $enabled) {
if (!\array_key_exists($scope, $this->attributes)) {
$this->attributes[$scope] = [];
}
$this->attributes[$scope][$key] = $enabled;
return $this;
}
/**
* @inheritdoc
*/
public function getAttribute($scope, $key) {
if (\array_key_exists($scope, $this->attributes) &&
\array_key_exists($key, $this->attributes[$scope])) {
return $this->attributes[$scope][$key];
}
return null;
}
/**
* @inheritdoc
*/
public function toArray() {
$result = [];
foreach ($this->attributes as $scope => $keys) {
foreach ($keys as $key => $enabled) {
$result[] = [
"scope" => $scope,
"key" => $key,
"enabled" => $enabled
];
}
}
return $result;
}
}
@@ -0,0 +1,65 @@
<?php
namespace OC\Share20;
use OCP\Cache\CappedMemoryCache;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUserManager;
/**
* split of from the share manager to allow using it with minimal DI
*/
class ShareDisableChecker {
private CappedMemoryCache $sharingDisabledForUsersCache;
public function __construct(
private IConfig $config,
private IUserManager $userManager,
private IGroupManager $groupManager,
) {
$this->sharingDisabledForUsersCache = new CappedMemoryCache();
}
/**
* @param ?string $userId
* @return bool
*/
public function sharingDisabledForUser(?string $userId) {
if ($userId === null) {
return false;
}
if (isset($this->sharingDisabledForUsersCache[$userId])) {
return $this->sharingDisabledForUsersCache[$userId];
}
if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
$groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
$excludedGroups = json_decode($groupsList);
if (is_null($excludedGroups)) {
$excludedGroups = explode(',', $groupsList);
$newValue = json_encode($excludedGroups);
$this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue);
}
$user = $this->userManager->get($userId);
if (!$user) {
return false;
}
$usersGroups = $this->groupManager->getUserGroupIds($user);
if (!empty($usersGroups)) {
$remainingGroups = array_diff($usersGroups, $excludedGroups);
// if the user is only in groups which are disabled for sharing then
// sharing is also disabled for the user
if (empty($remainingGroups)) {
$this->sharingDisabledForUsersCache[$userId] = true;
return true;
}
}
}
$this->sharingDisabledForUsersCache[$userId] = false;
return false;
}
}
@@ -0,0 +1,217 @@
<?php
/**
* @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Joas Schilling <coding@schilljs.com>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @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 OC\Share20;
use OCP\Files\InvalidPathException;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Share\IManager;
use OCP\Share\IShareHelper;
class ShareHelper implements IShareHelper {
/** @var IManager */
private $shareManager;
public function __construct(IManager $shareManager) {
$this->shareManager = $shareManager;
}
/**
* @param Node $node
* @return array [ users => [Mapping $uid => $pathForUser], remotes => [Mapping $cloudId => $pathToMountRoot]]
*/
public function getPathsForAccessList(Node $node) {
$result = [
'users' => [],
'remotes' => [],
];
$accessList = $this->shareManager->getAccessList($node, true, true);
if (!empty($accessList['users'])) {
$result['users'] = $this->getPathsForUsers($node, $accessList['users']);
}
if (!empty($accessList['remote'])) {
$result['remotes'] = $this->getPathsForRemotes($node, $accessList['remote']);
}
return $result;
}
/**
* Sample:
* $users = [
* 'test1' => ['node_id' => 16, 'node_path' => '/foo'],
* 'test2' => ['node_id' => 23, 'node_path' => '/bar'],
* 'test3' => ['node_id' => 42, 'node_path' => '/cat'],
* 'test4' => ['node_id' => 48, 'node_path' => '/dog'],
* ];
*
* Node tree:
* - SixTeen is the parent of TwentyThree
* - TwentyThree is the parent of FortyTwo
* - FortyEight does not exist
*
* $return = [
* 'test1' => '/foo/TwentyThree/FortyTwo',
* 'test2' => '/bar/FortyTwo',
* 'test3' => '/cat',
* ],
*
* @param Node $node
* @param array[] $users
* @return array
*/
protected function getPathsForUsers(Node $node, array $users) {
/** @var array[] $byId */
$byId = [];
/** @var array[] $results */
$results = [];
foreach ($users as $uid => $info) {
if (!isset($byId[$info['node_id']])) {
$byId[$info['node_id']] = [];
}
$byId[$info['node_id']][$uid] = $info['node_path'];
}
try {
if (isset($byId[$node->getId()])) {
foreach ($byId[$node->getId()] as $uid => $path) {
$results[$uid] = $path;
}
unset($byId[$node->getId()]);
}
} catch (NotFoundException $e) {
return $results;
} catch (InvalidPathException $e) {
return $results;
}
if (empty($byId)) {
return $results;
}
$item = $node;
$appendix = '/' . $node->getName();
while (!empty($byId)) {
try {
/** @var Node $item */
$item = $item->getParent();
if (!empty($byId[$item->getId()])) {
foreach ($byId[$item->getId()] as $uid => $path) {
$results[$uid] = $path . $appendix;
}
unset($byId[$item->getId()]);
}
$appendix = '/' . $item->getName() . $appendix;
} catch (NotFoundException $e) {
return $results;
} catch (InvalidPathException $e) {
return $results;
} catch (NotPermittedException $e) {
return $results;
}
}
return $results;
}
/**
* Sample:
* $remotes = [
* 'test1' => ['node_id' => 16, 'token' => 't1'],
* 'test2' => ['node_id' => 23, 'token' => 't2'],
* 'test3' => ['node_id' => 42, 'token' => 't3'],
* 'test4' => ['node_id' => 48, 'token' => 't4'],
* ];
*
* Node tree:
* - SixTeen is the parent of TwentyThree
* - TwentyThree is the parent of FortyTwo
* - FortyEight does not exist
*
* $return = [
* 'test1' => ['token' => 't1', 'node_path' => '/SixTeen'],
* 'test2' => ['token' => 't2', 'node_path' => '/SixTeen/TwentyThree'],
* 'test3' => ['token' => 't3', 'node_path' => '/SixTeen/TwentyThree/FortyTwo'],
* ],
*
* @param Node $node
* @param array[] $remotes
* @return array
*/
protected function getPathsForRemotes(Node $node, array $remotes) {
/** @var array[] $byId */
$byId = [];
/** @var array[] $results */
$results = [];
foreach ($remotes as $cloudId => $info) {
if (!isset($byId[$info['node_id']])) {
$byId[$info['node_id']] = [];
}
$byId[$info['node_id']][$cloudId] = $info['token'];
}
$item = $node;
while (!empty($byId)) {
try {
if (!empty($byId[$item->getId()])) {
$path = $this->getMountedPath($item);
foreach ($byId[$item->getId()] as $uid => $token) {
$results[$uid] = [
'node_path' => $path,
'token' => $token,
];
}
unset($byId[$item->getId()]);
}
/** @var Node $item */
$item = $item->getParent();
} catch (NotFoundException $e) {
return $results;
} catch (InvalidPathException $e) {
return $results;
} catch (NotPermittedException $e) {
return $results;
}
}
return $results;
}
/**
* @param Node $node
* @return string
*/
protected function getMountedPath(Node $node) {
$path = $node->getPath();
$sections = explode('/', $path, 4);
return '/' . $sections[3];
}
}
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @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 OC\Share20;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Group\Events\UserRemovedEvent;
use OCP\Share\IManager;
/**
* @template-implements IEventListener<UserRemovedEvent>
*/
class UserRemovedListener implements IEventListener {
/** @var IManager */
protected $shareManager;
public function __construct(IManager $shareManager) {
$this->shareManager = $shareManager;
}
public function handle(Event $event): void {
if (!$event instanceof UserRemovedEvent) {
return;
}
$this->shareManager->userDeletedFromGroup($event->getUser()->getUID(), $event->getGroup()->getGID());
}
}