2016-01-11 12:30:03 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
* @author Daniel Calviño Sánchez <danxuliu@gmail.com>
|
2020-08-24 15:54:25 +03:00
|
|
|
* @author Daniel Kesselberg <mail@danielkesselberg.de>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2020-12-16 16:54:15 +03:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Maxence Lange <maxence@nextcloud.com>
|
2020-08-24 15:54:25 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-11 12:30:03 +03:00
|
|
|
*
|
|
|
|
* @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,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2016-01-11 12:30:03 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2016-01-11 12:30:03 +03:00
|
|
|
namespace OC\Share20;
|
|
|
|
|
2019-11-22 22:52:10 +03:00
|
|
|
use OC\Share20\Exception\ProviderException;
|
2016-02-04 12:00:55 +03:00
|
|
|
use OCA\FederatedFileSharing\AddressHandler;
|
|
|
|
use OCA\FederatedFileSharing\FederatedShareProvider;
|
|
|
|
use OCA\FederatedFileSharing\Notifications;
|
|
|
|
use OCA\FederatedFileSharing\TokenHandler;
|
2017-03-30 16:23:44 +03:00
|
|
|
use OCA\ShareByMail\Settings\SettingsManager;
|
2016-07-29 16:38:31 +03:00
|
|
|
use OCA\ShareByMail\ShareByMailProvider;
|
2017-04-18 23:23:07 +03:00
|
|
|
use OCP\Defaults;
|
2020-07-13 16:43:42 +03:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2016-01-20 10:30:37 +03:00
|
|
|
use OCP\IServerContainer;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\Share\IProviderFactory;
|
2020-06-24 17:49:16 +03:00
|
|
|
use OCP\Share\IShare;
|
2020-12-03 17:51:58 +03:00
|
|
|
use OCP\Share\IShareProvider;
|
2016-01-13 16:21:55 +03:00
|
|
|
|
2016-01-11 12:30:03 +03:00
|
|
|
/**
|
|
|
|
* Class ProviderFactory
|
|
|
|
*
|
|
|
|
* @package OC\Share20
|
|
|
|
*/
|
|
|
|
class ProviderFactory implements IProviderFactory {
|
|
|
|
|
2016-01-20 10:30:37 +03:00
|
|
|
/** @var IServerContainer */
|
|
|
|
private $serverContainer;
|
2016-01-13 16:21:55 +03:00
|
|
|
/** @var DefaultShareProvider */
|
|
|
|
private $defaultProvider = null;
|
2016-02-04 12:00:55 +03:00
|
|
|
/** @var FederatedShareProvider */
|
|
|
|
private $federatedProvider = null;
|
2016-07-29 16:38:31 +03:00
|
|
|
/** @var ShareByMailProvider */
|
|
|
|
private $shareByMailProvider;
|
2017-07-11 14:21:24 +03:00
|
|
|
/** @var \OCA\Circles\ShareByCircleProvider */
|
|
|
|
private $shareByCircleProvider = null;
|
|
|
|
/** @var bool */
|
|
|
|
private $circlesAreNotAvailable = false;
|
2019-09-05 16:32:58 +03:00
|
|
|
/** @var \OCA\Talk\Share\RoomShareProvider */
|
2018-06-29 11:10:58 +03:00
|
|
|
private $roomShareProvider = null;
|
2016-01-13 16:21:55 +03:00
|
|
|
|
2020-12-03 17:51:58 +03:00
|
|
|
private $registeredShareProviders = [];
|
|
|
|
|
|
|
|
private $shareProviders = [];
|
|
|
|
|
2016-01-20 10:30:37 +03:00
|
|
|
/**
|
|
|
|
* IProviderFactory constructor.
|
2017-03-17 22:48:33 +03:00
|
|
|
*
|
2016-01-20 10:30:37 +03:00
|
|
|
* @param IServerContainer $serverContainer
|
|
|
|
*/
|
|
|
|
public function __construct(IServerContainer $serverContainer) {
|
|
|
|
$this->serverContainer = $serverContainer;
|
|
|
|
}
|
|
|
|
|
2020-12-03 17:51:58 +03:00
|
|
|
public function registerProvider(string $shareProviderClass): void {
|
|
|
|
$this->registeredShareProviders[] = $shareProviderClass;
|
|
|
|
}
|
|
|
|
|
2016-01-11 12:30:03 +03:00
|
|
|
/**
|
|
|
|
* Create the default share provider.
|
|
|
|
*
|
|
|
|
* @return DefaultShareProvider
|
|
|
|
*/
|
|
|
|
protected function defaultShareProvider() {
|
2016-01-13 16:21:55 +03:00
|
|
|
if ($this->defaultProvider === null) {
|
|
|
|
$this->defaultProvider = new DefaultShareProvider(
|
2016-01-20 10:30:37 +03:00
|
|
|
$this->serverContainer->getDatabaseConnection(),
|
|
|
|
$this->serverContainer->getUserManager(),
|
|
|
|
$this->serverContainer->getGroupManager(),
|
2018-07-12 15:55:50 +03:00
|
|
|
$this->serverContainer->getLazyRootFolder(),
|
|
|
|
$this->serverContainer->getMailer(),
|
|
|
|
$this->serverContainer->query(Defaults::class),
|
2020-06-23 09:14:27 +03:00
|
|
|
$this->serverContainer->getL10NFactory(),
|
|
|
|
$this->serverContainer->getURLGenerator(),
|
|
|
|
$this->serverContainer->getConfig()
|
2016-01-13 16:21:55 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->defaultProvider;
|
2016-01-11 12:30:03 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 12:00:55 +03:00
|
|
|
/**
|
|
|
|
* Create the federated share provider
|
|
|
|
*
|
|
|
|
* @return FederatedShareProvider
|
|
|
|
*/
|
|
|
|
protected function federatedShareProvider() {
|
|
|
|
if ($this->federatedProvider === null) {
|
2016-02-04 13:13:06 +03:00
|
|
|
/*
|
|
|
|
* Check if the app is enabled
|
|
|
|
*/
|
|
|
|
$appManager = $this->serverContainer->getAppManager();
|
|
|
|
if (!$appManager->isEnabledForUser('federatedfilesharing')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-02-04 12:00:55 +03:00
|
|
|
/*
|
|
|
|
* TODO: add factory to federated sharing app
|
|
|
|
*/
|
2019-09-19 13:57:45 +03:00
|
|
|
$l = $this->serverContainer->getL10N('federatedfilesharing');
|
2016-02-04 12:00:55 +03:00
|
|
|
$addressHandler = new AddressHandler(
|
|
|
|
$this->serverContainer->getURLGenerator(),
|
2017-01-27 14:52:17 +03:00
|
|
|
$l,
|
|
|
|
$this->serverContainer->getCloudIdManager()
|
2016-02-04 12:00:55 +03:00
|
|
|
);
|
|
|
|
$notifications = new Notifications(
|
|
|
|
$addressHandler,
|
2016-02-25 22:46:01 +03:00
|
|
|
$this->serverContainer->getHTTPClientService(),
|
2017-04-05 23:35:59 +03:00
|
|
|
$this->serverContainer->query(\OCP\OCS\IDiscoveryService::class),
|
2018-05-04 16:25:02 +03:00
|
|
|
$this->serverContainer->getJobList(),
|
|
|
|
\OC::$server->getCloudFederationProviderManager(),
|
2020-07-13 16:43:42 +03:00
|
|
|
\OC::$server->getCloudFederationFactory(),
|
|
|
|
$this->serverContainer->query(IEventDispatcher::class)
|
2016-02-04 12:00:55 +03:00
|
|
|
);
|
|
|
|
$tokenHandler = new TokenHandler(
|
|
|
|
$this->serverContainer->getSecureRandom()
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->federatedProvider = new FederatedShareProvider(
|
|
|
|
$this->serverContainer->getDatabaseConnection(),
|
|
|
|
$addressHandler,
|
|
|
|
$notifications,
|
|
|
|
$tokenHandler,
|
|
|
|
$l,
|
|
|
|
$this->serverContainer->getLogger(),
|
2016-04-18 19:17:08 +03:00
|
|
|
$this->serverContainer->getLazyRootFolder(),
|
2016-05-11 21:48:27 +03:00
|
|
|
$this->serverContainer->getConfig(),
|
2017-01-27 14:52:17 +03:00
|
|
|
$this->serverContainer->getUserManager(),
|
2017-05-24 10:07:58 +03:00
|
|
|
$this->serverContainer->getCloudIdManager(),
|
2018-06-13 15:19:59 +03:00
|
|
|
$this->serverContainer->getGlobalScaleConfig(),
|
|
|
|
$this->serverContainer->getCloudFederationProviderManager()
|
2016-02-04 12:00:55 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->federatedProvider;
|
|
|
|
}
|
|
|
|
|
2016-07-29 16:38:31 +03:00
|
|
|
/**
|
|
|
|
* Create the federated share provider
|
|
|
|
*
|
2017-03-01 15:45:04 +03:00
|
|
|
* @return ShareByMailProvider
|
2016-07-29 16:38:31 +03:00
|
|
|
*/
|
|
|
|
protected function getShareByMailProvider() {
|
|
|
|
if ($this->shareByMailProvider === null) {
|
|
|
|
/*
|
|
|
|
* Check if the app is enabled
|
|
|
|
*/
|
|
|
|
$appManager = $this->serverContainer->getAppManager();
|
|
|
|
if (!$appManager->isEnabledForUser('sharebymail')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-03-30 16:23:44 +03:00
|
|
|
$settingsManager = new SettingsManager($this->serverContainer->getConfig());
|
2016-07-29 16:38:31 +03:00
|
|
|
|
|
|
|
$this->shareByMailProvider = new ShareByMailProvider(
|
|
|
|
$this->serverContainer->getDatabaseConnection(),
|
|
|
|
$this->serverContainer->getSecureRandom(),
|
|
|
|
$this->serverContainer->getUserManager(),
|
|
|
|
$this->serverContainer->getLazyRootFolder(),
|
2017-03-30 16:23:44 +03:00
|
|
|
$this->serverContainer->getL10N('sharebymail'),
|
2016-10-26 12:04:00 +03:00
|
|
|
$this->serverContainer->getLogger(),
|
|
|
|
$this->serverContainer->getMailer(),
|
2016-11-07 17:08:56 +03:00
|
|
|
$this->serverContainer->getURLGenerator(),
|
2017-03-30 16:23:44 +03:00
|
|
|
$this->serverContainer->getActivityManager(),
|
2017-04-18 23:23:07 +03:00
|
|
|
$settingsManager,
|
2017-04-10 19:36:23 +03:00
|
|
|
$this->serverContainer->query(Defaults::class),
|
2017-04-19 17:56:34 +03:00
|
|
|
$this->serverContainer->getHasher(),
|
2020-08-09 19:13:14 +03:00
|
|
|
$this->serverContainer->get(IEventDispatcher::class)
|
2016-07-29 16:38:31 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->shareByMailProvider;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-17 22:48:33 +03:00
|
|
|
/**
|
|
|
|
* Create the circle share provider
|
|
|
|
*
|
|
|
|
* @return FederatedShareProvider
|
2017-07-18 21:38:40 +03:00
|
|
|
*
|
|
|
|
* @suppress PhanUndeclaredClassMethod
|
2017-03-17 22:48:33 +03:00
|
|
|
*/
|
|
|
|
protected function getShareByCircleProvider() {
|
2017-07-11 14:21:24 +03:00
|
|
|
if ($this->circlesAreNotAvailable) {
|
2017-03-17 22:48:33 +03:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-07-11 14:21:24 +03:00
|
|
|
if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') ||
|
|
|
|
!class_exists('\OCA\Circles\ShareByCircleProvider')
|
|
|
|
) {
|
|
|
|
$this->circlesAreNotAvailable = true;
|
|
|
|
return null;
|
|
|
|
}
|
2017-03-17 22:48:33 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-06-29 11:10:58 +03:00
|
|
|
/**
|
|
|
|
* 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 {
|
2019-09-05 16:32:58 +03:00
|
|
|
$this->roomShareProvider = $this->serverContainer->query('\OCA\Talk\Share\RoomShareProvider');
|
2018-06-29 11:10:58 +03:00
|
|
|
} catch (\OCP\AppFramework\QueryException $e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->roomShareProvider;
|
|
|
|
}
|
2017-03-17 22:48:33 +03:00
|
|
|
|
2016-01-11 12:30:03 +03:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2016-01-13 16:21:55 +03:00
|
|
|
public function getProvider($id) {
|
2016-02-04 13:13:06 +03:00
|
|
|
$provider = null;
|
2020-12-03 17:51:58 +03:00
|
|
|
if (isset($this->shareProviders[$id])) {
|
|
|
|
return $this->shareProviders[$id];
|
|
|
|
}
|
|
|
|
|
2016-01-13 16:21:55 +03:00
|
|
|
if ($id === 'ocinternal') {
|
2016-02-04 13:13:06 +03:00
|
|
|
$provider = $this->defaultShareProvider();
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($id === 'ocFederatedSharing') {
|
2016-02-04 13:13:06 +03:00
|
|
|
$provider = $this->federatedShareProvider();
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($id === 'ocMailShare') {
|
2016-07-29 16:38:31 +03:00
|
|
|
$provider = $this->getShareByMailProvider();
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($id === 'ocCircleShare') {
|
2017-03-17 22:48:33 +03:00
|
|
|
$provider = $this->getShareByCircleProvider();
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($id === 'ocRoomShare') {
|
2018-06-29 11:10:58 +03:00
|
|
|
$provider = $this->getRoomShareProvider();
|
2016-01-13 16:21:55 +03:00
|
|
|
}
|
|
|
|
|
2020-12-03 17:51:58 +03:00
|
|
|
foreach ($this->registeredShareProviders as $shareProvider) {
|
|
|
|
/** @var IShareProvider $instance */
|
|
|
|
$instance = $this->serverContainer->get($shareProvider);
|
|
|
|
$this->shareProviders[$instance->identifier()] = $instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($this->shareProviders[$id])) {
|
|
|
|
$provider = $this->shareProviders[$id];
|
|
|
|
}
|
|
|
|
|
2016-02-04 13:13:06 +03:00
|
|
|
if ($provider === null) {
|
|
|
|
throw new ProviderException('No provider with id .' . $id . ' found.');
|
2016-02-04 12:00:55 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 13:13:06 +03:00
|
|
|
return $provider;
|
2016-01-13 16:21:55 +03:00
|
|
|
}
|
2016-01-11 12:30:03 +03:00
|
|
|
|
2016-01-13 16:21:55 +03:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function getProviderForType($shareType) {
|
2016-02-04 13:13:06 +03:00
|
|
|
$provider = null;
|
|
|
|
|
2020-06-24 17:49:16 +03:00
|
|
|
if ($shareType === IShare::TYPE_USER ||
|
|
|
|
$shareType === IShare::TYPE_GROUP ||
|
|
|
|
$shareType === IShare::TYPE_LINK
|
2017-03-17 22:48:33 +03:00
|
|
|
) {
|
2016-02-04 13:13:06 +03:00
|
|
|
$provider = $this->defaultShareProvider();
|
2020-06-24 17:49:16 +03:00
|
|
|
} elseif ($shareType === IShare::TYPE_REMOTE || $shareType === IShare::TYPE_REMOTE_GROUP) {
|
2016-02-04 13:13:06 +03:00
|
|
|
$provider = $this->federatedShareProvider();
|
2020-06-24 17:49:16 +03:00
|
|
|
} elseif ($shareType === IShare::TYPE_EMAIL) {
|
2016-07-29 16:38:31 +03:00
|
|
|
$provider = $this->getShareByMailProvider();
|
2020-06-24 17:49:16 +03:00
|
|
|
} elseif ($shareType === IShare::TYPE_CIRCLE) {
|
2017-03-17 22:48:33 +03:00
|
|
|
$provider = $this->getShareByCircleProvider();
|
2020-06-24 17:49:16 +03:00
|
|
|
} elseif ($shareType === IShare::TYPE_ROOM) {
|
2018-06-29 11:10:58 +03:00
|
|
|
$provider = $this->getRoomShareProvider();
|
2020-12-03 17:52:43 +03:00
|
|
|
} elseif ($shareType === IShare::TYPE_DECK) {
|
|
|
|
$provider = $this->getProvider('deck');
|
2016-02-04 13:13:06 +03:00
|
|
|
}
|
|
|
|
|
2017-03-17 22:48:33 +03:00
|
|
|
|
2016-02-04 13:13:06 +03:00
|
|
|
if ($provider === null) {
|
|
|
|
throw new ProviderException('No share provider for share type ' . $shareType);
|
2016-01-13 16:21:55 +03:00
|
|
|
}
|
2016-01-11 12:30:03 +03:00
|
|
|
|
2016-02-04 13:13:06 +03:00
|
|
|
return $provider;
|
2016-01-11 12:30:03 +03:00
|
|
|
}
|
2016-06-18 23:04:56 +03:00
|
|
|
|
|
|
|
public function getAllProviders() {
|
2017-03-17 22:48:33 +03:00
|
|
|
$shares = [$this->defaultShareProvider(), $this->federatedShareProvider()];
|
2016-11-28 14:13:55 +03:00
|
|
|
$shareByMail = $this->getShareByMailProvider();
|
|
|
|
if ($shareByMail !== null) {
|
2017-03-17 22:48:33 +03:00
|
|
|
$shares[] = $shareByMail;
|
|
|
|
}
|
|
|
|
$shareByCircle = $this->getShareByCircleProvider();
|
|
|
|
if ($shareByCircle !== null) {
|
|
|
|
$shares[] = $shareByCircle;
|
2016-11-28 14:13:55 +03:00
|
|
|
}
|
2018-06-29 11:10:58 +03:00
|
|
|
$roomShare = $this->getRoomShareProvider();
|
|
|
|
if ($roomShare !== null) {
|
|
|
|
$shares[] = $roomShare;
|
|
|
|
}
|
2017-03-17 22:48:33 +03:00
|
|
|
|
2020-12-03 18:03:35 +03:00
|
|
|
foreach ($this->registeredShareProviders as $shareProvider) {
|
|
|
|
/** @var IShareProvider $instance */
|
|
|
|
$instance = $this->serverContainer->get($shareProvider);
|
|
|
|
if (!isset($this->shareProviders[$instance->identifier()])) {
|
|
|
|
$this->shareProviders[$instance->identifier()] = $instance;
|
|
|
|
}
|
|
|
|
$shares[] = $this->shareProviders[$instance->identifier()];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-03-17 22:48:33 +03:00
|
|
|
return $shares;
|
2016-06-18 23:04:56 +03:00
|
|
|
}
|
2016-01-11 12:30:03 +03:00
|
|
|
}
|