diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-05-12 22:05:58 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-12 22:05:58 +0300 |
commit | de4a71c915ad6a1d49fe6d86b8268177312d1568 (patch) | |
tree | 2b09b54d8aee8a3a15dd12744670097fa5a32da9 /lib | |
parent | 72b577543641f6787935307c774cc88edc837ccb (diff) | |
parent | e26c055fb45cd548c71253cda7bb0c93b8d11a77 (diff) |
Merge pull request #20574 from nextcloud/backport/16035/stable18
[stable18] dont show remote and email options if we have an exact match for local user email
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Collaboration/Collaborators/Search.php | 7 | ||||
-rw-r--r-- | lib/private/Collaboration/Collaborators/UserPlugin.php | 29 |
2 files changed, 28 insertions, 8 deletions
diff --git a/lib/private/Collaboration/Collaborators/Search.php b/lib/private/Collaboration/Collaborators/Search.php index 7f5c5a1a811..9b9decfecbe 100644 --- a/lib/private/Collaboration/Collaborators/Search.php +++ b/lib/private/Collaboration/Collaborators/Search.php @@ -85,6 +85,13 @@ class Search implements ISearch { $searchResult->unsetResult($emailType); } + // if we have an exact local user match, there is no need to show the remote and email matches + $userType = new SearchResultType('users'); + if($searchResult->hasExactIdMatch($userType)) { + $searchResult->unsetResult($remoteType); + $searchResult->unsetResult($emailType); + } + return [$searchResult->asArray(), (bool)$hasMoreResults]; } diff --git a/lib/private/Collaboration/Collaborators/UserPlugin.php b/lib/private/Collaboration/Collaborators/UserPlugin.php index c40aaff4229..5fb278fc5ff 100644 --- a/lib/private/Collaboration/Collaborators/UserPlugin.php +++ b/lib/private/Collaboration/Collaborators/UserPlugin.php @@ -31,6 +31,7 @@ use OCP\Collaboration\Collaborators\ISearchPlugin; use OCP\Collaboration\Collaborators\ISearchResult; use OCP\Collaboration\Collaborators\SearchResultType; use OCP\IConfig; +use OCP\IGroup; use OCP\IGroupManager; use OCP\IUser; use OCP\IUserManager; @@ -70,11 +71,11 @@ class UserPlugin implements ISearchPlugin { $userGroups = []; if ($this->shareWithGroupOnly) { // Search in all the groups this user is part of - $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); + $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); foreach ($userGroups as $userGroup) { - $usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $limit, $offset); - foreach ($usersTmp as $uid => $userDisplayName) { - $users[(string) $uid] = $userDisplayName; + $usersInGroup = $userGroup->searchDisplayName($search, $limit, $offset); + foreach ($usersInGroup as $user) { + $users[$user->getUID()] = $user; } } } else { @@ -83,7 +84,7 @@ class UserPlugin implements ISearchPlugin { foreach ($usersTmp as $user) { if ($user->isEnabled()) { // Don't keep deactivated users - $users[(string) $user->getUID()] = $user->getDisplayName(); + $users[(string) $user->getUID()] = $user; } } } @@ -96,9 +97,15 @@ class UserPlugin implements ISearchPlugin { $foundUserById = false; $lowerSearch = strtolower($search); - foreach ($users as $uid => $userDisplayName) { + foreach ($users as $uid => $user) { + $userDisplayName = $user->getDisplayName(); + $userEmail = $user->getEMailAddress(); $uid = (string) $uid; - if (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch) { + if ( + strtolower($uid) === $lowerSearch || + strtolower($userDisplayName) === $lowerSearch || + strtolower($userEmail) === $lowerSearch + ) { if (strtolower($uid) === $lowerSearch) { $foundUserById = true; } @@ -129,7 +136,10 @@ class UserPlugin implements ISearchPlugin { if ($this->shareWithGroupOnly) { // Only add, if we have a common group - $commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user)); + $userGroupIds = array_map(function(IGroup $group) { + return $group->getGID(); + }, $userGroups); + $commonGroups = array_intersect($userGroupIds, $this->groupManager->getUserGroupIds($user)); $addUser = !empty($commonGroups); } @@ -151,6 +161,9 @@ class UserPlugin implements ISearchPlugin { $type = new SearchResultType('users'); $searchResult->addResultSet($type, $result['wide'], $result['exact']); + if (count($result['exact'])) { + $searchResult->markExactIdMatch($type); + } return $hasMoreResults; } |