move federated sharing settings to the federatedfilesharing app

This commit is contained in:
Björn Schießle 2016-04-18 18:17:08 +02:00
parent 606b756a94
commit e10105474f
No known key found for this signature in database
GPG Key ID: 2378A753E2BF04F6
31 changed files with 263 additions and 53 deletions

View File

@ -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) { $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'); $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 // this is what is thrown when trying to access a non-existing share
throw new \Sabre\DAV\Exception\NotAuthenticated(); throw new \Sabre\DAV\Exception\NotAuthenticated();
} }

View File

@ -21,7 +21,5 @@
namespace OCA\FederatedFileSharing\AppInfo; namespace OCA\FederatedFileSharing\AppInfo;
use OCP\AppFramework\App; $app = new Application('federatedfilesharing');
$app->registerSettings();
new App('federatedfilesharing');

View File

@ -0,0 +1,88 @@
<?php
/**
* @author Björn Schießle <schiessle@owncloud.com>
*
* @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 <http://www.gnu.org/licenses/>
*
*/
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()
);
}
}

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -25,6 +25,8 @@ namespace OCA\FederatedFileSharing;
use OC\Share20\Share; use OC\Share20\Share;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger; use OCP\ILogger;
use OCP\Share\IShare; use OCP\Share\IShare;
@ -65,6 +67,9 @@ class FederatedShareProvider implements IShareProvider {
/** @var IRootFolder */ /** @var IRootFolder */
private $rootFolder; private $rootFolder;
/** @var IConfig */
private $config;
/** /**
* DefaultShareProvider constructor. * DefaultShareProvider constructor.
* *
@ -75,6 +80,7 @@ class FederatedShareProvider implements IShareProvider {
* @param IL10N $l10n * @param IL10N $l10n
* @param ILogger $logger * @param ILogger $logger
* @param IRootFolder $rootFolder * @param IRootFolder $rootFolder
* @param IConfig $config
*/ */
public function __construct( public function __construct(
IDBConnection $connection, IDBConnection $connection,
@ -83,7 +89,8 @@ class FederatedShareProvider implements IShareProvider {
TokenHandler $tokenHandler, TokenHandler $tokenHandler,
IL10N $l10n, IL10N $l10n,
ILogger $logger, ILogger $logger,
IRootFolder $rootFolder IRootFolder $rootFolder,
IConfig $config
) { ) {
$this->dbConnection = $connection; $this->dbConnection = $connection;
$this->addressHandler = $addressHandler; $this->addressHandler = $addressHandler;
@ -92,6 +99,7 @@ class FederatedShareProvider implements IShareProvider {
$this->l = $l10n; $this->l = $l10n;
$this->logger = $logger; $this->logger = $logger;
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
$this->config = $config;
} }
/** /**
@ -601,4 +609,24 @@ class FederatedShareProvider implements IShareProvider {
// We don't handle groups here // We don't handle groups here
return; 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;
}
} }

View File

@ -20,12 +20,15 @@
* *
*/ */
use OCA\FederatedFileSharing\AppInfo\Application;
\OC_Util::checkAdminUser(); \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 = new OCP\Template('federatedfilesharing', 'settings-admin');
$tmpl->assign('outgoingServer2serverShareEnabled', OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled()); $tmpl->assign('outgoingServer2serverShareEnabled', $federatedShareProvider->isOutgoingServer2serverShareEnabled());
$tmpl->assign('incomingServer2serverShareEnabled', OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled()); $tmpl->assign('incomingServer2serverShareEnabled', $federatedShareProvider->isIncomingServer2serverShareEnabled());
return $tmpl->fetchPage(); return $tmpl->fetchPage();

View File

@ -21,9 +21,14 @@
* *
*/ */
use OCA\FederatedFileSharing\AppInfo\Application;
\OC_Util::checkLoggedIn(); \OC_Util::checkLoggedIn();
$l = \OC::$server->getL10N('files_sharing'); $l = \OC::$server->getL10N('federatedfilesharing');
$app = new Application('federatedfilesharing');
$federatedShareProvider = $app->getFederatedShareProvider();
$isIE8 = false; $isIE8 = false;
preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches); preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
@ -35,8 +40,8 @@ $cloudID = \OC::$server->getUserSession()->getUser()->getCloudId();
$url = 'https://owncloud.org/federation#' . $cloudID; $url = 'https://owncloud.org/federation#' . $cloudID;
$ownCloudLogoPath = \OC::$server->getURLGenerator()->imagePath('core', 'logo-icon.svg'); $ownCloudLogoPath = \OC::$server->getURLGenerator()->imagePath('core', 'logo-icon.svg');
$tmpl = new OCP\Template('files_sharing', 'settings-personal'); $tmpl = new OCP\Template('federatedfilesharing', 'settings-personal');
$tmpl->assign('outgoingServer2serverShareEnabled', \OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled()); $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_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('message_without_URL', $l->t('Share with me through my #ownCloud Federated Cloud ID', [$cloudID]));
$tmpl->assign('owncloud_logo_path', $ownCloudLogoPath); $tmpl->assign('owncloud_logo_path', $ownCloudLogoPath);

View File

@ -1,7 +1,9 @@
<?php <?php
/** @var OC_L10N $l */ /** @var OC_L10N $l */
/** @var array $_ */ /** @var array $_ */
script('federatedfilesharing', 'settings-admin');
?> ?>
<div id="fileSharingSettings"> <div id="fileSharingSettings">
<h3><?php p($l->t('Federated Cloud Sharing'));?></h3> <h3><?php p($l->t('Federated Cloud Sharing'));?></h3>
<a target="_blank" rel="noreferrer" class="icon-info svg" <a target="_blank" rel="noreferrer" class="icon-info svg"

View File

@ -1,11 +1,11 @@
<?php <?php
/** @var OC_L10N $l */ /** @var OC_L10N $l */
/** @var array $_ */ /** @var array $_ */
script('files_sharing', 'settings-personal'); script('federatedfilesharing', 'settings-personal');
style('files_sharing', 'settings-personal'); style('federatedfilesharing', 'settings-personal');
if ($_['showShareIT']) { if ($_['showShareIT']) {
script('files_sharing', '3rdparty/gs-share/gs-share'); script('federatedfilesharing', '3rdparty/gs-share/gs-share');
style('files_sharing', '3rdparty/gs-share/style'); style('federatedfilesharing', '3rdparty/gs-share/style');
} }
?> ?>

View File

@ -26,6 +26,7 @@ use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\FederatedFileSharing\Notifications; use OCA\FederatedFileSharing\Notifications;
use OCA\FederatedFileSharing\TokenHandler; use OCA\FederatedFileSharing\TokenHandler;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger; use OCP\ILogger;
@ -54,6 +55,8 @@ class FederatedShareProviderTest extends TestCase {
protected $logger; protected $logger;
/** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */ /** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */
protected $rootFolder; protected $rootFolder;
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
protected $config;
/** @var IManager */ /** @var IManager */
protected $shareManager; protected $shareManager;
@ -78,6 +81,7 @@ class FederatedShareProviderTest extends TestCase {
})); }));
$this->logger = $this->getMock('OCP\ILogger'); $this->logger = $this->getMock('OCP\ILogger');
$this->rootFolder = $this->getMock('OCP\Files\IRootFolder'); $this->rootFolder = $this->getMock('OCP\Files\IRootFolder');
$this->config = $this->getMock('OCP\IConfig');
$this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l); $this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l);
$this->provider = new FederatedShareProvider( $this->provider = new FederatedShareProvider(
@ -87,7 +91,8 @@ class FederatedShareProviderTest extends TestCase {
$this->tokenHandler, $this->tokenHandler,
$this->l, $this->l,
$this->logger, $this->logger,
$this->rootFolder $this->rootFolder,
$this->config
); );
$this->shareManager = \OC::$server->getShareManager(); $this->shareManager = \OC::$server->getShareManager();
@ -510,4 +515,43 @@ class FederatedShareProviderTest extends TestCase {
$this->assertCount($rowDeleted ? 0 : 1, $data); $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]
];
}
} }

View File

@ -31,8 +31,11 @@ OCP\JSON::checkAppEnabled('files_sharing');
$l = \OC::$server->getL10N('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 // 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')))); \OCP\JSON::error(array('data' => array('message' => $l->t('Server to server sharing is not enabled on this server'))));
exit(); exit();
} }

View File

@ -29,7 +29,10 @@ if (!isset($_GET['t'])) {
exit; 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 \OC_Response::setStatus(404); // 404 not found
exit; exit;
} }

View File

@ -26,11 +26,25 @@
namespace OCA\Files_Sharing\API; namespace OCA\Files_Sharing\API;
use OCA\FederatedFileSharing\DiscoveryManager; use OCA\FederatedFileSharing\DiscoveryManager;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\Files_Sharing\Activity; use OCA\Files_Sharing\Activity;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
class Server2Server { class Server2Server {
/** @var FederatedShareProvider */
private $federatedShareProvider;
/**
* Server2Server constructor.
*
* @param FederatedShareProvider $federatedShareProvider
*/
public function __construct(FederatedShareProvider $federatedShareProvider) {
$this->federatedShareProvider = $federatedShareProvider;
}
/** /**
* create a new share * create a new share
* *
@ -300,9 +314,9 @@ class Server2Server {
$result = \OCP\App::isEnabled('files_sharing'); $result = \OCP\App::isEnabled('files_sharing');
if ($incoming) { if ($incoming) {
$result = $result && \OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled(); $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled();
} else { } else {
$result = $result && \OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled(); $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
} }
return $result; return $result;

View File

@ -44,9 +44,6 @@ $l = \OC::$server->getL10N('files_sharing');
$application = new Application(); $application = new Application();
$application->registerMountProviders(); $application->registerMountProviders();
\OCP\App::registerAdmin('files_sharing', 'settings-admin');
\OCP\App::registerPersonal('files_sharing', 'settings-personal');
\OCA\Files_Sharing\Helper::registerHooks(); \OCA\Files_Sharing\Helper::registerHooks();
\OCP\Share::registerBackend('file', 'OC_Share_Backend_File'); \OCP\Share::registerBackend('file', 'OC_Share_Backend_File');

View File

@ -45,6 +45,7 @@ class Application extends App {
* Controllers * Controllers
*/ */
$container->registerService('ShareController', function (SimpleContainer $c) use ($server) { $container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing');
return new ShareController( return new ShareController(
$c->query('AppName'), $c->query('AppName'),
$c->query('Request'), $c->query('Request'),
@ -56,7 +57,8 @@ class Application extends App {
$server->getShareManager(), $server->getShareManager(),
$server->getSession(), $server->getSession(),
$server->getPreviewManager(), $server->getPreviewManager(),
$server->getRootFolder() $server->getRootFolder(),
$federatedSharingApp->getFederatedShareProvider()
); );
}); });
$container->registerService('ExternalSharesController', function (SimpleContainer $c) { $container->registerService('ExternalSharesController', function (SimpleContainer $c) {

View File

@ -33,6 +33,7 @@ namespace OCA\Files_Sharing\Controllers;
use OC; use OC;
use OC_Files; use OC_Files;
use OC_Util; use OC_Util;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP; use OCP;
use OCP\Template; use OCP\Template;
use OCP\Share; use OCP\Share;
@ -79,6 +80,8 @@ class ShareController extends Controller {
protected $previewManager; protected $previewManager;
/** @var IRootFolder */ /** @var IRootFolder */
protected $rootFolder; protected $rootFolder;
/** @var FederatedShareProvider */
protected $federatedShareProvider;
/** /**
* @param string $appName * @param string $appName
@ -92,6 +95,7 @@ class ShareController extends Controller {
* @param ISession $session * @param ISession $session
* @param IPreview $previewManager * @param IPreview $previewManager
* @param IRootFolder $rootFolder * @param IRootFolder $rootFolder
* @param FederatedShareProvider $federatedShareProvider
*/ */
public function __construct($appName, public function __construct($appName,
IRequest $request, IRequest $request,
@ -103,7 +107,8 @@ class ShareController extends Controller {
\OCP\Share\IManager $shareManager, \OCP\Share\IManager $shareManager,
ISession $session, ISession $session,
IPreview $previewManager, IPreview $previewManager,
IRootFolder $rootFolder) { IRootFolder $rootFolder,
FederatedShareProvider $federatedShareProvider) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->config = $config; $this->config = $config;
@ -115,6 +120,7 @@ class ShareController extends Controller {
$this->session = $session; $this->session = $session;
$this->previewManager = $previewManager; $this->previewManager = $previewManager;
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
$this->federatedShareProvider = $federatedShareProvider;
} }
/** /**
@ -300,7 +306,7 @@ class ShareController extends Controller {
$shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype()); $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype());
$shareTmpl['dirToken'] = $token; $shareTmpl['dirToken'] = $token;
$shareTmpl['sharingToken'] = $token; $shareTmpl['sharingToken'] = $token;
$shareTmpl['server2serversharing'] = Helper::isOutgoingServer2serverShareEnabled(); $shareTmpl['server2serversharing'] = $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
$shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false'; $shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false';
$shareTmpl['dir'] = ''; $shareTmpl['dir'] = '';
$shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize(); $shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize();

View File

@ -279,26 +279,6 @@ class Helper {
return $path; 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 * get default share folder
* *

View File

@ -1,4 +1,6 @@
<?php <?php
use OCA\FederatedFileSharing\FederatedShareProvider;
/** /**
* @author Andreas Fischer <bantu@owncloud.com> * @author Andreas Fischer <bantu@owncloud.com>
* @author Bart Visscher <bartv@thisnet.nl> * @author Bart Visscher <bartv@thisnet.nl>
@ -40,6 +42,18 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
private $path; 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) { public function isValidSource($itemSource, $uidOwner) {
try { try {
$path = \OC\Files\Filesystem::getPath($itemSource); $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) { public function isShareTypeAllowed($shareType) {
if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
return \OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled(); return $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
} }
return true; return true;

View File

@ -29,6 +29,7 @@
namespace OCA\Files_Sharing\Controllers; namespace OCA\Files_Sharing\Controllers;
use OC\Files\Filesystem; use OC\Files\Filesystem;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\Exceptions\ShareNotFound;
use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\RedirectResponse;
@ -66,6 +67,8 @@ class ShareControllerTest extends \Test\TestCase {
private $shareManager; private $shareManager;
/** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */ /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */
private $userManager; private $userManager;
/** @var FederatedShareProvider | \PHPUnit_Framework_MockObject_MockObject */
private $federatedShareProvider;
protected function setUp() { protected function setUp() {
$this->appName = 'files_sharing'; $this->appName = 'files_sharing';
@ -76,6 +79,12 @@ class ShareControllerTest extends \Test\TestCase {
$this->previewManager = $this->getMock('\OCP\IPreview'); $this->previewManager = $this->getMock('\OCP\IPreview');
$this->config = $this->getMock('\OCP\IConfig'); $this->config = $this->getMock('\OCP\IConfig');
$this->userManager = $this->getMock('\OCP\IUserManager'); $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->shareController = new \OCA\Files_Sharing\Controllers\ShareController(
$this->appName, $this->appName,
@ -88,7 +97,8 @@ class ShareControllerTest extends \Test\TestCase {
$this->shareManager, $this->shareManager,
$this->session, $this->session,
$this->previewManager, $this->previewManager,
$this->getMock('\OCP\Files\IRootFolder') $this->getMock('\OCP\Files\IRootFolder'),
$this->federatedShareProvider
); );

View File

@ -44,6 +44,9 @@ class Test_Files_Sharing_S2S_OCS_API extends TestCase {
*/ */
private $s2s; private $s2s;
/** @var \OCA\FederatedFileSharing\FederatedShareProvider | PHPUnit_Framework_MockObject_MockObject */
private $federatedShareProvider;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
@ -57,10 +60,16 @@ class Test_Files_Sharing_S2S_OCS_API extends TestCase {
->setConstructorArgs([$config, $clientService]) ->setConstructorArgs([$config, $clientService])
->getMock(); ->getMock();
$httpHelperMock->expects($this->any())->method('post')->with($this->anything())->will($this->returnValue(true)); $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->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(); $this->connection = \OC::$server->getDatabaseConnection();
} }

View File

@ -114,7 +114,8 @@ class ProviderFactory implements IProviderFactory {
$tokenHandler, $tokenHandler,
$l, $l,
$this->serverContainer->getLogger(), $this->serverContainer->getLogger(),
$this->serverContainer->getLazyRootFolder() $this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getConfig()
); );
} }

View File

@ -99,7 +99,8 @@ API::register(
// Server-to-Server Sharing // Server-to-Server Sharing
if (\OC::$server->getAppManager()->isEnabledForUser('files_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', API::register('post',
'/cloud/shares', '/cloud/shares',
array($s2s, 'createShare'), array($s2s, 'createShare'),