mirror of
https://github.com/nextcloud/server.git
synced 2026-04-29 18:11:41 -04:00
Merge pull request #31963 from nextcloud/feat/use_setting_in_dav_search
Use share setting in DAV search
This commit is contained in:
commit
7ccfddbe64
4 changed files with 34 additions and 3 deletions
|
|
@ -270,6 +270,8 @@ class Principal implements BackendInterface {
|
|||
$limitEnumerationGroup = $this->shareManager->limitEnumerationToGroups();
|
||||
$limitEnumerationPhone = $this->shareManager->limitEnumerationToPhone();
|
||||
$allowEnumerationFullMatch = $this->shareManager->allowEnumerationFullMatch();
|
||||
$ignoreSecondDisplayName = $this->shareManager->ignoreSecondDisplayName();
|
||||
$matchEmail = $this->shareManager->matchEmail();
|
||||
|
||||
// If sharing is restricted to group members only,
|
||||
// return only members that have groups in common
|
||||
|
|
@ -298,7 +300,7 @@ class Principal implements BackendInterface {
|
|||
switch ($prop) {
|
||||
case '{http://sabredav.org/ns}email-address':
|
||||
if (!$allowEnumeration) {
|
||||
if ($allowEnumerationFullMatch) {
|
||||
if ($allowEnumerationFullMatch && $matchEmail) {
|
||||
$users = $this->userManager->getByEmail($value);
|
||||
} else {
|
||||
$users = [];
|
||||
|
|
@ -349,8 +351,9 @@ class Principal implements BackendInterface {
|
|||
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 = [];
|
||||
|
|
|
|||
|
|
@ -662,6 +662,10 @@ class PrincipalTest extends TestCase {
|
|||
->method('allowEnumerationFullMatch')
|
||||
->willReturn(true);
|
||||
|
||||
$this->shareManager->expects($this->once())
|
||||
->method('matchEmail')
|
||||
->willReturn(true);
|
||||
|
||||
$user2 = $this->createMock(IUser::class);
|
||||
$user2->method('getUID')->willReturn('user2');
|
||||
$user2->method('getDisplayName')->willReturn('User 2');
|
||||
|
|
|
|||
|
|
@ -1963,6 +1963,14 @@ class Manager implements IManager {
|
|||
return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
|
||||
}
|
||||
|
||||
public function matchEmail(): bool {
|
||||
return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', '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;
|
||||
|
|
|
|||
|
|
@ -454,6 +454,22 @@ interface IManager {
|
|||
*/
|
||||
public function allowEnumerationFullMatch(): bool;
|
||||
|
||||
/**
|
||||
* Check if the search should match the email
|
||||
*
|
||||
* @return bool
|
||||
* @since 25.0.0
|
||||
*/
|
||||
public function matchEmail(): bool;
|
||||
|
||||
/**
|
||||
* Check if the search should ignore the second in parentheses display name if there is any
|
||||
*
|
||||
* @return bool
|
||||
* @since 25.0.0
|
||||
*/
|
||||
public function ignoreSecondDisplayName(): bool;
|
||||
|
||||
/**
|
||||
* Check if the current user can enumerate the target user
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue