diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2017-05-24 09:07:58 +0200 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2017-05-29 18:19:28 +0200 |
commit | 7c2d473d7686f4824d3b7f05238d262e26d5efa2 (patch) | |
tree | f4aae21880e293a2ded78e63ee3300b61b5f487f /apps/federatedfilesharing | |
parent | 4be17dff0f9846d32f9740e7d7766bdbc1e98b51 (diff) | |
download | nextcloud-server-7c2d473d7686f4824d3b7f05238d262e26d5efa2.tar.gz nextcloud-server-7c2d473d7686f4824d3b7f05238d262e26d5efa2.zip |
add new config switched for the global scale architecture
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'apps/federatedfilesharing')
7 files changed, 116 insertions, 25 deletions
diff --git a/apps/federatedfilesharing/lib/AppInfo/Application.php b/apps/federatedfilesharing/lib/AppInfo/Application.php index 9d8464e37d5..346d3c4e292 100644 --- a/apps/federatedfilesharing/lib/AppInfo/Application.php +++ b/apps/federatedfilesharing/lib/AppInfo/Application.php @@ -30,6 +30,7 @@ use OCA\FederatedFileSharing\Controller\RequestHandlerController; use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\FederatedFileSharing\Notifications; use OCP\AppFramework\App; +use OCP\GlobalScale\IConfig; class Application extends App { @@ -91,6 +92,7 @@ class Application extends App { * initialize federated share provider */ protected function initFederatedShareProvider() { + $c = $this->getContainer(); $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( \OC::$server->getURLGenerator(), \OC::$server->getL10N('federatedfilesharing'), @@ -116,7 +118,8 @@ class Application extends App { \OC::$server->getLazyRootFolder(), \OC::$server->getConfig(), \OC::$server->getUserManager(), - \OC::$server->getCloudIdManager() + \OC::$server->getCloudIdManager(), + $c->query(IConfig::class) ); } diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php index 34e02391e05..60a54c6ca3c 100644 --- a/apps/federatedfilesharing/lib/FederatedShareProvider.php +++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php @@ -85,6 +85,9 @@ class FederatedShareProvider implements IShareProvider { /** @var ICloudIdManager */ private $cloudIdManager; + /** @var \OCP\GlobalScale\IConfig */ + private $gsConfig; + /** * DefaultShareProvider constructor. * @@ -98,6 +101,7 @@ class FederatedShareProvider implements IShareProvider { * @param IConfig $config * @param IUserManager $userManager * @param ICloudIdManager $cloudIdManager + * @param \OCP\GlobalScale\IConfig $globalScaleConfig */ public function __construct( IDBConnection $connection, @@ -109,7 +113,8 @@ class FederatedShareProvider implements IShareProvider { IRootFolder $rootFolder, IConfig $config, IUserManager $userManager, - ICloudIdManager $cloudIdManager + ICloudIdManager $cloudIdManager, + \OCP\GlobalScale\IConfig $globalScaleConfig ) { $this->dbConnection = $connection; $this->addressHandler = $addressHandler; @@ -121,6 +126,7 @@ class FederatedShareProvider implements IShareProvider { $this->config = $config; $this->userManager = $userManager; $this->cloudIdManager = $cloudIdManager; + $this->gsConfig = $globalScaleConfig; } /** @@ -941,6 +947,9 @@ class FederatedShareProvider implements IShareProvider { * @return bool */ public function isOutgoingServer2serverShareEnabled() { + if ($this->gsConfig->onlyInternalFederation()) { + return false; + } $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); return ($result === 'yes'); } @@ -951,6 +960,9 @@ class FederatedShareProvider implements IShareProvider { * @return bool */ public function isIncomingServer2serverShareEnabled() { + if ($this->gsConfig->onlyInternalFederation()) { + return false; + } $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); return ($result === 'yes'); } @@ -961,6 +973,10 @@ class FederatedShareProvider implements IShareProvider { * @return bool */ public function isLookupServerQueriesEnabled() { + // in a global scale setup we should always query the lookup server + if ($this->gsConfig->isGlobalScaleEnabled()) { + return true; + } $result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no'); return ($result === 'yes'); } @@ -972,6 +988,10 @@ class FederatedShareProvider implements IShareProvider { * @return bool */ public function isLookupServerUploadEnabled() { + // in a global scale setup the admin is responsible to keep the lookup server up-to-date + if ($this->gsConfig->isGlobalScaleEnabled()) { + return false; + } $result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes'); return ($result === 'yes'); } diff --git a/apps/federatedfilesharing/lib/Settings/Admin.php b/apps/federatedfilesharing/lib/Settings/Admin.php index baac4b1086f..47470fd5841 100644 --- a/apps/federatedfilesharing/lib/Settings/Admin.php +++ b/apps/federatedfilesharing/lib/Settings/Admin.php @@ -25,6 +25,7 @@ namespace OCA\FederatedFileSharing\Settings; use OCA\FederatedFileSharing\FederatedShareProvider; use OCP\AppFramework\Http\TemplateResponse; +use OCP\GlobalScale\IConfig; use OCP\Settings\ISettings; class Admin implements ISettings { @@ -32,15 +33,27 @@ class Admin implements ISettings { /** @var FederatedShareProvider */ private $fedShareProvider; - public function __construct(FederatedShareProvider $fedShareProvider) { + /** @var IConfig */ + private $gsConfig; + + /** + * Admin constructor. + * + * @param FederatedShareProvider $fedShareProvider + * @param IConfig $globalScaleConfig + */ + public function __construct(FederatedShareProvider $fedShareProvider, IConfig $globalScaleConfig) { $this->fedShareProvider = $fedShareProvider; + $this->gsConfig = $globalScaleConfig; } /** * @return TemplateResponse */ public function getForm() { + $parameters = [ + 'internalOnly' => $this->gsConfig->onlyInternalFederation(), 'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(), 'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(), 'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(), diff --git a/apps/federatedfilesharing/settings-personal.php b/apps/federatedfilesharing/settings-personal.php index d70f4e491a5..cd22cc17089 100644 --- a/apps/federatedfilesharing/settings-personal.php +++ b/apps/federatedfilesharing/settings-personal.php @@ -53,7 +53,7 @@ if(\OC::$server->getAppManager()->isEnabledForUser("theming")) { $textColor = "#000000"; } } catch (OCP\AppFramework\QueryException $e) { - + } } diff --git a/apps/federatedfilesharing/templates/settings-admin.php b/apps/federatedfilesharing/templates/settings-admin.php index ff5cb0084e5..e106f1dc4e7 100644 --- a/apps/federatedfilesharing/templates/settings-admin.php +++ b/apps/federatedfilesharing/templates/settings-admin.php @@ -4,6 +4,8 @@ script('federatedfilesharing', 'settings-admin'); ?> +<?php if($_['internalOnly'] === false): ?> + <div id="fileSharingSettings" class="followupsection"> <h3><?php p($l->t('Federated Cloud Sharing'));?></h3> <a target="_blank" rel="noreferrer" class="icon-info svg" @@ -42,3 +44,5 @@ script('federatedfilesharing', 'settings-admin'); </p> </div> + +<?php endif; ?> diff --git a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php index e01e02c83ba..3ecd8162cad 100644 --- a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php +++ b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php @@ -65,6 +65,8 @@ class FederatedShareProviderTest extends \Test\TestCase { protected $config; /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */ protected $userManager; + /** @var \OCP\GlobalScale\IConfig|\PHPUnit_Framework_MockObject_MockObject */ + protected $gsConfig; /** @var IManager */ protected $shareManager; @@ -96,11 +98,11 @@ class FederatedShareProviderTest extends \Test\TestCase { $this->userManager = $this->getMockBuilder('OCP\IUserManager')->getMock(); //$this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l); $this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')->disableOriginalConstructor()->getMock(); + $this->cloudIdManager = new CloudIdManager(); + $this->gsConfig = $this->createMock(\OCP\GlobalScale\IConfig::class); $this->userManager->expects($this->any())->method('userExists')->willReturn(true); - $this->cloudIdManager = new CloudIdManager(); - $this->provider = new FederatedShareProvider( $this->connection, $this->addressHandler, @@ -111,7 +113,8 @@ class FederatedShareProviderTest extends \Test\TestCase { $this->rootFolder, $this->config, $this->userManager, - $this->cloudIdManager + $this->cloudIdManager, + $this->gsConfig ); $this->shareManager = \OC::$server->getShareManager(); @@ -409,7 +412,8 @@ class FederatedShareProviderTest extends \Test\TestCase { $this->rootFolder, $this->config, $this->userManager, - $this->cloudIdManager + $this->cloudIdManager, + $this->gsConfig ] )->setMethods(['sendPermissionUpdate'])->getMock(); @@ -674,13 +678,15 @@ class FederatedShareProviderTest extends \Test\TestCase { } /** - * @dataProvider dataTestFederatedSharingSettings + * @dataProvider dataTestIsOutgoingServer2serverShareEnabled * * @param string $isEnabled * @param bool $expected */ - public function testIsOutgoingServer2serverShareEnabled($isEnabled, $expected) { - $this->config->expects($this->once())->method('getAppValue') + public function testIsOutgoingServer2serverShareEnabled($internalOnly, $isEnabled, $expected) { + $this->gsConfig->expects($this->once())->method('onlyInternalFederation') + ->willReturn($internalOnly); + $this->config->expects($this->any())->method('getAppValue') ->with('files_sharing', 'outgoing_server2server_share_enabled', 'yes') ->willReturn($isEnabled); @@ -689,14 +695,25 @@ class FederatedShareProviderTest extends \Test\TestCase { ); } + public function dataTestIsOutgoingServer2serverShareEnabled() { + return [ + [false, 'yes', true], + [false, 'no', false], + [true, 'yes', false], + [true, 'no', false], + ]; + } + /** - * @dataProvider dataTestFederatedSharingSettings + * @dataProvider dataTestIsIncomingServer2serverShareEnabled * * @param string $isEnabled * @param bool $expected */ - public function testIsIncomingServer2serverShareEnabled($isEnabled, $expected) { - $this->config->expects($this->once())->method('getAppValue') + public function testIsIncomingServer2serverShareEnabled($onlyInternal, $isEnabled, $expected) { + $this->gsConfig->expects($this->once())->method('onlyInternalFederation') + ->willReturn($onlyInternal); + $this->config->expects($this->any())->method('getAppValue') ->with('files_sharing', 'incoming_server2server_share_enabled', 'yes') ->willReturn($isEnabled); @@ -705,14 +722,25 @@ class FederatedShareProviderTest extends \Test\TestCase { ); } + public function dataTestIsIncomingServer2serverShareEnabled() { + return [ + [false, 'yes', true], + [false, 'no', false], + [true, 'yes', false], + [true, 'no', false], + ]; + } + /** - * @dataProvider dataTestFederatedSharingSettings + * @dataProvider dataTestIsLookupServerQueriesEnabled * * @param string $isEnabled * @param bool $expected */ - public function testIsLookupServerQueriesEnabled($isEnabled, $expected) { - $this->config->expects($this->once())->method('getAppValue') + public function testIsLookupServerQueriesEnabled($gsEnabled, $isEnabled, $expected) { + $this->gsConfig->expects($this->once())->method('isGlobalScaleEnabled') + ->willReturn($gsEnabled); + $this->config->expects($this->any())->method('getAppValue') ->with('files_sharing', 'lookupServerEnabled', 'no') ->willReturn($isEnabled); @@ -721,14 +749,26 @@ class FederatedShareProviderTest extends \Test\TestCase { ); } + + public function dataTestIsLookupServerQueriesEnabled() { + return [ + [false, 'yes', true], + [false, 'no', false], + [true, 'yes', true], + [true, 'no', true], + ]; + } + /** - * @dataProvider dataTestFederatedSharingSettings + * @dataProvider dataTestIsLookupServerUploadEnabled * * @param string $isEnabled * @param bool $expected */ - public function testIsLookupServerUploadEnabled($isEnabled, $expected) { - $this->config->expects($this->once())->method('getAppValue') + public function testIsLookupServerUploadEnabled($gsEnabled, $isEnabled, $expected) { + $this->gsConfig->expects($this->once())->method('isGlobalScaleEnabled') + ->willReturn($gsEnabled); + $this->config->expects($this->any())->method('getAppValue') ->with('files_sharing', 'lookupServerUploadEnabled', 'yes') ->willReturn($isEnabled); @@ -737,10 +777,12 @@ class FederatedShareProviderTest extends \Test\TestCase { ); } - public function dataTestFederatedSharingSettings() { + public function dataTestIsLookupServerUploadEnabled() { return [ - ['yes', true], - ['no', false] + [false, 'yes', true], + [false, 'no', false], + [true, 'yes', false], + [true, 'no', false], ]; } diff --git a/apps/federatedfilesharing/tests/Settings/AdminTest.php b/apps/federatedfilesharing/tests/Settings/AdminTest.php index 9eae6317bf7..ce47ffb2385 100644 --- a/apps/federatedfilesharing/tests/Settings/AdminTest.php +++ b/apps/federatedfilesharing/tests/Settings/AdminTest.php @@ -25,6 +25,7 @@ namespace OCA\FederatedFileSharing\Tests\Settings; use OCA\FederatedFileSharing\Settings\Admin; use OCP\AppFramework\Http\TemplateResponse; +use OCP\GlobalScale\IConfig; use Test\TestCase; class AdminTest extends TestCase { @@ -32,12 +33,17 @@ class AdminTest extends TestCase { private $admin; /** @var \OCA\FederatedFileSharing\FederatedShareProvider */ private $federatedShareProvider; + /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ + private $gsConfig; public function setUp() { parent::setUp(); - $this->federatedShareProvider = $this->getMockBuilder('\OCA\FederatedFileSharing\FederatedShareProvider')->disableOriginalConstructor()->getMock(); + $this->federatedShareProvider = $this->getMockBuilder('\OCA\FederatedFileSharing\FederatedShareProvider') + ->disableOriginalConstructor()->getMock(); + $this->gsConfig = $this->getMock(IConfig::class); $this->admin = new Admin( - $this->federatedShareProvider + $this->federatedShareProvider, + $this->gsConfig ); } @@ -73,8 +79,11 @@ class AdminTest extends TestCase { ->expects($this->once()) ->method('isLookupServerUploadEnabled') ->willReturn($state); + $this->gsConfig->expects($this->once())->method('onlyInternalFederation') + ->willReturn($state); $params = [ + 'internalOnly' => $state, 'outgoingServer2serverShareEnabled' => $state, 'incomingServer2serverShareEnabled' => $state, 'lookupServerEnabled' => $state, |