diff --git a/apps/files_sharing/api/sharees.php b/apps/files_sharing/api/sharees.php index 807b6b3314f1..d7eabb9a550a 100644 --- a/apps/files_sharing/api/sharees.php +++ b/apps/files_sharing/api/sharees.php @@ -139,8 +139,8 @@ protected function getUsers($search) { $foundUserById = false; foreach ($users as $uid => $userDisplayName) { - if ($uid === $search || $userDisplayName === $search) { - if ($uid === $search) { + if (strtolower($uid) === $search || strtolower($userDisplayName) === $search) { + if (strtolower($uid) === $search) { $foundUserById = true; } $this->result['exact']['users'][] = [ @@ -199,7 +199,7 @@ protected function getGroups($search) { } foreach ($groups as $gid) { - if ($gid === $search) { + if (strtolower($gid) === $search) { $this->result['exact']['groups'][] = [ 'label' => $search, 'value' => [ @@ -222,8 +222,8 @@ protected function getGroups($search) { // On page one we try if the search result has a direct hit on the // user id and if so, we add that to the exact match list $group = $this->groupManager->get($search); - if ($group instanceof IGroup && (!$this->shareWithGroupOnly || array_intersect([$group], $userGroups))) { - array_push($this->result['exact']['users'], [ + if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) { + array_push($this->result['exact']['groups'], [ 'label' => $group->getGID(), 'value' => [ 'shareType' => Share::SHARE_TYPE_GROUP, @@ -241,23 +241,17 @@ protected function getGroups($search) { protected function getRemote($search) { $this->result['remotes'] = []; - if (substr_count($search, '@') >= 1 && $this->offset === 0) { - $this->result['exact']['remotes'][] = [ - 'label' => $search, - 'value' => [ - 'shareType' => Share::SHARE_TYPE_REMOTE, - 'shareWith' => $search, - ], - ]; - } - // Search in contacts //@todo Pagination missing $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']); + $foundRemoteById = false; foreach ($addressBookContacts as $contact) { if (isset($contact['CLOUD'])) { foreach ($contact['CLOUD'] as $cloudId) { - if ($contact['FN'] === $search || $cloudId === $search) { + if (strtolower($contact['FN']) === $search || strtolower($cloudId) === $search) { + if (strtolower($cloudId) === $search) { + $foundRemoteById = true; + } $this->result['exact']['remotes'][] = [ 'label' => $contact['FN'], 'value' => [ @@ -278,6 +272,16 @@ protected function getRemote($search) { } } + if (!$foundRemoteById && substr_count($search, '@') >= 1 && substr_count($search, ' ') === 0 && $this->offset === 0) { + $this->result['exact']['remotes'][] = [ + 'label' => $search, + 'value' => [ + 'shareType' => Share::SHARE_TYPE_REMOTE, + 'shareWith' => $search, + ], + ]; + } + $this->reachedEndFor[] = 'remotes'; } @@ -313,7 +317,7 @@ public function search() { $this->limit = (int) $perPage; $this->offset = $perPage * ($page - 1); - return $this->searchSharees($search, $itemType, $shareTypes, $page, $perPage); + return $this->searchSharees(strtolower($search), $itemType, $shareTypes, $page, $perPage); } /** diff --git a/apps/files_sharing/tests/api/shareestest.php b/apps/files_sharing/tests/api/shareestest.php index d9f366233436..1e4438acd889 100644 --- a/apps/files_sharing/tests/api/shareestest.php +++ b/apps/files_sharing/tests/api/shareestest.php @@ -111,8 +111,20 @@ protected function getGroupMock($gid) { public function dataGetUsers() { return [ - ['test', false, [], [], [], [], true], - ['test', true, [], [], [], [], true], + ['test', false, [], [], [], [], true, false], + ['test', true, [], [], [], [], true, false], + [ + 'test', false, [], [], + [ + ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']], + ], [], true, $this->getUserMock('test', 'Test') + ], + [ + 'test', true, [], [], + [ + ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']], + ], [], true, $this->getUserMock('test', 'Test') + ], [ 'test', false, @@ -125,6 +137,7 @@ public function dataGetUsers() { ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], ], true, + false, ], [ 'test', @@ -140,24 +153,26 @@ public function dataGetUsers() { ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']], ], false, + false, ], [ 'test', false, [], [ - $this->getUserMock('test', 'Test'), + $this->getUserMock('test0', 'Test'), $this->getUserMock('test1', 'Test One'), $this->getUserMock('test2', 'Test Two'), ], [ - ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']], + ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test0']], ], [ ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']], ], false, + false, ], [ 'test', @@ -172,6 +187,7 @@ public function dataGetUsers() { ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], ], true, + false, ], [ 'test', @@ -193,6 +209,7 @@ public function dataGetUsers() { ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']], ], false, + false, ], [ 'test', @@ -213,6 +230,7 @@ public function dataGetUsers() { ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']], ], false, + false, ], ]; } @@ -227,8 +245,9 @@ public function dataGetUsers() { * @param array $exactExpected * @param array $expected * @param bool $reachedEnd + * @param mixed $singleUser */ - public function testGetUsers($searchTerm, $shareWithGroupOnly, $groupResponse, $userResponse, $exactExpected, $expected, $reachedEnd) { + public function testGetUsers($searchTerm, $shareWithGroupOnly, $groupResponse, $userResponse, $exactExpected, $expected, $reachedEnd, $singleUser) { $this->invokePrivate($this->sharees, 'limit', [2]); $this->invokePrivate($this->sharees, 'offset', [0]); $this->invokePrivate($this->sharees, 'shareWithGroupOnly', [$shareWithGroupOnly]); @@ -255,6 +274,13 @@ public function testGetUsers($searchTerm, $shareWithGroupOnly, $groupResponse, $ ->willReturnMap($userResponse); } + if ($singleUser !== false) { + $this->userManager->expects($this->once()) + ->method('get') + ->with($searchTerm) + ->willReturn($singleUser); + } + $this->invokePrivate($this->sharees, 'getUsers', [$searchTerm]); $result = $this->invokePrivate($this->sharees, 'result'); @@ -265,7 +291,7 @@ public function testGetUsers($searchTerm, $shareWithGroupOnly, $groupResponse, $ public function dataGetGroups() { return [ - ['test', false, [], [], [], [], true], + ['test', false, [], [], [], [], true, false], [ 'test', false, [$this->getGroupMock('test1')], @@ -273,6 +299,7 @@ public function dataGetGroups() { [], [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]], true, + false, ], [ 'test', false, @@ -284,8 +311,41 @@ public function dataGetGroups() { [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]], [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]], false, + false, ], - ['test', true, [], [], [], [], true], + [ + 'test', false, + [ + $this->getGroupMock('test0'), + $this->getGroupMock('test1'), + ], + [], + [], + [ + ['label' => 'test0', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test0']], + ['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']], + ], + false, + null, + ], + [ + 'test', false, + [ + $this->getGroupMock('test0'), + $this->getGroupMock('test1'), + ], + [], + [ + ['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']], + ], + [ + ['label' => 'test0', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test0']], + ['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']], + ], + false, + $this->getGroupMock('test'), + ], + ['test', true, [], [], [], [], true, false], [ 'test', true, [ @@ -296,6 +356,7 @@ public function dataGetGroups() { [], [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]], false, + false, ], [ 'test', true, @@ -307,6 +368,7 @@ public function dataGetGroups() { [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]], [], false, + false, ], [ 'test', true, @@ -318,6 +380,51 @@ public function dataGetGroups() { [], [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]], false, + false, + ], + [ + 'test', true, + [ + $this->getGroupMock('test'), + $this->getGroupMock('test1'), + ], + [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')], + [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]], + [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]], + false, + false, + ], + [ + 'test', true, + [ + $this->getGroupMock('test0'), + $this->getGroupMock('test1'), + ], + [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')], + [], + [ + ['label' => 'test0', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test0']], + ['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']], + ], + false, + null, + ], + [ + 'test', true, + [ + $this->getGroupMock('test0'), + $this->getGroupMock('test1'), + ], + [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')], + [ + ['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']], + ], + [ + ['label' => 'test0', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test0']], + ['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']], + ], + false, + $this->getGroupMock('test'), ], ]; } @@ -332,8 +439,9 @@ public function dataGetGroups() { * @param array $exactExpected * @param array $expected * @param bool $reachedEnd + * @param mixed $singleGroup */ - public function testGetGroups($searchTerm, $shareWithGroupOnly, $groupResponse, $userGroupsResponse, $exactExpected, $expected, $reachedEnd) { + public function testGetGroups($searchTerm, $shareWithGroupOnly, $groupResponse, $userGroupsResponse, $exactExpected, $expected, $reachedEnd, $singleGroup) { $this->invokePrivate($this->sharees, 'limit', [2]); $this->invokePrivate($this->sharees, 'offset', [0]); $this->invokePrivate($this->sharees, 'shareWithGroupOnly', [$shareWithGroupOnly]); @@ -343,6 +451,13 @@ public function testGetGroups($searchTerm, $shareWithGroupOnly, $groupResponse, ->with($searchTerm, $this->invokePrivate($this->sharees, 'limit'), $this->invokePrivate($this->sharees, 'offset')) ->willReturn($groupResponse); + if ($singleGroup !== false) { + $this->groupManager->expects($this->once()) + ->method('get') + ->with($searchTerm) + ->willReturn($singleGroup); + } + if ($shareWithGroupOnly) { $user = $this->getUserMock('admin', 'Administrator'); $this->session->expects($this->any()) @@ -426,6 +541,31 @@ public function dataGetRemote() { ], true, ], + [ + 'username@localhost', + [ + [ + 'FN' => 'User3 @ Localhost', + ], + [ + 'FN' => 'User2 @ Localhost', + 'CLOUD' => [ + ], + ], + [ + 'FN' => 'User @ Localhost', + 'CLOUD' => [ + 'username@localhost', + ], + ], + ], + [ + ['label' => 'User @ Localhost', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost']], + ], + [ + ], + true, + ], ]; }