do not offer the handle of the current user for auto completion

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2018-01-17 13:49:18 +01:00
parent 3784fa2074
commit 6fdd686111
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
3 changed files with 67 additions and 0 deletions

View File

@ -40,6 +40,15 @@ class Search implements ISearch {
$this->c = $c;
}
/**
* @param $search
* @param array $shareTypes
* @param $lookup
* @param $limit
* @param $offset
* @return array
* @throws \OCP\AppFramework\QueryException
*/
public function search($search, array $shareTypes, $lookup, $limit, $offset) {
$hasMoreResults = false;

View File

@ -83,6 +83,8 @@ class UserPlugin implements ISearchPlugin {
}
}
$this->takeOutCurrentUser($users);
if (!$this->shareeEnumeration || sizeof($users) < $limit) {
$hasMoreResults = true;
}
@ -146,4 +148,13 @@ class UserPlugin implements ISearchPlugin {
return $hasMoreResults;
}
public function takeOutCurrentUser(array &$users) {
$currentUser = $this->userSession->getUser();
if(!is_null($currentUser)) {
if (isset($users[$currentUser->getUID()])) {
unset($users[$currentUser->getUID()]);
}
}
}
}

View File

@ -442,4 +442,51 @@ class UserPluginTest extends TestCase {
$this->assertEquals($expected, $result['users']);
$this->assertSame($reachedEnd, $moreResults);
}
public function takeOutCurrentUserProvider() {
$inputUsers = [
'alice' => 'Alice',
'bob' => 'Bob',
'carol' => 'Carol'
];
return [
[
$inputUsers,
['alice', 'carol'],
'bob'
],
[
$inputUsers,
['alice', 'bob', 'carol'],
'dave'
],
[
$inputUsers,
['alice', 'bob', 'carol'],
null
]
];
}
/**
* @dataProvider takeOutCurrentUserProvider
* @param array $users
* @param array $expectedUIDs
* @param $currentUserId
*/
public function testTakeOutCurrentUser(array $users, array $expectedUIDs, $currentUserId) {
$this->instantiatePlugin();
$this->session->expects($this->once())
->method('getUser')
->willReturnCallback(function() use ($currentUserId) {
if($currentUserId !== null) {
return $this->getUserMock($currentUserId, $currentUserId);
}
return null;
});
$this->plugin->takeOutCurrentUser($users);
$this->assertSame($expectedUIDs, array_keys($users));
}
}