Skip to content

Commit 7d510d1

Browse files
committed
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>
1 parent 620614e commit 7d510d1

File tree

2 files changed

+44
-31
lines changed

2 files changed

+44
-31
lines changed

apps/settings/lib/Settings/Admin/Sharing.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function getForm() {
3737
$excludedPasswordGroups = $this->config->getAppValue('core', 'shareapi_enforce_links_password_excluded_groups', '');
3838
$onlyShareWithGroupMembersExcludeGroupList = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members_exclude_group_list', '');
3939

40+
/** @var \OC\Share20\Manager */
41+
$share20Manager = $this->shareManager;
4042
$parameters = [
4143
// Built-In Sharing
4244
'enabled' => $this->getHumanBooleanConfig('core', 'shareapi_enabled', true),
@@ -49,7 +51,7 @@ public function getForm() {
4951
'restrictUserEnumerationToGroup' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_group'),
5052
'restrictUserEnumerationToPhone' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_phone'),
5153
'restrictUserEnumerationFullMatch' => $this->shareManager->allowEnumerationFullMatch(),
52-
'restrictUserEnumerationFullMatchUserId' => $this->shareManager->matchUserId(),
54+
'restrictUserEnumerationFullMatchUserId' => $share20Manager->matchUserId(),
5355
'restrictUserEnumerationFullMatchEmail' => $this->shareManager->matchEmail(),
5456
'restrictUserEnumerationFullMatchIgnoreSecondDN' => $this->shareManager->ignoreSecondDisplayName(),
5557
'enforceLinksPassword' => Util::isPublicLinkPasswordRequired(false),

lib/private/Collaboration/Collaborators/UserPlugin.php

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
6262
$users = [];
6363
$hasMoreResults = false;
6464

65-
$currentUserId = $this->userSession->getUser()->getUID();
66-
$currentUserGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
65+
/** @var IUser */
66+
$currentUser = $this->userSession->getUser();
67+
$currentUserId = $currentUser->getUID();
68+
$currentUserGroups = $this->groupManager->getUserGroupIds($currentUser);
6769

6870
// ShareWithGroupOnly filtering
6971
$currentUserGroups = array_diff($currentUserGroups, $this->shareWithGroupOnlyExcludeGroupsList);
@@ -75,7 +77,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
7577
foreach ($usersInGroup as $userId => $displayName) {
7678
$userId = (string)$userId;
7779
$user = $this->userManager->get($userId);
78-
if (!$user->isEnabled()) {
80+
if (!$user?->isEnabled()) {
7981
// Ignore disabled users
8082
continue;
8183
}
@@ -85,37 +87,43 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
8587
$hasMoreResults = true;
8688
}
8789
}
90+
}
8891

89-
if (!$this->shareWithGroupOnly && $this->shareeEnumerationPhone) {
90-
$usersTmp = $this->userManager->searchKnownUsersByDisplayName($currentUserId, $search, $limit, $offset);
91-
if (!empty($usersTmp)) {
92+
// not limited to group only sharing
93+
if (!$this->shareWithGroupOnly) {
94+
if (!$this->shareeEnumerationPhone && !$this->shareeEnumerationInGroupOnly) {
95+
// no restrictions, add everything
96+
$usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset);
97+
foreach ($usersTmp as $user) {
98+
if ($user->isEnabled()) { // Don't keep deactivated users
99+
$users[$user->getUID()] = $user;
100+
}
101+
}
102+
} else {
103+
// make sure to add phonebook matches if configured
104+
if ($this->shareeEnumerationPhone) {
105+
$usersTmp = $this->userManager->searchKnownUsersByDisplayName($currentUserId, $search, $limit, $offset);
92106
foreach ($usersTmp as $user) {
93107
if ($user->isEnabled()) { // Don't keep deactivated users
94108
$users[$user->getUID()] = $user;
95109
}
96110
}
97-
98-
uasort($users, function ($a, $b) {
99-
/**
100-
* @var \OC\User\User $a
101-
* @var \OC\User\User $b
102-
*/
103-
return strcasecmp($a->getDisplayName(), $b->getDisplayName());
104-
});
105111
}
106-
}
107-
} else {
108-
// Search in all users
109-
if ($this->shareeEnumerationPhone) {
110-
$usersTmp = $this->userManager->searchKnownUsersByDisplayName($currentUserId, $search, $limit, $offset);
111-
} else {
112-
$usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset);
113-
}
114-
foreach ($usersTmp as $user) {
115-
if ($user->isEnabled()) { // Don't keep deactivated users
116-
$users[$user->getUID()] = $user;
112+
113+
// additionally we need to add full matches
114+
if ($this->shareeEnumerationFullMatch) {
115+
$usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset);
116+
foreach ($usersTmp as $user) {
117+
if ($user->isEnabled() && mb_strtolower($user->getDisplayName()) === mb_strtolower($search)) {
118+
$users[$user->getUID()] = $user;
119+
}
120+
}
117121
}
118122
}
123+
124+
uasort($users, function (IUser $a, IUser $b) {
125+
return strcasecmp($a->getDisplayName(), $b->getDisplayName());
126+
});
119127
}
120128

121129
$this->takeOutCurrentUser($users);
@@ -147,11 +155,14 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
147155

148156

149157
if (
150-
$this->shareeEnumerationFullMatch &&
151-
$lowerSearch !== '' && (strtolower($uid) === $lowerSearch ||
152-
strtolower($userDisplayName) === $lowerSearch ||
153-
($this->shareeEnumerationFullMatchIgnoreSecondDisplayName && trim(strtolower(preg_replace('/ \(.*\)$/', '', $userDisplayName))) === $lowerSearch) ||
154-
($this->shareeEnumerationFullMatchEmail && strtolower($userEmail ?? '') === $lowerSearch))
158+
$this->shareeEnumerationFullMatch
159+
&& $lowerSearch !== ''
160+
&& (
161+
strtolower($uid) === $lowerSearch
162+
|| strtolower($userDisplayName) === $lowerSearch
163+
|| ($this->shareeEnumerationFullMatchIgnoreSecondDisplayName && trim(strtolower(preg_replace('/ \(.*\)$/', '', $userDisplayName))) === $lowerSearch)
164+
|| ($this->shareeEnumerationFullMatchEmail && strtolower($userEmail ?? '') === $lowerSearch)
165+
)
155166
) {
156167
if (strtolower($uid) === $lowerSearch) {
157168
$foundUserById = true;

0 commit comments

Comments
 (0)