From e10105474fbef8940fdfa96d5e2bf2f09b1f0649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 18 Apr 2016 18:17:08 +0200 Subject: [PATCH] move federated sharing settings to the federatedfilesharing app --- apps/dav/appinfo/v1/publicwebdav.php | 4 +- apps/federatedfilesharing/appinfo/app.php | 6 +- .../appinfo/application.php | 88 +++++++++++++++++++ .../css/3rdparty/gs-share/style.css | 0 .../css/settings-personal.css | 0 .../img/social-diaspora.svg | 0 .../img/social-facebook.svg | 0 .../img/social-gnu.svg | 0 .../img/social-googleplus.svg | 0 .../img/social-twitter.svg | 0 .../js/3rdparty/gs-share/gs-share.js | 0 .../js/settings-admin.js | 0 .../js/settings-personal.js | 0 .../lib/federatedshareprovider.php | 30 ++++++- .../settings-admin.php | 11 ++- .../settings-personal.php | 11 ++- .../templates/settings-admin.php | 2 + .../templates/settings-personal.php | 8 +- .../tests/federatedshareprovidertest.php | 46 +++++++++- apps/files_sharing/ajax/external.php | 5 +- apps/files_sharing/ajax/shareinfo.php | 5 +- apps/files_sharing/api/server2server.php | 18 +++- apps/files_sharing/appinfo/app.php | 3 - apps/files_sharing/appinfo/application.php | 4 +- .../lib/controllers/sharecontroller.php | 10 ++- apps/files_sharing/lib/helper.php | 20 ----- apps/files_sharing/lib/share/file.php | 16 +++- .../tests/controller/sharecontroller.php | 12 ++- apps/files_sharing/tests/server2server.php | 11 ++- lib/private/Share20/ProviderFactory.php | 3 +- ocs/routes.php | 3 +- 31 files changed, 263 insertions(+), 53 deletions(-) create mode 100644 apps/federatedfilesharing/appinfo/application.php rename apps/{files_sharing => federatedfilesharing}/css/3rdparty/gs-share/style.css (100%) rename apps/{files_sharing => federatedfilesharing}/css/settings-personal.css (100%) rename apps/{files_sharing => federatedfilesharing}/img/social-diaspora.svg (100%) rename apps/{files_sharing => federatedfilesharing}/img/social-facebook.svg (100%) rename apps/{files_sharing => federatedfilesharing}/img/social-gnu.svg (100%) rename apps/{files_sharing => federatedfilesharing}/img/social-googleplus.svg (100%) rename apps/{files_sharing => federatedfilesharing}/img/social-twitter.svg (100%) rename apps/{files_sharing => federatedfilesharing}/js/3rdparty/gs-share/gs-share.js (100%) rename apps/{files_sharing => federatedfilesharing}/js/settings-admin.js (100%) rename apps/{files_sharing => federatedfilesharing}/js/settings-personal.js (100%) rename apps/{files_sharing => federatedfilesharing}/settings-admin.php (65%) rename apps/{files_sharing => federatedfilesharing}/settings-personal.php (80%) rename apps/{files_sharing => federatedfilesharing}/templates/settings-admin.php (95%) rename apps/{files_sharing => federatedfilesharing}/templates/settings-personal.php (91%) diff --git a/apps/dav/appinfo/v1/publicwebdav.php b/apps/dav/appinfo/v1/publicwebdav.php index 43fedb1941..39c169728b 100644 --- a/apps/dav/appinfo/v1/publicwebdav.php +++ b/apps/dav/appinfo/v1/publicwebdav.php @@ -55,7 +55,9 @@ $linkCheckPlugin = new \OCA\DAV\Files\Sharing\PublicLinkCheckPlugin(); $server = $serverFactory->createServer($baseuri, $requestUri, $authBackend, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin) { $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); - if (OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled() === false && !$isAjax) { + $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing'); + $federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); + if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) { // this is what is thrown when trying to access a non-existing share throw new \Sabre\DAV\Exception\NotAuthenticated(); } diff --git a/apps/federatedfilesharing/appinfo/app.php b/apps/federatedfilesharing/appinfo/app.php index 804ab69759..23af62037a 100644 --- a/apps/federatedfilesharing/appinfo/app.php +++ b/apps/federatedfilesharing/appinfo/app.php @@ -21,7 +21,5 @@ namespace OCA\FederatedFileSharing\AppInfo; -use OCP\AppFramework\App; - -new App('federatedfilesharing'); - +$app = new Application('federatedfilesharing'); +$app->registerSettings(); diff --git a/apps/federatedfilesharing/appinfo/application.php b/apps/federatedfilesharing/appinfo/application.php new file mode 100644 index 0000000000..5a213aec8e --- /dev/null +++ b/apps/federatedfilesharing/appinfo/application.php @@ -0,0 +1,88 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 + * + */ + + +namespace OCA\FederatedFileSharing\AppInfo; + + +use OCA\FederatedFileSharing\FederatedShareProvider; +use OCP\AppFramework\App; + +class Application extends App { + + /** @var FederatedShareProvider */ + protected $federatedShareProvider; + + /** + * register personal and admin settings page + */ + public function registerSettings() { + \OCP\App::registerAdmin('federatedfilesharing', 'settings-admin'); + \OCP\App::registerPersonal('federatedfilesharing', 'settings-personal'); + } + + /** + * get instance of federated share provider + * + * @return FederatedShareProvider + */ + public function getFederatedShareProvider() { + if ($this->federatedShareProvider === null) { + $this->initFederatedShareProvider(); + } + return $this->federatedShareProvider; + } + + /** + * initialize federated share provider + */ + protected function initFederatedShareProvider() { + $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( + \OC::$server->getURLGenerator(), + \OC::$server->getL10N('federatedfilesharing') + ); + $discoveryManager = new \OCA\FederatedFileSharing\DiscoveryManager( + \OC::$server->getMemCacheFactory(), + \OC::$server->getHTTPClientService() + ); + $notifications = new \OCA\FederatedFileSharing\Notifications( + $addressHandler, + \OC::$server->getHTTPClientService(), + $discoveryManager, + \OC::$server->getJobList() + ); + $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( + \OC::$server->getSecureRandom() + ); + + $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( + \OC::$server->getDatabaseConnection(), + $addressHandler, + $notifications, + $tokenHandler, + \OC::$server->getL10N('federatedfilesharing'), + \OC::$server->getLogger(), + \OC::$server->getLazyRootFolder(), + \OC::$server->getConfig() + ); + } + +} diff --git a/apps/files_sharing/css/3rdparty/gs-share/style.css b/apps/federatedfilesharing/css/3rdparty/gs-share/style.css similarity index 100% rename from apps/files_sharing/css/3rdparty/gs-share/style.css rename to apps/federatedfilesharing/css/3rdparty/gs-share/style.css diff --git a/apps/files_sharing/css/settings-personal.css b/apps/federatedfilesharing/css/settings-personal.css similarity index 100% rename from apps/files_sharing/css/settings-personal.css rename to apps/federatedfilesharing/css/settings-personal.css diff --git a/apps/files_sharing/img/social-diaspora.svg b/apps/federatedfilesharing/img/social-diaspora.svg similarity index 100% rename from apps/files_sharing/img/social-diaspora.svg rename to apps/federatedfilesharing/img/social-diaspora.svg diff --git a/apps/files_sharing/img/social-facebook.svg b/apps/federatedfilesharing/img/social-facebook.svg similarity index 100% rename from apps/files_sharing/img/social-facebook.svg rename to apps/federatedfilesharing/img/social-facebook.svg diff --git a/apps/files_sharing/img/social-gnu.svg b/apps/federatedfilesharing/img/social-gnu.svg similarity index 100% rename from apps/files_sharing/img/social-gnu.svg rename to apps/federatedfilesharing/img/social-gnu.svg diff --git a/apps/files_sharing/img/social-googleplus.svg b/apps/federatedfilesharing/img/social-googleplus.svg similarity index 100% rename from apps/files_sharing/img/social-googleplus.svg rename to apps/federatedfilesharing/img/social-googleplus.svg diff --git a/apps/files_sharing/img/social-twitter.svg b/apps/federatedfilesharing/img/social-twitter.svg similarity index 100% rename from apps/files_sharing/img/social-twitter.svg rename to apps/federatedfilesharing/img/social-twitter.svg diff --git a/apps/files_sharing/js/3rdparty/gs-share/gs-share.js b/apps/federatedfilesharing/js/3rdparty/gs-share/gs-share.js similarity index 100% rename from apps/files_sharing/js/3rdparty/gs-share/gs-share.js rename to apps/federatedfilesharing/js/3rdparty/gs-share/gs-share.js diff --git a/apps/files_sharing/js/settings-admin.js b/apps/federatedfilesharing/js/settings-admin.js similarity index 100% rename from apps/files_sharing/js/settings-admin.js rename to apps/federatedfilesharing/js/settings-admin.js diff --git a/apps/files_sharing/js/settings-personal.js b/apps/federatedfilesharing/js/settings-personal.js similarity index 100% rename from apps/files_sharing/js/settings-personal.js rename to apps/federatedfilesharing/js/settings-personal.js diff --git a/apps/federatedfilesharing/lib/federatedshareprovider.php b/apps/federatedfilesharing/lib/federatedshareprovider.php index 78b0b66420..d014a6219a 100644 --- a/apps/federatedfilesharing/lib/federatedshareprovider.php +++ b/apps/federatedfilesharing/lib/federatedshareprovider.php @@ -25,6 +25,8 @@ namespace OCA\FederatedFileSharing; use OC\Share20\Share; use OCP\Files\IRootFolder; +use OCP\IAppConfig; +use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; use OCP\Share\IShare; @@ -65,6 +67,9 @@ class FederatedShareProvider implements IShareProvider { /** @var IRootFolder */ private $rootFolder; + /** @var IConfig */ + private $config; + /** * DefaultShareProvider constructor. * @@ -75,6 +80,7 @@ class FederatedShareProvider implements IShareProvider { * @param IL10N $l10n * @param ILogger $logger * @param IRootFolder $rootFolder + * @param IConfig $config */ public function __construct( IDBConnection $connection, @@ -83,7 +89,8 @@ class FederatedShareProvider implements IShareProvider { TokenHandler $tokenHandler, IL10N $l10n, ILogger $logger, - IRootFolder $rootFolder + IRootFolder $rootFolder, + IConfig $config ) { $this->dbConnection = $connection; $this->addressHandler = $addressHandler; @@ -92,6 +99,7 @@ class FederatedShareProvider implements IShareProvider { $this->l = $l10n; $this->logger = $logger; $this->rootFolder = $rootFolder; + $this->config = $config; } /** @@ -601,4 +609,24 @@ class FederatedShareProvider implements IShareProvider { // We don't handle groups here return; } + + /** + * check if users from other ownCloud instances are allowed to mount public links share by this instance + * + * @return bool + */ + public function isOutgoingServer2serverShareEnabled() { + $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); + return ($result === 'yes') ? true : false; + } + + /** + * check if users are allowed to mount public links from other ownClouds + * + * @return bool + */ + public function isIncomingServer2serverShareEnabled() { + $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); + return ($result === 'yes') ? true : false; + } } diff --git a/apps/files_sharing/settings-admin.php b/apps/federatedfilesharing/settings-admin.php similarity index 65% rename from apps/files_sharing/settings-admin.php rename to apps/federatedfilesharing/settings-admin.php index b2a305ebcd..9dd21281fd 100644 --- a/apps/files_sharing/settings-admin.php +++ b/apps/federatedfilesharing/settings-admin.php @@ -20,12 +20,15 @@ * */ +use OCA\FederatedFileSharing\AppInfo\Application; + \OC_Util::checkAdminUser(); -\OCP\Util::addScript('files_sharing', 'settings-admin'); +$app = new Application('federatedfilesharing'); +$federatedShareProvider = $app->getFederatedShareProvider(); -$tmpl = new OCP\Template('files_sharing', 'settings-admin'); -$tmpl->assign('outgoingServer2serverShareEnabled', OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled()); -$tmpl->assign('incomingServer2serverShareEnabled', OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled()); +$tmpl = new OCP\Template('federatedfilesharing', 'settings-admin'); +$tmpl->assign('outgoingServer2serverShareEnabled', $federatedShareProvider->isOutgoingServer2serverShareEnabled()); +$tmpl->assign('incomingServer2serverShareEnabled', $federatedShareProvider->isIncomingServer2serverShareEnabled()); return $tmpl->fetchPage(); diff --git a/apps/files_sharing/settings-personal.php b/apps/federatedfilesharing/settings-personal.php similarity index 80% rename from apps/files_sharing/settings-personal.php rename to apps/federatedfilesharing/settings-personal.php index 982a8b05c1..385d397114 100644 --- a/apps/files_sharing/settings-personal.php +++ b/apps/federatedfilesharing/settings-personal.php @@ -21,9 +21,14 @@ * */ +use OCA\FederatedFileSharing\AppInfo\Application; + \OC_Util::checkLoggedIn(); -$l = \OC::$server->getL10N('files_sharing'); +$l = \OC::$server->getL10N('federatedfilesharing'); + +$app = new Application('federatedfilesharing'); +$federatedShareProvider = $app->getFederatedShareProvider(); $isIE8 = false; preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches); @@ -35,8 +40,8 @@ $cloudID = \OC::$server->getUserSession()->getUser()->getCloudId(); $url = 'https://owncloud.org/federation#' . $cloudID; $ownCloudLogoPath = \OC::$server->getURLGenerator()->imagePath('core', 'logo-icon.svg'); -$tmpl = new OCP\Template('files_sharing', 'settings-personal'); -$tmpl->assign('outgoingServer2serverShareEnabled', \OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled()); +$tmpl = new OCP\Template('federatedfilesharing', 'settings-personal'); +$tmpl->assign('outgoingServer2serverShareEnabled', $federatedShareProvider->isOutgoingServer2serverShareEnabled()); $tmpl->assign('message_with_URL', $l->t('Share with me through my #ownCloud Federated Cloud ID, see %s', [$url])); $tmpl->assign('message_without_URL', $l->t('Share with me through my #ownCloud Federated Cloud ID', [$cloudID])); $tmpl->assign('owncloud_logo_path', $ownCloudLogoPath); diff --git a/apps/files_sharing/templates/settings-admin.php b/apps/federatedfilesharing/templates/settings-admin.php similarity index 95% rename from apps/files_sharing/templates/settings-admin.php rename to apps/federatedfilesharing/templates/settings-admin.php index 64b6b8e72a..5d2eb04c17 100644 --- a/apps/files_sharing/templates/settings-admin.php +++ b/apps/federatedfilesharing/templates/settings-admin.php @@ -1,7 +1,9 @@ +

t('Federated Cloud Sharing'));?>

diff --git a/apps/federatedfilesharing/tests/federatedshareprovidertest.php b/apps/federatedfilesharing/tests/federatedshareprovidertest.php index 92e9f10c3c..1fbae90a46 100644 --- a/apps/federatedfilesharing/tests/federatedshareprovidertest.php +++ b/apps/federatedfilesharing/tests/federatedshareprovidertest.php @@ -26,6 +26,7 @@ use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\FederatedFileSharing\Notifications; use OCA\FederatedFileSharing\TokenHandler; use OCP\Files\IRootFolder; +use OCP\IConfig; use OCP\IDBConnection; use OCP\IL10N; use OCP\ILogger; @@ -54,6 +55,8 @@ class FederatedShareProviderTest extends TestCase { protected $logger; /** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */ protected $rootFolder; + /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */ + protected $config; /** @var IManager */ protected $shareManager; @@ -78,6 +81,7 @@ class FederatedShareProviderTest extends TestCase { })); $this->logger = $this->getMock('OCP\ILogger'); $this->rootFolder = $this->getMock('OCP\Files\IRootFolder'); + $this->config = $this->getMock('OCP\IConfig'); $this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l); $this->provider = new FederatedShareProvider( @@ -87,7 +91,8 @@ class FederatedShareProviderTest extends TestCase { $this->tokenHandler, $this->l, $this->logger, - $this->rootFolder + $this->rootFolder, + $this->config ); $this->shareManager = \OC::$server->getShareManager(); @@ -510,4 +515,43 @@ class FederatedShareProviderTest extends TestCase { $this->assertCount($rowDeleted ? 0 : 1, $data); } + + /** + * @dataProvider dataTestFederatedSharingSettings + * + * @param string $isEnabled + * @param bool $expected + */ + public function testIsOutgoingServer2serverShareEnabled($isEnabled, $expected) { + $this->config->expects($this->once())->method('getAppValue') + ->with('files_sharing', 'outgoing_server2server_share_enabled', 'yes') + ->willReturn($isEnabled); + + $this->assertSame($expected, + $this->provider->isOutgoingServer2serverShareEnabled() + ); + } + + /** + * @dataProvider dataTestFederatedSharingSettings + * + * @param string $isEnabled + * @param bool $expected + */ + public function testIsIncomingServer2serverShareEnabled($isEnabled, $expected) { + $this->config->expects($this->once())->method('getAppValue') + ->with('files_sharing', 'incoming_server2server_share_enabled', 'yes') + ->willReturn($isEnabled); + + $this->assertSame($expected, + $this->provider->isIncomingServer2serverShareEnabled() + ); + } + + public function dataTestFederatedSharingSettings() { + return [ + ['yes', true], + ['no', false] + ]; + } } diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php index 76f9d5d766..78e648618b 100644 --- a/apps/files_sharing/ajax/external.php +++ b/apps/files_sharing/ajax/external.php @@ -31,8 +31,11 @@ OCP\JSON::checkAppEnabled('files_sharing'); $l = \OC::$server->getL10N('files_sharing'); +$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing'); +$federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); + // check if server admin allows to mount public links from other servers -if (OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled() === false) { +if ($federatedShareProvider->isIncomingServer2serverShareEnabled() === false) { \OCP\JSON::error(array('data' => array('message' => $l->t('Server to server sharing is not enabled on this server')))); exit(); } diff --git a/apps/files_sharing/ajax/shareinfo.php b/apps/files_sharing/ajax/shareinfo.php index 47bc061c13..d7f756b003 100644 --- a/apps/files_sharing/ajax/shareinfo.php +++ b/apps/files_sharing/ajax/shareinfo.php @@ -29,7 +29,10 @@ if (!isset($_GET['t'])) { exit; } -if (OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled() === false) { +$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing'); +$federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); + +if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false) { \OC_Response::setStatus(404); // 404 not found exit; } diff --git a/apps/files_sharing/api/server2server.php b/apps/files_sharing/api/server2server.php index 11b24d9148..034ec5105e 100644 --- a/apps/files_sharing/api/server2server.php +++ b/apps/files_sharing/api/server2server.php @@ -26,11 +26,25 @@ namespace OCA\Files_Sharing\API; use OCA\FederatedFileSharing\DiscoveryManager; +use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\Files_Sharing\Activity; use OCP\Files\NotFoundException; class Server2Server { + /** @var FederatedShareProvider */ + private $federatedShareProvider; + + + /** + * Server2Server constructor. + * + * @param FederatedShareProvider $federatedShareProvider + */ + public function __construct(FederatedShareProvider $federatedShareProvider) { + $this->federatedShareProvider = $federatedShareProvider; + } + /** * create a new share * @@ -300,9 +314,9 @@ class Server2Server { $result = \OCP\App::isEnabled('files_sharing'); if ($incoming) { - $result = $result && \OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled(); + $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); } else { - $result = $result && \OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled(); + $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); } return $result; diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 29202c15b2..e0cbfd7f5b 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -44,9 +44,6 @@ $l = \OC::$server->getL10N('files_sharing'); $application = new Application(); $application->registerMountProviders(); -\OCP\App::registerAdmin('files_sharing', 'settings-admin'); -\OCP\App::registerPersonal('files_sharing', 'settings-personal'); - \OCA\Files_Sharing\Helper::registerHooks(); \OCP\Share::registerBackend('file', 'OC_Share_Backend_File'); diff --git a/apps/files_sharing/appinfo/application.php b/apps/files_sharing/appinfo/application.php index 5233b34383..b17e213e2e 100644 --- a/apps/files_sharing/appinfo/application.php +++ b/apps/files_sharing/appinfo/application.php @@ -45,6 +45,7 @@ class Application extends App { * Controllers */ $container->registerService('ShareController', function (SimpleContainer $c) use ($server) { + $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing'); return new ShareController( $c->query('AppName'), $c->query('Request'), @@ -56,7 +57,8 @@ class Application extends App { $server->getShareManager(), $server->getSession(), $server->getPreviewManager(), - $server->getRootFolder() + $server->getRootFolder(), + $federatedSharingApp->getFederatedShareProvider() ); }); $container->registerService('ExternalSharesController', function (SimpleContainer $c) { diff --git a/apps/files_sharing/lib/controllers/sharecontroller.php b/apps/files_sharing/lib/controllers/sharecontroller.php index ea024b6016..72294f6b26 100644 --- a/apps/files_sharing/lib/controllers/sharecontroller.php +++ b/apps/files_sharing/lib/controllers/sharecontroller.php @@ -33,6 +33,7 @@ namespace OCA\Files_Sharing\Controllers; use OC; use OC_Files; use OC_Util; +use OCA\FederatedFileSharing\FederatedShareProvider; use OCP; use OCP\Template; use OCP\Share; @@ -79,6 +80,8 @@ class ShareController extends Controller { protected $previewManager; /** @var IRootFolder */ protected $rootFolder; + /** @var FederatedShareProvider */ + protected $federatedShareProvider; /** * @param string $appName @@ -92,6 +95,7 @@ class ShareController extends Controller { * @param ISession $session * @param IPreview $previewManager * @param IRootFolder $rootFolder + * @param FederatedShareProvider $federatedShareProvider */ public function __construct($appName, IRequest $request, @@ -103,7 +107,8 @@ class ShareController extends Controller { \OCP\Share\IManager $shareManager, ISession $session, IPreview $previewManager, - IRootFolder $rootFolder) { + IRootFolder $rootFolder, + FederatedShareProvider $federatedShareProvider) { parent::__construct($appName, $request); $this->config = $config; @@ -115,6 +120,7 @@ class ShareController extends Controller { $this->session = $session; $this->previewManager = $previewManager; $this->rootFolder = $rootFolder; + $this->federatedShareProvider = $federatedShareProvider; } /** @@ -300,7 +306,7 @@ class ShareController extends Controller { $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype()); $shareTmpl['dirToken'] = $token; $shareTmpl['sharingToken'] = $token; - $shareTmpl['server2serversharing'] = Helper::isOutgoingServer2serverShareEnabled(); + $shareTmpl['server2serversharing'] = $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); $shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false'; $shareTmpl['dir'] = ''; $shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize(); diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php index e857974ae7..c09694e988 100644 --- a/apps/files_sharing/lib/helper.php +++ b/apps/files_sharing/lib/helper.php @@ -279,26 +279,6 @@ class Helper { return $path; } - /** - * allow users from other ownCloud instances to mount public links share by this instance - * @return bool - */ - public static function isOutgoingServer2serverShareEnabled() { - $appConfig = \OC::$server->getAppConfig(); - $result = $appConfig->getValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); - return ($result === 'yes') ? true : false; - } - - /** - * allow user to mount public links from onther ownClouds - * @return bool - */ - public static function isIncomingServer2serverShareEnabled() { - $appConfig = \OC::$server->getAppConfig(); - $result = $appConfig->getValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); - return ($result === 'yes') ? true : false; - } - /** * get default share folder * diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php index 113675508f..38605def73 100644 --- a/apps/files_sharing/lib/share/file.php +++ b/apps/files_sharing/lib/share/file.php @@ -1,4 +1,6 @@ * @author Bart Visscher @@ -40,6 +42,18 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { private $path; + /** @var FederatedShareProvider */ + private $federatedShareProvider; + + public function __construct(FederatedShareProvider $federatedShareProvider = null) { + if ($federatedShareProvider) { + $this->federatedShareProvider = $federatedShareProvider; + } else { + $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing'); + $this->federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); + } + } + public function isValidSource($itemSource, $uidOwner) { try { $path = \OC\Files\Filesystem::getPath($itemSource); @@ -173,7 +187,7 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { */ public function isShareTypeAllowed($shareType) { if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { - return \OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled(); + return $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); } return true; diff --git a/apps/files_sharing/tests/controller/sharecontroller.php b/apps/files_sharing/tests/controller/sharecontroller.php index db8c7fe553..df3973099f 100644 --- a/apps/files_sharing/tests/controller/sharecontroller.php +++ b/apps/files_sharing/tests/controller/sharecontroller.php @@ -29,6 +29,7 @@ namespace OCA\Files_Sharing\Controllers; use OC\Files\Filesystem; +use OCA\FederatedFileSharing\FederatedShareProvider; use OCP\Share\Exceptions\ShareNotFound; use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\RedirectResponse; @@ -66,6 +67,8 @@ class ShareControllerTest extends \Test\TestCase { private $shareManager; /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */ private $userManager; + /** @var FederatedShareProvider | \PHPUnit_Framework_MockObject_MockObject */ + private $federatedShareProvider; protected function setUp() { $this->appName = 'files_sharing'; @@ -76,6 +79,12 @@ class ShareControllerTest extends \Test\TestCase { $this->previewManager = $this->getMock('\OCP\IPreview'); $this->config = $this->getMock('\OCP\IConfig'); $this->userManager = $this->getMock('\OCP\IUserManager'); + $this->federatedShareProvider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider') + ->disableOriginalConstructor()->getMock(); + $this->federatedShareProvider->expects($this->any()) + ->method('isOutgoingServer2serverShareEnabled')->willReturn(true); + $this->federatedShareProvider->expects($this->any()) + ->method('isIncomingServer2serverShareEnabled')->willReturn(true); $this->shareController = new \OCA\Files_Sharing\Controllers\ShareController( $this->appName, @@ -88,7 +97,8 @@ class ShareControllerTest extends \Test\TestCase { $this->shareManager, $this->session, $this->previewManager, - $this->getMock('\OCP\Files\IRootFolder') + $this->getMock('\OCP\Files\IRootFolder'), + $this->federatedShareProvider ); diff --git a/apps/files_sharing/tests/server2server.php b/apps/files_sharing/tests/server2server.php index 7714f274c6..1d047916ca 100644 --- a/apps/files_sharing/tests/server2server.php +++ b/apps/files_sharing/tests/server2server.php @@ -44,6 +44,9 @@ class Test_Files_Sharing_S2S_OCS_API extends TestCase { */ private $s2s; + /** @var \OCA\FederatedFileSharing\FederatedShareProvider | PHPUnit_Framework_MockObject_MockObject */ + private $federatedShareProvider; + protected function setUp() { parent::setUp(); @@ -57,10 +60,16 @@ class Test_Files_Sharing_S2S_OCS_API extends TestCase { ->setConstructorArgs([$config, $clientService]) ->getMock(); $httpHelperMock->expects($this->any())->method('post')->with($this->anything())->will($this->returnValue(true)); + $this->federatedShareProvider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider') + ->disableOriginalConstructor()->getMock(); + $this->federatedShareProvider->expects($this->any()) + ->method('isOutgoingServer2serverShareEnabled')->willReturn(true); + $this->federatedShareProvider->expects($this->any()) + ->method('isIncomingServer2serverShareEnabled')->willReturn(true); $this->registerHttpHelper($httpHelperMock); - $this->s2s = new \OCA\Files_Sharing\API\Server2Server(); + $this->s2s = new \OCA\Files_Sharing\API\Server2Server($this->federatedShareProvider); $this->connection = \OC::$server->getDatabaseConnection(); } diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index 0948b56704..0bedfb84fc 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -114,7 +114,8 @@ class ProviderFactory implements IProviderFactory { $tokenHandler, $l, $this->serverContainer->getLogger(), - $this->serverContainer->getLazyRootFolder() + $this->serverContainer->getLazyRootFolder(), + $this->serverContainer->getConfig() ); } diff --git a/ocs/routes.php b/ocs/routes.php index b99aa5c759..af9c3e7413 100644 --- a/ocs/routes.php +++ b/ocs/routes.php @@ -99,7 +99,8 @@ API::register( // Server-to-Server Sharing if (\OC::$server->getAppManager()->isEnabledForUser('files_sharing')) { - $s2s = new \OCA\Files_Sharing\API\Server2Server(); + $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing'); + $s2s = new \OCA\Files_Sharing\API\Server2Server($federatedSharingApp->getFederatedShareProvider()); API::register('post', '/cloud/shares', array($s2s, 'createShare'),