aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2016-04-18 18:17:08 +0200
committerBjörn Schießle <schiessle@owncloud.com>2016-04-22 14:55:40 +0200
commite10105474fbef8940fdfa96d5e2bf2f09b1f0649 (patch)
tree1881e059a3408a2d4e8096e31719ba989f7dfab1
parent606b756a94643eaae87e18b39f6c75e6d18fec7e (diff)
downloadnextcloud-server-e10105474fbef8940fdfa96d5e2bf2f09b1f0649.tar.gz
nextcloud-server-e10105474fbef8940fdfa96d5e2bf2f09b1f0649.zip
move federated sharing settings to the federatedfilesharing app
-rw-r--r--apps/dav/appinfo/v1/publicwebdav.php4
-rw-r--r--apps/federatedfilesharing/appinfo/app.php6
-rw-r--r--apps/federatedfilesharing/appinfo/application.php88
-rw-r--r--apps/federatedfilesharing/css/3rdparty/gs-share/style.css (renamed from apps/files_sharing/css/3rdparty/gs-share/style.css)0
-rw-r--r--apps/federatedfilesharing/css/settings-personal.css (renamed from apps/files_sharing/css/settings-personal.css)0
-rw-r--r--apps/federatedfilesharing/img/social-diaspora.svg (renamed from apps/files_sharing/img/social-diaspora.svg)0
-rw-r--r--apps/federatedfilesharing/img/social-facebook.svg (renamed from apps/files_sharing/img/social-facebook.svg)0
-rw-r--r--apps/federatedfilesharing/img/social-gnu.svg (renamed from apps/files_sharing/img/social-gnu.svg)0
-rw-r--r--apps/federatedfilesharing/img/social-googleplus.svg (renamed from apps/files_sharing/img/social-googleplus.svg)0
-rw-r--r--apps/federatedfilesharing/img/social-twitter.svg (renamed from apps/files_sharing/img/social-twitter.svg)0
-rw-r--r--apps/federatedfilesharing/js/3rdparty/gs-share/gs-share.js (renamed from apps/files_sharing/js/3rdparty/gs-share/gs-share.js)0
-rw-r--r--apps/federatedfilesharing/js/settings-admin.js (renamed from apps/files_sharing/js/settings-admin.js)0
-rw-r--r--apps/federatedfilesharing/js/settings-personal.js (renamed from apps/files_sharing/js/settings-personal.js)0
-rw-r--r--apps/federatedfilesharing/lib/federatedshareprovider.php30
-rw-r--r--apps/federatedfilesharing/settings-admin.php (renamed from apps/files_sharing/settings-admin.php)11
-rw-r--r--apps/federatedfilesharing/settings-personal.php (renamed from apps/files_sharing/settings-personal.php)11
-rw-r--r--apps/federatedfilesharing/templates/settings-admin.php (renamed from apps/files_sharing/templates/settings-admin.php)2
-rw-r--r--apps/federatedfilesharing/templates/settings-personal.php (renamed from apps/files_sharing/templates/settings-personal.php)8
-rw-r--r--apps/federatedfilesharing/tests/federatedshareprovidertest.php46
-rw-r--r--apps/files_sharing/ajax/external.php5
-rw-r--r--apps/files_sharing/ajax/shareinfo.php5
-rw-r--r--apps/files_sharing/api/server2server.php18
-rw-r--r--apps/files_sharing/appinfo/app.php3
-rw-r--r--apps/files_sharing/appinfo/application.php4
-rw-r--r--apps/files_sharing/lib/controllers/sharecontroller.php10
-rw-r--r--apps/files_sharing/lib/helper.php20
-rw-r--r--apps/files_sharing/lib/share/file.php16
-rw-r--r--apps/files_sharing/tests/controller/sharecontroller.php12
-rw-r--r--apps/files_sharing/tests/server2server.php11
-rw-r--r--lib/private/Share20/ProviderFactory.php3
-rw-r--r--ocs/routes.php3
31 files changed, 263 insertions, 53 deletions
diff --git a/apps/dav/appinfo/v1/publicwebdav.php b/apps/dav/appinfo/v1/publicwebdav.php
index 43fedb19415..39c169728b9 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 804ab69759c..23af62037a3 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 00000000000..5a213aec8e2
--- /dev/null
+++ b/apps/federatedfilesharing/appinfo/application.php
@@ -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()
+ );
+ }
+
+}
diff --git a/apps/files_sharing/css/3rdparty/gs-share/style.css b/apps/federatedfilesharing/css/3rdparty/gs-share/style.css
index c699ddb3db5..c699ddb3db5 100644
--- a/apps/files_sharing/css/3rdparty/gs-share/style.css
+++ b/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
index f53365c9371..f53365c9371 100644
--- a/apps/files_sharing/css/settings-personal.css
+++ b/apps/federatedfilesharing/css/settings-personal.css
diff --git a/apps/files_sharing/img/social-diaspora.svg b/apps/federatedfilesharing/img/social-diaspora.svg
index 1d5131129a9..1d5131129a9 100644
--- a/apps/files_sharing/img/social-diaspora.svg
+++ b/apps/federatedfilesharing/img/social-diaspora.svg
diff --git a/apps/files_sharing/img/social-facebook.svg b/apps/federatedfilesharing/img/social-facebook.svg
index aad02bc3853..aad02bc3853 100644
--- a/apps/files_sharing/img/social-facebook.svg
+++ b/apps/federatedfilesharing/img/social-facebook.svg
diff --git a/apps/files_sharing/img/social-gnu.svg b/apps/federatedfilesharing/img/social-gnu.svg
index 24556aaa024..24556aaa024 100644
--- a/apps/files_sharing/img/social-gnu.svg
+++ b/apps/federatedfilesharing/img/social-gnu.svg
diff --git a/apps/files_sharing/img/social-googleplus.svg b/apps/federatedfilesharing/img/social-googleplus.svg
index 123273f2d38..123273f2d38 100644
--- a/apps/files_sharing/img/social-googleplus.svg
+++ b/apps/federatedfilesharing/img/social-googleplus.svg
diff --git a/apps/files_sharing/img/social-twitter.svg b/apps/federatedfilesharing/img/social-twitter.svg
index 00ce390de6b..00ce390de6b 100644
--- a/apps/files_sharing/img/social-twitter.svg
+++ b/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
index fd4442708a4..fd4442708a4 100644
--- a/apps/files_sharing/js/3rdparty/gs-share/gs-share.js
+++ b/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
index 95578bff548..95578bff548 100644
--- a/apps/files_sharing/js/settings-admin.js
+++ b/apps/federatedfilesharing/js/settings-admin.js
diff --git a/apps/files_sharing/js/settings-personal.js b/apps/federatedfilesharing/js/settings-personal.js
index 14a9b7bbfa7..14a9b7bbfa7 100644
--- a/apps/files_sharing/js/settings-personal.js
+++ b/apps/federatedfilesharing/js/settings-personal.js
diff --git a/apps/federatedfilesharing/lib/federatedshareprovider.php b/apps/federatedfilesharing/lib/federatedshareprovider.php
index 78b0b664204..d014a6219a3 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
index b2a305ebcdb..9dd21281fda 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
index 982a8b05c15..385d3971146 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
index 64b6b8e72a3..5d2eb04c170 100644
--- a/apps/files_sharing/templates/settings-admin.php
+++ b/apps/federatedfilesharing/templates/settings-admin.php
@@ -1,7 +1,9 @@
<?php
/** @var OC_L10N $l */
/** @var array $_ */
+script('federatedfilesharing', 'settings-admin');
?>
+
<div id="fileSharingSettings">
<h3><?php p($l->t('Federated Cloud Sharing'));?></h3>
<a target="_blank" rel="noreferrer" class="icon-info svg"
diff --git a/apps/files_sharing/templates/settings-personal.php b/apps/federatedfilesharing/templates/settings-personal.php
index ea9aae038a7..87b524af3e8 100644
--- a/apps/files_sharing/templates/settings-personal.php
+++ b/apps/federatedfilesharing/templates/settings-personal.php
@@ -1,11 +1,11 @@
<?php
/** @var OC_L10N $l */
/** @var array $_ */
-script('files_sharing', 'settings-personal');
-style('files_sharing', 'settings-personal');
+script('federatedfilesharing', 'settings-personal');
+style('federatedfilesharing', 'settings-personal');
if ($_['showShareIT']) {
- script('files_sharing', '3rdparty/gs-share/gs-share');
- style('files_sharing', '3rdparty/gs-share/style');
+ script('federatedfilesharing', '3rdparty/gs-share/gs-share');
+ style('federatedfilesharing', '3rdparty/gs-share/style');
}
?>
diff --git a/apps/federatedfilesharing/tests/federatedshareprovidertest.php b/apps/federatedfilesharing/tests/federatedshareprovidertest.php
index 92e9f10c3cd..1fbae90a46f 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 76f9d5d7668..78e648618be 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 47bc061c136..d7f756b0039 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 11b24d9148b..034ec5105e4 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 29202c15b22..e0cbfd7f5ba 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 5233b343830..b17e213e2e2 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 ea024b6016a..72294f6b26f 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 e857974ae74..c09694e9888 100644
--- a/apps/files_sharing/lib/helper.php
+++ b/apps/files_sharing/lib/helper.php
@@ -280,26 +280,6 @@ class Helper {
}
/**
- * 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
*
* @return string
diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php
index 113675508fb..38605def73a 100644
--- a/apps/files_sharing/lib/share/file.php
+++ b/apps/files_sharing/lib/share/file.php
@@ -1,4 +1,6 @@
<?php
+use OCA\FederatedFileSharing\FederatedShareProvider;
+
/**
* @author Andreas Fischer <bantu@owncloud.com>
* @author Bart Visscher <bartv@thisnet.nl>
@@ -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 db8c7fe553c..df3973099fb 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 7714f274c6d..1d047916ca9 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 0948b567046..0bedfb84fc7 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 b99aa5c7597..af9c3e74137 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'),