Ver código fonte

Filter out local users from address book remote searches

Signed-off-by: Julius Härtl <jus@bitgrid.net>
tags/v15.0.0beta1
Julius Härtl 5 anos atrás
pai
commit
ce79e587e4
Nenhuma conta vinculada ao e-mail do autor do commit

+ 11
- 2
lib/private/Collaboration/Collaborators/RemotePlugin.php Ver arquivo

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

+ 7
- 1
tests/lib/Collaboration/Collaborators/RemotePluginTest.php Ver arquivo

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

/**

Carregando…
Cancelar
Salvar