Filter out local users from address book remote searches

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2018-10-17 21:20:15 +02:00
parent 45d8aeb9f2
commit ce79e587e4
No known key found for this signature in database
GPG key ID: 4C614C6ED2CDE6DF
2 changed files with 18 additions and 3 deletions

View file

@ -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);

View file

@ -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);
}
/**