Skip to content

Commit

Permalink
dont show remote and email options if we have an exact match for loca…
Browse files Browse the repository at this point in the history
…l user email

Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Apr 8, 2020
1 parent 547ba64 commit 01c147a
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 70 deletions.
7 changes: 7 additions & 0 deletions lib/private/Collaboration/Collaborators/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ public function search($search, array $shareTypes, $lookup, $limit, $offset) {
$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];
}

Expand Down
29 changes: 21 additions & 8 deletions lib/private/Collaboration/Collaborators/UserPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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;
Expand Down Expand Up @@ -75,11 +76,11 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
$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 {
Expand All @@ -88,7 +89,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
$currentUserGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
foreach ($usersTmp as $user) {
if ($user->isEnabled()) { // Don't keep deactivated users
$users[(string) $user->getUID()] = $user->getDisplayName();
$users[$user->getUID()] = $user;

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

$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;
}
Expand Down Expand Up @@ -156,7 +163,10 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {

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);
}

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

$type = new SearchResultType('users');
$searchResult->addResultSet($type, $result['wide'], $result['exact']);
if (count($result['exact'])) {
$searchResult->markExactIdMatch($type);
}

return $hasMoreResults;
}
Expand Down
Loading

0 comments on commit 01c147a

Please sign in to comment.