Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move federated sharing settings to the federatedfilesharing app #24073

Merged
merged 1 commit into from
Apr 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/dav/appinfo/v1/publicwebdav.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@

$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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throws an exception when the app is not enabled, because autoloading from the path is not allowed...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but at the moment the app is always enabled. I also want to move the settings 1:1 with as few changes as possible. Maybe in a second step the shareManager should have a "getShareProvider($shareType)" method which we could query instead of the share provider directly. cc @rullzer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmmm lets think about that... because in general I think the abstraction of the share manager is pretty nice.. But I see the use case

$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();
}
Expand Down
6 changes: 2 additions & 4 deletions apps/federatedfilesharing/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@

namespace OCA\FederatedFileSharing\AppInfo;

use OCP\AppFramework\App;

new App('federatedfilesharing');

$app = new Application('federatedfilesharing');
$app->registerSettings();
88 changes: 88 additions & 0 deletions apps/federatedfilesharing/appinfo/application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* @author Björn Schießle <[email protected]>
*
* @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()
);
}

}
30 changes: 29 additions & 1 deletion apps/federatedfilesharing/lib/federatedshareprovider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

use OC\Share20\Share;
use OCP\Files\IRootFolder;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\Share\IShare;
Expand Down Expand Up @@ -65,6 +67,9 @@ class FederatedShareProvider implements IShareProvider {
/** @var IRootFolder */
private $rootFolder;

/** @var IConfig */
private $config;

/**
* DefaultShareProvider constructor.
*
Expand All @@ -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,
Expand All @@ -83,7 +89,8 @@ public function __construct(
TokenHandler $tokenHandler,
IL10N $l10n,
ILogger $logger,
IRootFolder $rootFolder
IRootFolder $rootFolder,
IConfig $config
) {
$this->dbConnection = $connection;
$this->addressHandler = $addressHandler;
Expand All @@ -92,6 +99,7 @@ public function __construct(
$this->l = $l10n;
$this->logger = $logger;
$this->rootFolder = $rootFolder;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -601,4 +609,24 @@ public function userDeletedFromGroup($uid, $gid) {
// 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -35,8 +40,8 @@
$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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
}
?>

Expand Down
46 changes: 45 additions & 1 deletion apps/federatedfilesharing/tests/federatedshareprovidertest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCA\FederatedFileSharing\Notifications;
use OCA\FederatedFileSharing\TokenHandler;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\ILogger;
Expand Down Expand Up @@ -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;
Expand All @@ -78,6 +81,7 @@ public function setUp() {
}));
$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(
Expand All @@ -87,7 +91,8 @@ public function setUp() {
$this->tokenHandler,
$this->l,
$this->logger,
$this->rootFolder
$this->rootFolder,
$this->config
);

$this->shareManager = \OC::$server->getShareManager();
Expand Down Expand Up @@ -510,4 +515,43 @@ public function testDeleteUser($owner, $initiator, $recipient, $deletedUser, $ro

$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]
];
}
}
5 changes: 4 additions & 1 deletion apps/files_sharing/ajax/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@

$l = \OC::$server->getL10N('files_sharing');

$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

$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();
}
Expand Down
5 changes: 4 additions & 1 deletion apps/files_sharing/ajax/shareinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
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;
}
Expand Down
18 changes: 16 additions & 2 deletions apps/files_sharing/api/server2server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -300,9 +314,9 @@ private function isS2SEnabled($incoming = false) {
$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;
Expand Down
Loading