Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
do not offer the handle of the current user for auto completion
Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Jan 17, 2018
commit 6fdd6861118f55a9e740552b82382f55e9415eea
9 changes: 9 additions & 0 deletions lib/private/Collaboration/Collaborators/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public function __construct(IContainer $c) {
$this->c = $c;
}

/**
* @param $search
* @param array $shareTypes
* @param $lookup
* @param $limit
* @param $offset
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add types?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah stupid IDE ;)

* @return array
* @throws \OCP\AppFramework\QueryException
*/
public function search($search, array $shareTypes, $lookup, $limit, $offset) {
$hasMoreResults = false;

Expand Down
11 changes: 11 additions & 0 deletions lib/private/Collaboration/Collaborators/UserPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
}
}

$this->takeOutCurrentUser($users);

if (!$this->shareeEnumeration || sizeof($users) < $limit) {
$hasMoreResults = true;
}
Expand Down Expand Up @@ -146,4 +148,13 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {

return $hasMoreResults;
}

public function takeOutCurrentUser(array &$users) {
$currentUser = $this->userSession->getUser();
if(!is_null($currentUser)) {
if (isset($users[$currentUser->getUID()])) {
unset($users[$currentUser->getUID()]);
}
}
}
}
47 changes: 47 additions & 0 deletions tests/lib/Collaboration/Collaborators/UserPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,51 @@ function($appName, $key, $default)
$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));
}
}