Merge pull request #5084 from nextcloud/useful-gs-settings
add new config switched for the global scale architecture
This commit is contained in:
commit
74fccf20c8
|
@ -30,6 +30,7 @@ use OCA\FederatedFileSharing\Controller\RequestHandlerController;
|
||||||
use OCA\FederatedFileSharing\FederatedShareProvider;
|
use OCA\FederatedFileSharing\FederatedShareProvider;
|
||||||
use OCA\FederatedFileSharing\Notifications;
|
use OCA\FederatedFileSharing\Notifications;
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
|
use OCP\GlobalScale\IConfig;
|
||||||
|
|
||||||
class Application extends App {
|
class Application extends App {
|
||||||
|
|
||||||
|
@ -91,6 +92,7 @@ class Application extends App {
|
||||||
* initialize federated share provider
|
* initialize federated share provider
|
||||||
*/
|
*/
|
||||||
protected function initFederatedShareProvider() {
|
protected function initFederatedShareProvider() {
|
||||||
|
$c = $this->getContainer();
|
||||||
$addressHandler = new \OCA\FederatedFileSharing\AddressHandler(
|
$addressHandler = new \OCA\FederatedFileSharing\AddressHandler(
|
||||||
\OC::$server->getURLGenerator(),
|
\OC::$server->getURLGenerator(),
|
||||||
\OC::$server->getL10N('federatedfilesharing'),
|
\OC::$server->getL10N('federatedfilesharing'),
|
||||||
|
@ -116,7 +118,8 @@ class Application extends App {
|
||||||
\OC::$server->getLazyRootFolder(),
|
\OC::$server->getLazyRootFolder(),
|
||||||
\OC::$server->getConfig(),
|
\OC::$server->getConfig(),
|
||||||
\OC::$server->getUserManager(),
|
\OC::$server->getUserManager(),
|
||||||
\OC::$server->getCloudIdManager()
|
\OC::$server->getCloudIdManager(),
|
||||||
|
$c->query(IConfig::class)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,9 @@ class FederatedShareProvider implements IShareProvider {
|
||||||
/** @var ICloudIdManager */
|
/** @var ICloudIdManager */
|
||||||
private $cloudIdManager;
|
private $cloudIdManager;
|
||||||
|
|
||||||
|
/** @var \OCP\GlobalScale\IConfig */
|
||||||
|
private $gsConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DefaultShareProvider constructor.
|
* DefaultShareProvider constructor.
|
||||||
*
|
*
|
||||||
|
@ -98,6 +101,7 @@ class FederatedShareProvider implements IShareProvider {
|
||||||
* @param IConfig $config
|
* @param IConfig $config
|
||||||
* @param IUserManager $userManager
|
* @param IUserManager $userManager
|
||||||
* @param ICloudIdManager $cloudIdManager
|
* @param ICloudIdManager $cloudIdManager
|
||||||
|
* @param \OCP\GlobalScale\IConfig $globalScaleConfig
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IDBConnection $connection,
|
IDBConnection $connection,
|
||||||
|
@ -109,7 +113,8 @@ class FederatedShareProvider implements IShareProvider {
|
||||||
IRootFolder $rootFolder,
|
IRootFolder $rootFolder,
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
IUserManager $userManager,
|
IUserManager $userManager,
|
||||||
ICloudIdManager $cloudIdManager
|
ICloudIdManager $cloudIdManager,
|
||||||
|
\OCP\GlobalScale\IConfig $globalScaleConfig
|
||||||
) {
|
) {
|
||||||
$this->dbConnection = $connection;
|
$this->dbConnection = $connection;
|
||||||
$this->addressHandler = $addressHandler;
|
$this->addressHandler = $addressHandler;
|
||||||
|
@ -121,6 +126,7 @@ class FederatedShareProvider implements IShareProvider {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->userManager = $userManager;
|
$this->userManager = $userManager;
|
||||||
$this->cloudIdManager = $cloudIdManager;
|
$this->cloudIdManager = $cloudIdManager;
|
||||||
|
$this->gsConfig = $globalScaleConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -941,6 +947,9 @@ class FederatedShareProvider implements IShareProvider {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isOutgoingServer2serverShareEnabled() {
|
public function isOutgoingServer2serverShareEnabled() {
|
||||||
|
if ($this->gsConfig->onlyInternalFederation()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes');
|
$result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes');
|
||||||
return ($result === 'yes');
|
return ($result === 'yes');
|
||||||
}
|
}
|
||||||
|
@ -951,6 +960,9 @@ class FederatedShareProvider implements IShareProvider {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isIncomingServer2serverShareEnabled() {
|
public function isIncomingServer2serverShareEnabled() {
|
||||||
|
if ($this->gsConfig->onlyInternalFederation()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes');
|
$result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes');
|
||||||
return ($result === 'yes');
|
return ($result === 'yes');
|
||||||
}
|
}
|
||||||
|
@ -961,6 +973,10 @@ class FederatedShareProvider implements IShareProvider {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isLookupServerQueriesEnabled() {
|
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');
|
$result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no');
|
||||||
return ($result === 'yes');
|
return ($result === 'yes');
|
||||||
}
|
}
|
||||||
|
@ -972,6 +988,10 @@ class FederatedShareProvider implements IShareProvider {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isLookupServerUploadEnabled() {
|
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');
|
$result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes');
|
||||||
return ($result === 'yes');
|
return ($result === 'yes');
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace OCA\FederatedFileSharing\Settings;
|
||||||
|
|
||||||
use OCA\FederatedFileSharing\FederatedShareProvider;
|
use OCA\FederatedFileSharing\FederatedShareProvider;
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\GlobalScale\IConfig;
|
||||||
use OCP\Settings\ISettings;
|
use OCP\Settings\ISettings;
|
||||||
|
|
||||||
class Admin implements ISettings {
|
class Admin implements ISettings {
|
||||||
|
@ -32,15 +33,27 @@ class Admin implements ISettings {
|
||||||
/** @var FederatedShareProvider */
|
/** @var FederatedShareProvider */
|
||||||
private $fedShareProvider;
|
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->fedShareProvider = $fedShareProvider;
|
||||||
|
$this->gsConfig = $globalScaleConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return TemplateResponse
|
* @return TemplateResponse
|
||||||
*/
|
*/
|
||||||
public function getForm() {
|
public function getForm() {
|
||||||
|
|
||||||
$parameters = [
|
$parameters = [
|
||||||
|
'internalOnly' => $this->gsConfig->onlyInternalFederation(),
|
||||||
'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(),
|
'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(),
|
||||||
'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(),
|
'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(),
|
||||||
'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(),
|
'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(),
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
script('federatedfilesharing', 'settings-admin');
|
script('federatedfilesharing', 'settings-admin');
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
<?php if($_['internalOnly'] === false): ?>
|
||||||
|
|
||||||
<div id="fileSharingSettings" class="followupsection">
|
<div id="fileSharingSettings" class="followupsection">
|
||||||
<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"
|
||||||
|
@ -42,3 +44,5 @@ script('federatedfilesharing', 'settings-admin');
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
|
|
|
@ -65,6 +65,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
|
||||||
protected $config;
|
protected $config;
|
||||||
/** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */
|
/** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $userManager;
|
protected $userManager;
|
||||||
|
/** @var \OCP\GlobalScale\IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
protected $gsConfig;
|
||||||
|
|
||||||
/** @var IManager */
|
/** @var IManager */
|
||||||
protected $shareManager;
|
protected $shareManager;
|
||||||
|
@ -96,11 +98,11 @@ class FederatedShareProviderTest extends \Test\TestCase {
|
||||||
$this->userManager = $this->getMockBuilder('OCP\IUserManager')->getMock();
|
$this->userManager = $this->getMockBuilder('OCP\IUserManager')->getMock();
|
||||||
//$this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l);
|
//$this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l);
|
||||||
$this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')->disableOriginalConstructor()->getMock();
|
$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->userManager->expects($this->any())->method('userExists')->willReturn(true);
|
||||||
|
|
||||||
$this->cloudIdManager = new CloudIdManager();
|
|
||||||
|
|
||||||
$this->provider = new FederatedShareProvider(
|
$this->provider = new FederatedShareProvider(
|
||||||
$this->connection,
|
$this->connection,
|
||||||
$this->addressHandler,
|
$this->addressHandler,
|
||||||
|
@ -111,7 +113,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
|
||||||
$this->rootFolder,
|
$this->rootFolder,
|
||||||
$this->config,
|
$this->config,
|
||||||
$this->userManager,
|
$this->userManager,
|
||||||
$this->cloudIdManager
|
$this->cloudIdManager,
|
||||||
|
$this->gsConfig
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->shareManager = \OC::$server->getShareManager();
|
$this->shareManager = \OC::$server->getShareManager();
|
||||||
|
@ -409,7 +412,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
|
||||||
$this->rootFolder,
|
$this->rootFolder,
|
||||||
$this->config,
|
$this->config,
|
||||||
$this->userManager,
|
$this->userManager,
|
||||||
$this->cloudIdManager
|
$this->cloudIdManager,
|
||||||
|
$this->gsConfig
|
||||||
]
|
]
|
||||||
)->setMethods(['sendPermissionUpdate'])->getMock();
|
)->setMethods(['sendPermissionUpdate'])->getMock();
|
||||||
|
|
||||||
|
@ -674,13 +678,15 @@ class FederatedShareProviderTest extends \Test\TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataTestFederatedSharingSettings
|
* @dataProvider dataTestIsOutgoingServer2serverShareEnabled
|
||||||
*
|
*
|
||||||
* @param string $isEnabled
|
* @param string $isEnabled
|
||||||
* @param bool $expected
|
* @param bool $expected
|
||||||
*/
|
*/
|
||||||
public function testIsOutgoingServer2serverShareEnabled($isEnabled, $expected) {
|
public function testIsOutgoingServer2serverShareEnabled($internalOnly, $isEnabled, $expected) {
|
||||||
$this->config->expects($this->once())->method('getAppValue')
|
$this->gsConfig->expects($this->once())->method('onlyInternalFederation')
|
||||||
|
->willReturn($internalOnly);
|
||||||
|
$this->config->expects($this->any())->method('getAppValue')
|
||||||
->with('files_sharing', 'outgoing_server2server_share_enabled', 'yes')
|
->with('files_sharing', 'outgoing_server2server_share_enabled', 'yes')
|
||||||
->willReturn($isEnabled);
|
->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 string $isEnabled
|
||||||
* @param bool $expected
|
* @param bool $expected
|
||||||
*/
|
*/
|
||||||
public function testIsIncomingServer2serverShareEnabled($isEnabled, $expected) {
|
public function testIsIncomingServer2serverShareEnabled($onlyInternal, $isEnabled, $expected) {
|
||||||
$this->config->expects($this->once())->method('getAppValue')
|
$this->gsConfig->expects($this->once())->method('onlyInternalFederation')
|
||||||
|
->willReturn($onlyInternal);
|
||||||
|
$this->config->expects($this->any())->method('getAppValue')
|
||||||
->with('files_sharing', 'incoming_server2server_share_enabled', 'yes')
|
->with('files_sharing', 'incoming_server2server_share_enabled', 'yes')
|
||||||
->willReturn($isEnabled);
|
->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 string $isEnabled
|
||||||
* @param bool $expected
|
* @param bool $expected
|
||||||
*/
|
*/
|
||||||
public function testIsLookupServerQueriesEnabled($isEnabled, $expected) {
|
public function testIsLookupServerQueriesEnabled($gsEnabled, $isEnabled, $expected) {
|
||||||
$this->config->expects($this->once())->method('getAppValue')
|
$this->gsConfig->expects($this->once())->method('isGlobalScaleEnabled')
|
||||||
|
->willReturn($gsEnabled);
|
||||||
|
$this->config->expects($this->any())->method('getAppValue')
|
||||||
->with('files_sharing', 'lookupServerEnabled', 'no')
|
->with('files_sharing', 'lookupServerEnabled', 'no')
|
||||||
->willReturn($isEnabled);
|
->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 string $isEnabled
|
||||||
* @param bool $expected
|
* @param bool $expected
|
||||||
*/
|
*/
|
||||||
public function testIsLookupServerUploadEnabled($isEnabled, $expected) {
|
public function testIsLookupServerUploadEnabled($gsEnabled, $isEnabled, $expected) {
|
||||||
$this->config->expects($this->once())->method('getAppValue')
|
$this->gsConfig->expects($this->once())->method('isGlobalScaleEnabled')
|
||||||
|
->willReturn($gsEnabled);
|
||||||
|
$this->config->expects($this->any())->method('getAppValue')
|
||||||
->with('files_sharing', 'lookupServerUploadEnabled', 'yes')
|
->with('files_sharing', 'lookupServerUploadEnabled', 'yes')
|
||||||
->willReturn($isEnabled);
|
->willReturn($isEnabled);
|
||||||
|
|
||||||
|
@ -737,10 +777,12 @@ class FederatedShareProviderTest extends \Test\TestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataTestFederatedSharingSettings() {
|
public function dataTestIsLookupServerUploadEnabled() {
|
||||||
return [
|
return [
|
||||||
['yes', true],
|
[false, 'yes', true],
|
||||||
['no', false]
|
[false, 'no', false],
|
||||||
|
[true, 'yes', false],
|
||||||
|
[true, 'no', false],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace OCA\FederatedFileSharing\Tests\Settings;
|
||||||
|
|
||||||
use OCA\FederatedFileSharing\Settings\Admin;
|
use OCA\FederatedFileSharing\Settings\Admin;
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\GlobalScale\IConfig;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class AdminTest extends TestCase {
|
class AdminTest extends TestCase {
|
||||||
|
@ -32,12 +33,17 @@ class AdminTest extends TestCase {
|
||||||
private $admin;
|
private $admin;
|
||||||
/** @var \OCA\FederatedFileSharing\FederatedShareProvider */
|
/** @var \OCA\FederatedFileSharing\FederatedShareProvider */
|
||||||
private $federatedShareProvider;
|
private $federatedShareProvider;
|
||||||
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $gsConfig;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::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->admin = new Admin(
|
||||||
$this->federatedShareProvider
|
$this->federatedShareProvider,
|
||||||
|
$this->gsConfig
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,8 +79,11 @@ class AdminTest extends TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('isLookupServerUploadEnabled')
|
->method('isLookupServerUploadEnabled')
|
||||||
->willReturn($state);
|
->willReturn($state);
|
||||||
|
$this->gsConfig->expects($this->once())->method('onlyInternalFederation')
|
||||||
|
->willReturn($state);
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
|
'internalOnly' => $state,
|
||||||
'outgoingServer2serverShareEnabled' => $state,
|
'outgoingServer2serverShareEnabled' => $state,
|
||||||
'incomingServer2serverShareEnabled' => $state,
|
'incomingServer2serverShareEnabled' => $state,
|
||||||
'lookupServerEnabled' => $state,
|
'lookupServerEnabled' => $state,
|
||||||
|
|
|
@ -1530,4 +1530,15 @@ $CONFIG = array(
|
||||||
*/
|
*/
|
||||||
'lookup_server' => 'https://lookup.nextcloud.com',
|
'lookup_server' => 'https://lookup.nextcloud.com',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set to true if the server is used in a setup based on Nextcloud's Global Scale architecture
|
||||||
|
*/
|
||||||
|
'gs.enabled' => false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* by default federation is only used internally in a Global Scale setup
|
||||||
|
* If you want to allow federation outside of your environment set it to 'global'
|
||||||
|
*/
|
||||||
|
'gs.federation' => 'internal',
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
|
@ -53,6 +53,7 @@ use OCP\AppFramework\IAppContainer;
|
||||||
use OCP\AppFramework\QueryException;
|
use OCP\AppFramework\QueryException;
|
||||||
use OCP\Files\Folder;
|
use OCP\Files\Folder;
|
||||||
use OCP\Files\IAppData;
|
use OCP\Files\IAppData;
|
||||||
|
use OCP\GlobalScale\IConfig;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\IServerContainer;
|
use OCP\IServerContainer;
|
||||||
|
@ -159,6 +160,10 @@ class DIContainer extends SimpleContainer implements IAppContainer {
|
||||||
return $this->getServer()->getEncryptionManager();
|
return $this->getServer()->getEncryptionManager();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->registerService(IConfig::class, function ($c) {
|
||||||
|
return $c->query(OC\GlobalScale\Config::class);
|
||||||
|
});
|
||||||
|
|
||||||
$this->registerService(IValidator::class, function($c) {
|
$this->registerService(IValidator::class, function($c) {
|
||||||
return $c->query(Validator::class);
|
return $c->query(Validator::class);
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace OC\GlobalScale;
|
||||||
|
|
||||||
|
|
||||||
|
use OCP\IConfig;
|
||||||
|
|
||||||
|
class Config implements \OCP\GlobalScale\IConfig {
|
||||||
|
|
||||||
|
/** @var IConfig */
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Config constructor.
|
||||||
|
*
|
||||||
|
* @param IConfig $config
|
||||||
|
*/
|
||||||
|
public function __construct(IConfig $config) {
|
||||||
|
$this->config = $config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if global scale is enabled
|
||||||
|
*
|
||||||
|
* @since 12.0.1
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isGlobalScaleEnabled() {
|
||||||
|
$enabled = $this->config->getSystemValue('gs.enabled', false);
|
||||||
|
return $enabled !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if federation should only be used internally in a global scale setup
|
||||||
|
*
|
||||||
|
* @since 12.0.1
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function onlyInternalFederation() {
|
||||||
|
// if global scale is disabled federation works always globally
|
||||||
|
$gsEnabled = $this->isGlobalScaleEnabled();
|
||||||
|
if ($gsEnabled === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$enabled = $this->config->getSystemValue('gs.federation', 'internal');
|
||||||
|
|
||||||
|
return $enabled === 'internal';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -24,6 +24,7 @@
|
||||||
namespace OC\Share20;
|
namespace OC\Share20;
|
||||||
|
|
||||||
use OC\CapabilitiesManager;
|
use OC\CapabilitiesManager;
|
||||||
|
use OC\GlobalScale\Config;
|
||||||
use OCA\FederatedFileSharing\AddressHandler;
|
use OCA\FederatedFileSharing\AddressHandler;
|
||||||
use OCA\FederatedFileSharing\FederatedShareProvider;
|
use OCA\FederatedFileSharing\FederatedShareProvider;
|
||||||
use OCA\FederatedFileSharing\Notifications;
|
use OCA\FederatedFileSharing\Notifications;
|
||||||
|
@ -125,7 +126,8 @@ class ProviderFactory implements IProviderFactory {
|
||||||
$this->serverContainer->getLazyRootFolder(),
|
$this->serverContainer->getLazyRootFolder(),
|
||||||
$this->serverContainer->getConfig(),
|
$this->serverContainer->getConfig(),
|
||||||
$this->serverContainer->getUserManager(),
|
$this->serverContainer->getUserManager(),
|
||||||
$this->serverContainer->getCloudIdManager()
|
$this->serverContainer->getCloudIdManager(),
|
||||||
|
$this->serverContainer->query(Config::class)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace OCP\GlobalScale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface IConfig
|
||||||
|
*
|
||||||
|
* Configuration of the global scale architecture
|
||||||
|
*
|
||||||
|
* @package OCP\GlobalScale
|
||||||
|
* @since 12.0.1
|
||||||
|
*/
|
||||||
|
interface IConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if global scale is enabled
|
||||||
|
*
|
||||||
|
* @since 12.0.1
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isGlobalScaleEnabled();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if federation should only be used internally in a global scale setup
|
||||||
|
*
|
||||||
|
* @since 12.0.1
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function onlyInternalFederation();
|
||||||
|
|
||||||
|
}
|
|
@ -212,8 +212,14 @@ $tmpl->assign('certs', $certificateManager->listCertificates());
|
||||||
$tmpl->assign('showCertificates', $enableCertImport);
|
$tmpl->assign('showCertificates', $enableCertImport);
|
||||||
$tmpl->assign('urlGenerator', $urlGenerator);
|
$tmpl->assign('urlGenerator', $urlGenerator);
|
||||||
|
|
||||||
$lookupServerUploadEnabled = $config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes');
|
$federatedFileSharingEnabled = \OC::$server->getAppManager()->isEnabledForUser('federatedfilesharing');
|
||||||
$lookupServerUploadEnabled = $lookupServerUploadEnabled === 'yes';
|
$lookupServerUploadEnabled = false;
|
||||||
|
if ($federatedFileSharingEnabled) {
|
||||||
|
$federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application();
|
||||||
|
$shareProvider = $federatedFileSharing->getFederatedShareProvider();
|
||||||
|
$lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
$tmpl->assign('lookupServerUploadEnabled', $lookupServerUploadEnabled);
|
$tmpl->assign('lookupServerUploadEnabled', $lookupServerUploadEnabled);
|
||||||
|
|
||||||
// Get array of group ids for this user
|
// Get array of group ids for this user
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace Test\GlobalScale;
|
||||||
|
|
||||||
|
|
||||||
|
use OC\GlobalScale\Config;
|
||||||
|
use OCP\IConfig;
|
||||||
|
use Test\TestCase;
|
||||||
|
|
||||||
|
class ConfigTest extends TestCase {
|
||||||
|
|
||||||
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->config = $this->createMock(IConfig::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $mockMethods
|
||||||
|
* @return Config|\PHPUnit_Framework_MockObject_MockObject
|
||||||
|
*/
|
||||||
|
public function getInstance($mockMethods = []) {
|
||||||
|
|
||||||
|
if (!empty($mockMethods)) {
|
||||||
|
return $this->getMockBuilder(Config::class)
|
||||||
|
->setConstructorArgs([$this->config])
|
||||||
|
->setMethods($mockMethods)
|
||||||
|
->getMock();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Config($this->config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsGlobalScaleEnabled() {
|
||||||
|
$gsConfig = $this->getInstance();
|
||||||
|
$this->config->expects($this->once())->method('getSystemValue')
|
||||||
|
->with('gs.enabled', false)->willReturn(true);
|
||||||
|
|
||||||
|
$result = $gsConfig->isGlobalScaleEnabled();
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataTestOnlyInternalFederation
|
||||||
|
*
|
||||||
|
* @param bool $gsEnabled
|
||||||
|
* @param string $gsFederation
|
||||||
|
* @param bool $expected
|
||||||
|
*/
|
||||||
|
public function testOnlyInternalFederation($gsEnabled, $gsFederation, $expected) {
|
||||||
|
$gsConfig = $this->getInstance(['isGlobalScaleEnabled']);
|
||||||
|
|
||||||
|
$gsConfig->expects($this->any())->method('isGlobalScaleEnabled')->willReturn($gsEnabled);
|
||||||
|
|
||||||
|
$this->config->expects($this->any())->method('getSystemValue')
|
||||||
|
->with('gs.federation', 'internal')->willReturn($gsFederation);
|
||||||
|
|
||||||
|
$this->assertSame($expected, $gsConfig->onlyInternalFederation());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dataTestOnlyInternalFederation() {
|
||||||
|
return [
|
||||||
|
[true, 'global', false],
|
||||||
|
[true, 'internal', true],
|
||||||
|
[false, 'global', false],
|
||||||
|
[false, 'internal', false]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue