Skip to content

Commit

Permalink
Use share setting in DAV search
Browse files Browse the repository at this point in the history
shareapi_restrict_user_enumeration_full_match_ignore_second_display_name was introduced to ignore second display name during search from the share panel. But this setting was not respected by search from the calendar application. This fix it.

Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed May 31, 2022
1 parent bb467e0 commit 883e6b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions apps/dav/lib/Connector/Sabre/Principal.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ protected function searchUserPrincipals(array $searchProperties, $test = 'allof'
$limitEnumerationGroup = $this->shareManager->limitEnumerationToGroups();
$limitEnumerationPhone = $this->shareManager->limitEnumerationToPhone();
$allowEnumerationFullMatch = $this->shareManager->allowEnumerationFullMatch();
$ignoreSecondDisplayName = $this->shareManager->ignoreSecondDisplayName();

// If sharing is restricted to group members only,
// return only members that have groups in common
Expand Down Expand Up @@ -349,8 +350,9 @@ protected function searchUserPrincipals(array $searchProperties, $test = 'allof'
if ($allowEnumerationFullMatch) {
$lowerSearch = strtolower($value);
$users = $this->userManager->searchDisplayName($value, $searchLimit);
$users = \array_filter($users, static function (IUser $user) use ($lowerSearch) {
return strtolower($user->getDisplayName()) === $lowerSearch;
$users = \array_filter($users, static function (IUser $user) use ($lowerSearch, $ignoreSecondDisplayName) {
$lowerDisplayName = strtolower($user->getDisplayName());
return $lowerDisplayName === $lowerSearch || ($ignoreSecondDisplayName && trim(preg_replace('/ \(.*\)$/', '', $lowerDisplayName)) === $lowerSearch);
});
} else {
$users = [];
Expand Down
4 changes: 4 additions & 0 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,10 @@ public function allowEnumerationFullMatch(): bool {
return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
}

public function ignoreSecondDisplayName(): bool {
return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_display_name', 'no') === 'yes';
}

public function currentUserCanEnumerateTargetUser(?IUser $currentUser, IUser $targetUser): bool {
if ($this->allowEnumerationFullMatch()) {
return true;
Expand Down
8 changes: 8 additions & 0 deletions lib/public/Share/IManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,14 @@ public function limitEnumerationToPhone(): bool;
*/
public function allowEnumerationFullMatch(): bool;

/**
* Check if the search should ignore the second in parentheses display name if there is any
*
* @return bool
* @since 24.0.0
*/
public function ignoreSecondDisplayName(): bool;

/**
* Check if the current user can enumerate the target user
*
Expand Down

0 comments on commit 883e6b5

Please sign in to comment.