mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
fix(Collaboration\UserPlugin): ensure full match is included in results
When searching we need to: 1. check if sharing is limited to groups - if yes only include those - otherwise continue 2. check if there are restrictions to groups or phonebook 3. check if full match is included Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
aca305aeba
commit
5c7ca58a3c
1 changed files with 40 additions and 29 deletions
|
|
@ -63,8 +63,10 @@ class UserPlugin implements ISearchPlugin {
|
|||
$users = [];
|
||||
$hasMoreResults = false;
|
||||
|
||||
$currentUserId = $this->userSession->getUser()->getUID();
|
||||
$currentUserGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
|
||||
/** @var IUser */
|
||||
$currentUser = $this->userSession->getUser();
|
||||
$currentUserId = $currentUser->getUID();
|
||||
$currentUserGroups = $this->groupManager->getUserGroupIds($currentUser);
|
||||
|
||||
// ShareWithGroupOnly filtering
|
||||
$currentUserGroups = array_diff($currentUserGroups, $this->shareWithGroupOnlyExcludeGroupsList);
|
||||
|
|
@ -76,7 +78,7 @@ class UserPlugin implements ISearchPlugin {
|
|||
foreach ($usersInGroup as $userId => $displayName) {
|
||||
$userId = (string)$userId;
|
||||
$user = $this->userManager->get($userId);
|
||||
if (!$user->isEnabled()) {
|
||||
if (!$user?->isEnabled()) {
|
||||
// Ignore disabled users
|
||||
continue;
|
||||
}
|
||||
|
|
@ -86,37 +88,43 @@ class UserPlugin implements ISearchPlugin {
|
|||
$hasMoreResults = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->shareWithGroupOnly && $this->shareeEnumerationPhone) {
|
||||
$usersTmp = $this->userManager->searchKnownUsersByDisplayName($currentUserId, $search, $limit, $offset);
|
||||
if (!empty($usersTmp)) {
|
||||
// not limited to group only sharing
|
||||
if (!$this->shareWithGroupOnly) {
|
||||
if (!$this->shareeEnumerationPhone && !$this->shareeEnumerationInGroupOnly) {
|
||||
// no restrictions, add everything
|
||||
$usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset);
|
||||
foreach ($usersTmp as $user) {
|
||||
if ($user->isEnabled()) { // Don't keep deactivated users
|
||||
$users[$user->getUID()] = $user;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// make sure to add phonebook matches if configured
|
||||
if ($this->shareeEnumerationPhone) {
|
||||
$usersTmp = $this->userManager->searchKnownUsersByDisplayName($currentUserId, $search, $limit, $offset);
|
||||
foreach ($usersTmp as $user) {
|
||||
if ($user->isEnabled()) { // Don't keep deactivated users
|
||||
$users[$user->getUID()] = $user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uasort($users, function ($a, $b) {
|
||||
/**
|
||||
* @var \OC\User\User $a
|
||||
* @var \OC\User\User $b
|
||||
*/
|
||||
return strcasecmp($a->getDisplayName(), $b->getDisplayName());
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Search in all users
|
||||
if ($this->shareeEnumerationPhone) {
|
||||
$usersTmp = $this->userManager->searchKnownUsersByDisplayName($currentUserId, $search, $limit, $offset);
|
||||
} else {
|
||||
$usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset);
|
||||
}
|
||||
foreach ($usersTmp as $user) {
|
||||
if ($user->isEnabled()) { // Don't keep deactivated users
|
||||
$users[$user->getUID()] = $user;
|
||||
// additionally we need to add full matches
|
||||
if ($this->shareeEnumerationFullMatch) {
|
||||
$usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset);
|
||||
foreach ($usersTmp as $user) {
|
||||
if ($user->isEnabled() && mb_strtolower($user->getDisplayName()) === mb_strtolower($search)) {
|
||||
$users[$user->getUID()] = $user;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uasort($users, function (IUser $a, IUser $b) {
|
||||
return strcasecmp($a->getDisplayName(), $b->getDisplayName());
|
||||
});
|
||||
}
|
||||
|
||||
$this->takeOutCurrentUser($users);
|
||||
|
|
@ -149,10 +157,13 @@ class UserPlugin implements ISearchPlugin {
|
|||
|
||||
if (
|
||||
$this->shareeEnumerationFullMatch
|
||||
&& $lowerSearch !== '' && (strtolower($uid) === $lowerSearch
|
||||
|| strtolower($userDisplayName) === $lowerSearch
|
||||
|| ($this->shareeEnumerationFullMatchIgnoreSecondDisplayName && trim(strtolower(preg_replace('/ \(.*\)$/', '', $userDisplayName))) === $lowerSearch)
|
||||
|| ($this->shareeEnumerationFullMatchEmail && strtolower($userEmail ?? '') === $lowerSearch))
|
||||
&& $lowerSearch !== ''
|
||||
&& (
|
||||
strtolower($uid) === $lowerSearch
|
||||
|| strtolower($userDisplayName) === $lowerSearch
|
||||
|| ($this->shareeEnumerationFullMatchIgnoreSecondDisplayName && trim(strtolower(preg_replace('/ \(.*\)$/', '', $userDisplayName))) === $lowerSearch)
|
||||
|| ($this->shareeEnumerationFullMatchEmail && strtolower($userEmail ?? '') === $lowerSearch)
|
||||
)
|
||||
) {
|
||||
if (strtolower($uid) === $lowerSearch) {
|
||||
$foundUserById = true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue