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