diff options
Diffstat (limited to 'apps/files_sharing/lib/Controller/ShareesAPIController.php')
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareesAPIController.php | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php index 6b3208dc289..cd5139693cf 100644 --- a/apps/files_sharing/lib/Controller/ShareesAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php @@ -165,9 +165,10 @@ class ShareesAPIController extends OCSController { } $foundUserById = false; + $lowerSearch = strtolower($search); foreach ($users as $uid => $userDisplayName) { - if (strtolower($uid) === strtolower($search) || strtolower($userDisplayName) === strtolower($search)) { - if (strtolower($uid) === strtolower($search)) { + if (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch) { + if (strtolower($uid) === $lowerSearch) { $foundUserById = true; } $this->result['exact']['users'][] = [ @@ -225,7 +226,7 @@ class ShareesAPIController extends OCSController { $this->result['groups'] = $this->result['exact']['groups'] = []; $groups = $this->groupManager->search($search, $this->limit, $this->offset); - $groups = array_map(function (IGroup $group) { return $group->getGID(); }, $groups); + $groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups); if (!$this->shareeEnumeration || sizeof($groups) < $this->limit) { $this->reachedEndFor[] = 'groups'; @@ -236,13 +237,19 @@ class ShareesAPIController extends OCSController { // Intersect all the groups that match with the groups this user is a member of $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); $userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups); - $groups = array_intersect($groups, $userGroups); + $groupIds = array_intersect($groupIds, $userGroups); } - foreach ($groups as $gid) { - if (strtolower($gid) === strtolower($search)) { + $lowerSearch = strtolower($search); + foreach ($groups as $group) { + // FIXME: use a more efficient approach + $gid = $group->getGID(); + if (!in_array($gid, $groupIds)) { + continue; + } + if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) { $this->result['exact']['groups'][] = [ - 'label' => $gid, + 'label' => $group->getDisplayName(), 'value' => [ 'shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => $gid, @@ -250,7 +257,7 @@ class ShareesAPIController extends OCSController { ]; } else { $this->result['groups'][] = [ - 'label' => $gid, + 'label' => $group->getDisplayName(), 'value' => [ 'shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => $gid, @@ -265,7 +272,7 @@ class ShareesAPIController extends OCSController { $group = $this->groupManager->get($search); if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) { array_push($this->result['exact']['groups'], [ - 'label' => $group->getGID(), + 'label' => $group->getDisplayName(), 'value' => [ 'shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => $group->getGID(), @@ -299,10 +306,11 @@ class ShareesAPIController extends OCSController { if (!is_array($cloudIds)) { $cloudIds = [$cloudIds]; } + $lowerSearch = strtolower($search); foreach ($cloudIds as $cloudId) { list(, $serverUrl) = $this->splitUserRemote($cloudId); - if (strtolower($contact['FN']) === strtolower($search) || strtolower($cloudId) === strtolower($search)) { - if (strtolower($cloudId) === strtolower($search)) { + if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) { + if (strtolower($cloudId) === $lowerSearch) { $result['exactIdMatch'] = true; } $result['exact'][] = [ |