summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/federatedfilesharing/lib/FederatedShareProvider.php10
-rw-r--r--apps/federatedfilesharing/lib/Settings/Admin.php1
-rw-r--r--apps/federatedfilesharing/templates/settings-admin.php7
-rw-r--r--apps/federatedfilesharing/tests/Settings/AdminTest.php5
-rw-r--r--apps/files_sharing/lib/Controller/ShareesAPIController.php42
-rw-r--r--apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php24
6 files changed, 71 insertions, 18 deletions
diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php
index 6481abe32e2..61f1b1c8f18 100644
--- a/apps/federatedfilesharing/lib/FederatedShareProvider.php
+++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php
@@ -943,4 +943,14 @@ class FederatedShareProvider implements IShareProvider {
$result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes');
return ($result === 'yes') ? true : false;
}
+
+ /**
+ * Check if querying sharees on the lookup server is enabled
+ *
+ * @return bool
+ */
+ public function isLookupServerQueriesEnabled() {
+ $result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no');
+ return ($result === 'yes') ? true : false;
+ }
}
diff --git a/apps/federatedfilesharing/lib/Settings/Admin.php b/apps/federatedfilesharing/lib/Settings/Admin.php
index 64619e329f3..20ff6ae6f4a 100644
--- a/apps/federatedfilesharing/lib/Settings/Admin.php
+++ b/apps/federatedfilesharing/lib/Settings/Admin.php
@@ -43,6 +43,7 @@ class Admin implements ISettings {
$parameters = [
'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(),
'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(),
+ 'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(),
];
return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, '');
diff --git a/apps/federatedfilesharing/templates/settings-admin.php b/apps/federatedfilesharing/templates/settings-admin.php
index 3ffd4bd5b27..0670553e061 100644
--- a/apps/federatedfilesharing/templates/settings-admin.php
+++ b/apps/federatedfilesharing/templates/settings-admin.php
@@ -25,4 +25,11 @@ script('federatedfilesharing', 'settings-admin');
<?php p($l->t('Allow users on this server to receive shares from other servers'));?>
</label><br/>
</p>
+ <p>
+ <input type="checkbox" name="lookupServerEnabled" id="lookupServerEnabled" class="checkbox"
+ value="1" <?php if ($_['lookupServerEnabled']) print_unescaped('checked="checked"'); ?> />
+ <label for="lookupServerEnabled">
+ <?php p($l->t('Enable lookups on lookup server'));?>
+ </label><br/>
+ </p>
</div>
diff --git a/apps/federatedfilesharing/tests/Settings/AdminTest.php b/apps/federatedfilesharing/tests/Settings/AdminTest.php
index 60fadca7b56..c0b35a6427b 100644
--- a/apps/federatedfilesharing/tests/Settings/AdminTest.php
+++ b/apps/federatedfilesharing/tests/Settings/AdminTest.php
@@ -65,10 +65,15 @@ class AdminTest extends TestCase {
->expects($this->once())
->method('isIncomingServer2serverShareEnabled')
->willReturn($state);
+ $this->federatedShareProvider
+ ->expects($this->once())
+ ->method('isLookupServerQueriesEnabled')
+ ->willReturn($state);
$params = [
'outgoingServer2serverShareEnabled' => $state,
'incomingServer2serverShareEnabled' => $state,
+ 'lookupServerEnabled' => $state,
];
$expected = new TemplateResponse('federatedfilesharing', 'settings-admin', $params, '');
$this->assertEquals($expected, $this->admin->getForm());
diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php
index 7b9e10090d2..6b3208dc289 100644
--- a/apps/files_sharing/lib/Controller/ShareesAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php
@@ -626,22 +626,36 @@ class ShareesAPIController extends OCSController {
}
protected function getLookup($search) {
- $client = $this->clientService->newClient();
-
- $response = $client->get('https://lookup.nextcloud.com/users?search='.urlencode($search));
- $body = json_decode($response->getBody(), true);
-
+ $isEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no');
$result = [];
- foreach ($body as $lookup) {
- $result[] = [
- 'label' => $lookup['federationId'],
- 'value' => [
- 'shareType' => Share::SHARE_TYPE_REMOTE,
- 'shareWith' => $lookup['federationId'],
- ],
- 'extra' => $lookup,
- ];
+
+ if($isEnabled === 'yes') {
+ try {
+ $client = $this->clientService->newClient();
+ $response = $client->get(
+ 'https://lookup.nextcloud.com/users?search=' . urlencode($search),
+ [
+ 'timeout' => 10,
+ 'connect_timeout' => 3,
+ ]
+ );
+
+ $body = json_decode($response->getBody(), true);
+
+ $result = [];
+ foreach ($body as $lookup) {
+ $result[] = [
+ 'label' => $lookup['federationId'],
+ 'value' => [
+ 'shareType' => Share::SHARE_TYPE_REMOTE,
+ 'shareWith' => $lookup['federationId'],
+ ],
+ 'extra' => $lookup,
+ ];
+ }
+ } catch (\Exception $e) {}
}
+
$this->result['lookup'] = $result;
}
diff --git a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
index 336dcb70f0e..c570cb16980 100644
--- a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
@@ -29,6 +29,7 @@ use OCA\Files_Sharing\Controller\ShareesAPIController;
use OCA\Files_Sharing\Tests\TestCase;
use OCP\AppFramework\Http;
use OCP\AppFramework\OCS\OCSBadRequestException;
+use OCP\Http\Client\IClientService;
use OCP\Share;
/**
@@ -60,6 +61,9 @@ class ShareesAPIControllerTest extends TestCase {
/** @var \OCP\Share\IManager|\PHPUnit_Framework_MockObject_MockObject */
protected $shareManager;
+ /** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
+ private $clientService;
+
protected function setUp() {
parent::setUp();
@@ -87,6 +91,8 @@ class ShareesAPIControllerTest extends TestCase {
->disableOriginalConstructor()
->getMock();
+ $this->clientService = $this->createMock(IClientService::class);
+
$this->sharees = new ShareesAPIController(
'files_sharing',
$this->request,
@@ -97,7 +103,8 @@ class ShareesAPIControllerTest extends TestCase {
$this->session,
$this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(),
$this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock(),
- $this->shareManager
+ $this->shareManager,
+ $this->clientService
);
}
@@ -1386,7 +1393,8 @@ class ShareesAPIControllerTest extends TestCase {
$this->session,
$this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(),
$this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock(),
- $this->shareManager
+ $this->shareManager,
+ $this->clientService
])
->setMethods(array('searchSharees', 'isRemoteSharingAllowed', 'shareProviderExists'))
->getMock();
@@ -1477,7 +1485,8 @@ class ShareesAPIControllerTest extends TestCase {
$this->session,
$this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(),
$this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock(),
- $this->shareManager
+ $this->shareManager,
+ $this->clientService
])
->setMethods(array('searchSharees', 'isRemoteSharingAllowed'))
->getMock();
@@ -1522,6 +1531,7 @@ class ShareesAPIControllerTest extends TestCase {
'groups' => [],
'remotes' => [],
'emails' => [],
+ 'lookup' => [],
], false],
['test', 'folder', [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_REMOTE], 1, 2, false, [], [], ['results' => [], 'exact' => [], 'exactIdMatch' => false],
[
@@ -1530,6 +1540,7 @@ class ShareesAPIControllerTest extends TestCase {
'groups' => [],
'remotes' => [],
'emails' => [],
+ 'lookup' => [],
], false],
[
'test', 'folder', [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_REMOTE], 1, 2, false, [
@@ -1551,6 +1562,7 @@ class ShareesAPIControllerTest extends TestCase {
['label' => 'testz@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'testz@remote']],
],
'emails' => [],
+ 'lookup' => [],
], true,
],
// No groups requested
@@ -1570,6 +1582,7 @@ class ShareesAPIControllerTest extends TestCase {
['label' => 'testz@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'testz@remote']],
],
'emails' => [],
+ 'lookup' => [],
], false,
],
// Share type restricted to user - Only one user
@@ -1585,6 +1598,7 @@ class ShareesAPIControllerTest extends TestCase {
'groups' => [],
'remotes' => [],
'emails' => [],
+ 'lookup' => [],
], false,
],
// Share type restricted to user - Multipage result
@@ -1602,6 +1616,7 @@ class ShareesAPIControllerTest extends TestCase {
'groups' => [],
'remotes' => [],
'emails' => [],
+ 'lookup' => [],
], true,
],
];
@@ -1636,7 +1651,8 @@ class ShareesAPIControllerTest extends TestCase {
$this->session,
$this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(),
$this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock(),
- $this->shareManager
+ $this->shareManager,
+ $this->clientService
])
->setMethods(array('getShareesForShareIds', 'getUsers', 'getGroups', 'getRemote'))
->getMock();