diff --git a/lib/private/Collaboration/Collaborators/Search.php b/lib/private/Collaboration/Collaborators/Search.php index e9b15dd120..0e856eeb6f 100644 --- a/lib/private/Collaboration/Collaborators/Search.php +++ b/lib/private/Collaboration/Collaborators/Search.php @@ -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; diff --git a/lib/private/Collaboration/Collaborators/UserPlugin.php b/lib/private/Collaboration/Collaborators/UserPlugin.php index 86a55aa428..ad67770354 100644 --- a/lib/private/Collaboration/Collaborators/UserPlugin.php +++ b/lib/private/Collaboration/Collaborators/UserPlugin.php @@ -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()]); + } + } + } } diff --git a/tests/lib/Collaboration/Collaborators/UserPluginTest.php b/tests/lib/Collaboration/Collaborators/UserPluginTest.php index 7d6d9c645a..cfb97de867 100644 --- a/tests/lib/Collaboration/Collaborators/UserPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/UserPluginTest.php @@ -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)); + } }