aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2018-10-17 21:20:15 +0200
committerJulius Härtl <jus@bitgrid.net>2018-10-30 10:19:33 +0100
commitce79e587e471493a40f08790f7c9e58f80452198 (patch)
tree77f5483ccc3af6a64a38c44e0bfc5af27ccdb06f
parent45d8aeb9f2708cc53473d8a344a1a8fe6a0331bc (diff)
downloadnextcloud-server-ce79e587e471493a40f08790f7c9e58f80452198.tar.gz
nextcloud-server-ce79e587e471493a40f08790f7c9e58f80452198.zip
Filter out local users from address book remote searches
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r--lib/private/Collaboration/Collaborators/RemotePlugin.php13
-rw-r--r--tests/lib/Collaboration/Collaborators/RemotePluginTest.php8
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/private/Collaboration/Collaborators/RemotePlugin.php b/lib/private/Collaboration/Collaborators/RemotePlugin.php
index e0f5298f83b..c967b51df14 100644
--- a/lib/private/Collaboration/Collaborators/RemotePlugin.php
+++ b/lib/private/Collaboration/Collaborators/RemotePlugin.php
@@ -30,6 +30,7 @@ use OCP\Collaboration\Collaborators\SearchResultType;
use OCP\Contacts\IManager;
use OCP\Federation\ICloudIdManager;
use OCP\IConfig;
+use OCP\IUserManager;
use OCP\Share;
class RemotePlugin implements ISearchPlugin {
@@ -41,11 +42,14 @@ class RemotePlugin implements ISearchPlugin {
private $cloudIdManager;
/** @var IConfig */
private $config;
+ /** @var IUserManager */
+ private $userManager;
- public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) {
+ public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config, IUserManager $userManager) {
$this->contactsManager = $contactsManager;
$this->cloudIdManager = $cloudIdManager;
$this->config = $config;
+ $this->userManager = $userManager;
$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
}
@@ -69,11 +73,16 @@ class RemotePlugin implements ISearchPlugin {
$lowerSearch = strtolower($search);
foreach ($cloudIds as $cloudId) {
try {
- list(, $serverUrl) = $this->splitUserRemote($cloudId);
+ list($remoteUser, $serverUrl) = $this->splitUserRemote($cloudId);
} catch (\InvalidArgumentException $e) {
continue;
}
+ $localUser = $this->userManager->get($remoteUser);
+ if ($localUser !== null && $cloudId === $localUser->getCloudId()) {
+ continue;
+ }
+
if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) {
if (strtolower($cloudId) === $lowerSearch) {
$searchResult->markExactIdMatch($resultType);
diff --git a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php
index aa009a7134b..ac050e23562 100644
--- a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php
+++ b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php
@@ -31,10 +31,15 @@ use OCP\Collaboration\Collaborators\SearchResultType;
use OCP\Contacts\IManager;
use OCP\Federation\ICloudIdManager;
use OCP\IConfig;
+use OCP\IUserManager;
use OCP\Share;
use Test\TestCase;
class RemotePluginTest extends TestCase {
+
+ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $userManager;
+
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
protected $config;
@@ -53,6 +58,7 @@ class RemotePluginTest extends TestCase {
public function setUp() {
parent::setUp();
+ $this->userManager = $this->createMock(IUserManager::class);
$this->config = $this->createMock(IConfig::class);
$this->contactsManager = $this->createMock(IManager::class);
$this->cloudIdManager = new CloudIdManager();
@@ -60,7 +66,7 @@ class RemotePluginTest extends TestCase {
}
public function instantiatePlugin() {
- $this->plugin = new RemotePlugin($this->contactsManager, $this->cloudIdManager, $this->config);
+ $this->plugin = new RemotePlugin($this->contactsManager, $this->cloudIdManager, $this->config, $this->userManager);
}
/**