Skip to content

Commit 01c147a

Browse files
committed
dont show remote and email options if we have an exact match for local user email
Signed-off-by: Robin Appelman <[email protected]>
1 parent 547ba64 commit 01c147a

File tree

3 files changed

+105
-70
lines changed

3 files changed

+105
-70
lines changed

lib/private/Collaboration/Collaborators/Search.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ public function search($search, array $shareTypes, $lookup, $limit, $offset) {
8585
$searchResult->unsetResult($emailType);
8686
}
8787

88+
// if we have an exact local user match, there is no need to show the remote and email matches
89+
$userType = new SearchResultType('users');
90+
if($searchResult->hasExactIdMatch($userType)) {
91+
$searchResult->unsetResult($remoteType);
92+
$searchResult->unsetResult($emailType);
93+
}
94+
8895
return [$searchResult->asArray(), (bool)$hasMoreResults];
8996
}
9097

lib/private/Collaboration/Collaborators/UserPlugin.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OCP\Collaboration\Collaborators\ISearchResult;
3333
use OCP\Collaboration\Collaborators\SearchResultType;
3434
use OCP\IConfig;
35+
use OCP\IGroup;
3536
use OCP\IGroupManager;
3637
use OCP\IUser;
3738
use OCP\IUserManager;
@@ -75,11 +76,11 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
7576
$userGroups = [];
7677
if ($this->shareWithGroupOnly) {
7778
// Search in all the groups this user is part of
78-
$userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
79+
$userGroups = $this->groupManager->getUserGroups($this->userSession->getUser());
7980
foreach ($userGroups as $userGroup) {
80-
$usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $limit, $offset);
81-
foreach ($usersTmp as $uid => $userDisplayName) {
82-
$users[(string) $uid] = $userDisplayName;
81+
$usersInGroup = $userGroup->searchDisplayName($search, $limit, $offset);
82+
foreach ($usersInGroup as $user) {
83+
$users[$user->getUID()] = $user;
8384
}
8485
}
8586
} else {
@@ -88,7 +89,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
8889
$currentUserGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
8990
foreach ($usersTmp as $user) {
9091
if ($user->isEnabled()) { // Don't keep deactivated users
91-
$users[(string) $user->getUID()] = $user->getDisplayName();
92+
$users[$user->getUID()] = $user;
9293

9394
$addToWideResults = false;
9495
if ($this->shareeEnumeration && !$this->shareeEnumerationInGroupOnly) {
@@ -123,9 +124,15 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
123124

124125
$foundUserById = false;
125126
$lowerSearch = strtolower($search);
126-
foreach ($users as $uid => $userDisplayName) {
127+
foreach ($users as $uid => $user) {
128+
$userDisplayName = $user->getDisplayName();
129+
$userEmail = $user->getEMailAddress();
127130
$uid = (string) $uid;
128-
if (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch) {
131+
if (
132+
strtolower($uid) === $lowerSearch ||
133+
strtolower($userDisplayName) === $lowerSearch ||
134+
strtolower($userEmail) === $lowerSearch
135+
) {
129136
if (strtolower($uid) === $lowerSearch) {
130137
$foundUserById = true;
131138
}
@@ -156,7 +163,10 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
156163

157164
if ($this->shareWithGroupOnly) {
158165
// Only add, if we have a common group
159-
$commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user));
166+
$userGroupIds = array_map(function(IGroup $group) {
167+
return $group->getGID();
168+
}, $userGroups);
169+
$commonGroups = array_intersect($userGroupIds, $this->groupManager->getUserGroupIds($user));
160170
$addUser = !empty($commonGroups);
161171
}
162172

@@ -179,6 +189,9 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
179189

180190
$type = new SearchResultType('users');
181191
$searchResult->addResultSet($type, $result['wide'], $result['exact']);
192+
if (count($result['exact'])) {
193+
$searchResult->markExactIdMatch($type);
194+
}
182195

183196
return $hasMoreResults;
184197
}

0 commit comments

Comments
 (0)