Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2019-06-21 16:38:19 +0300
committerRobin Appelman <robin@icewind.nl>2020-05-12 17:30:48 +0300
commite26c055fb45cd548c71253cda7bb0c93b8d11a77 (patch)
tree0a1671baaf5054ce3858cebbe7a8e460428c9232 /lib
parent6b96fe9be5cfcdeba6912362288cfeb20757ef44 (diff)
dont show remote and email options if we have an exact match for local user email
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Collaboration/Collaborators/Search.php7
-rw-r--r--lib/private/Collaboration/Collaborators/UserPlugin.php29
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;
}