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
diff options
context:
space:
mode:
-rw-r--r--apps/dav/lib/Connector/Sabre/Principal.php9
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php4
-rw-r--r--apps/settings/lib/Settings/Admin/Sharing.php3
-rw-r--r--apps/settings/tests/Settings/Admin/SharingTest.php12
-rw-r--r--build/integration/features/bootstrap/CollaborationContext.php3
-rw-r--r--lib/private/Collaboration/Collaborators/MailPlugin.php7
-rw-r--r--lib/private/Collaboration/Collaborators/UserPlugin.php14
-rw-r--r--lib/private/Share20/Manager.php8
-rw-r--r--lib/public/Share/IManager.php16
-rw-r--r--tests/lib/Collaboration/Collaborators/UserPluginTest.php151
10 files changed, 204 insertions, 23 deletions
diff --git a/apps/dav/lib/Connector/Sabre/Principal.php b/apps/dav/lib/Connector/Sabre/Principal.php
index e696659b338..e597b52f84f 100644
--- a/apps/dav/lib/Connector/Sabre/Principal.php
+++ b/apps/dav/lib/Connector/Sabre/Principal.php
@@ -265,6 +265,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
@@ -293,7 +295,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 = [];
@@ -344,8 +346,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 = [];
diff --git a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
index 39bb41688dc..b9dd5be1843 100644
--- a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
@@ -633,6 +633,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');
diff --git a/apps/settings/lib/Settings/Admin/Sharing.php b/apps/settings/lib/Settings/Admin/Sharing.php
index f4c44d49ef8..072f3d12fe4 100644
--- a/apps/settings/lib/Settings/Admin/Sharing.php
+++ b/apps/settings/lib/Settings/Admin/Sharing.php
@@ -89,6 +89,9 @@ class Sharing implements ISettings {
'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(false),
'passwordExcludedGroups' => $excludedPasswordGroupsList,
'passwordExcludedGroupsFeatureEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false),
+ 'restrictUserEnumerationFullMatchUserId' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes'),
+ 'restrictUserEnumerationFullMatchEmail' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes'),
+ 'restrictUserEnumerationFullMatchIgnoreSecondDN' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no'),
'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(),
'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'),
'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'),
diff --git a/apps/settings/tests/Settings/Admin/SharingTest.php b/apps/settings/tests/Settings/Admin/SharingTest.php
index 983fc04022e..0807add0277 100644
--- a/apps/settings/tests/Settings/Admin/SharingTest.php
+++ b/apps/settings/tests/Settings/Admin/SharingTest.php
@@ -76,6 +76,9 @@ class SharingTest extends TestCase {
['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no', 'no'],
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_default_expire_date', 'no', 'no'],
['core', 'shareapi_expire_after_n_days', '7', '7'],
@@ -106,6 +109,9 @@ class SharingTest extends TestCase {
'restrictUserEnumerationToGroup' => 'no',
'restrictUserEnumerationToPhone' => 'no',
'restrictUserEnumerationFullMatch' => 'yes',
+ 'restrictUserEnumerationFullMatchUserId' => 'yes',
+ 'restrictUserEnumerationFullMatchEmail' => 'yes',
+ 'restrictUserEnumerationFullMatchIgnoreSecondDN' => 'no',
'enforceLinkPassword' => false,
'onlyShareWithGroupMembers' => false,
'shareAPIEnabled' => 'yes',
@@ -147,6 +153,9 @@ class SharingTest extends TestCase {
['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no', 'no'],
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_default_expire_date', 'no', 'no'],
['core', 'shareapi_expire_after_n_days', '7', '7'],
@@ -177,6 +186,9 @@ class SharingTest extends TestCase {
'restrictUserEnumerationToGroup' => 'no',
'restrictUserEnumerationToPhone' => 'no',
'restrictUserEnumerationFullMatch' => 'yes',
+ 'restrictUserEnumerationFullMatchUserId' => 'yes',
+ 'restrictUserEnumerationFullMatchEmail' => 'yes',
+ 'restrictUserEnumerationFullMatchIgnoreSecondDN' => 'no',
'enforceLinkPassword' => false,
'onlyShareWithGroupMembers' => false,
'shareAPIEnabled' => 'yes',
diff --git a/build/integration/features/bootstrap/CollaborationContext.php b/build/integration/features/bootstrap/CollaborationContext.php
index 4ac3b6e3971..8deda86c2c3 100644
--- a/build/integration/features/bootstrap/CollaborationContext.php
+++ b/build/integration/features/bootstrap/CollaborationContext.php
@@ -69,6 +69,9 @@ class CollaborationContext implements Context {
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_to_group');
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_to_phone');
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match');
+ $this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match_userid');
+ $this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match_email');
+ $this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn');
$this->deleteServerConfig('core', 'shareapi_only_share_with_group_members');
}
diff --git a/lib/private/Collaboration/Collaborators/MailPlugin.php b/lib/private/Collaboration/Collaborators/MailPlugin.php
index f588bc4fd73..762d71baab3 100644
--- a/lib/private/Collaboration/Collaborators/MailPlugin.php
+++ b/lib/private/Collaboration/Collaborators/MailPlugin.php
@@ -51,6 +51,8 @@ class MailPlugin implements ISearchPlugin {
protected $shareeEnumerationPhone;
/* @var bool */
protected $shareeEnumerationFullMatch;
+ /* @var bool */
+ protected $shareeEnumerationFullMatchEmail;
/** @var IManager */
private $contactsManager;
@@ -88,12 +90,17 @@ class MailPlugin implements ISearchPlugin {
$this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
$this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
$this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
+ $this->shareeEnumerationFullMatchEmail = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes';
}
/**
* {@inheritdoc}
*/
public function search($search, $limit, $offset, ISearchResult $searchResult) {
+ if ($this->shareeEnumerationFullMatch && !$this->shareeEnumerationFullMatchEmail) {
+ return false;
+ }
+
$currentUserId = $this->userSession->getUser()->getUID();
$result = $userResults = ['wide' => [], 'exact' => []];
diff --git a/lib/private/Collaboration/Collaborators/UserPlugin.php b/lib/private/Collaboration/Collaborators/UserPlugin.php
index 9ed94082f0d..91e3a1ef49e 100644
--- a/lib/private/Collaboration/Collaborators/UserPlugin.php
+++ b/lib/private/Collaboration/Collaborators/UserPlugin.php
@@ -54,6 +54,12 @@ class UserPlugin implements ISearchPlugin {
protected $shareeEnumerationPhone;
/* @var bool */
protected $shareeEnumerationFullMatch;
+ /* @var bool */
+ protected $shareeEnumerationFullMatchUserId;
+ /* @var bool */
+ protected $shareeEnumerationFullMatchEmail;
+ /* @var bool */
+ protected $shareeEnumerationFullMatchIgnoreSecondDisplayName;
/** @var IConfig */
private $config;
@@ -87,6 +93,9 @@ class UserPlugin implements ISearchPlugin {
$this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
$this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
$this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
+ $this->shareeEnumerationFullMatchUserId = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes') === 'yes';
+ $this->shareeEnumerationFullMatchEmail = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes';
+ $this->shareeEnumerationFullMatchIgnoreSecondDisplayName = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no') === 'yes';
}
public function search($search, $limit, $offset, ISearchResult $searchResult) {
@@ -178,7 +187,8 @@ class UserPlugin implements ISearchPlugin {
$this->shareeEnumerationFullMatch &&
$lowerSearch !== '' && (strtolower($uid) === $lowerSearch ||
strtolower($userDisplayName) === $lowerSearch ||
- strtolower($userEmail) === $lowerSearch)
+ ($this->shareeEnumerationFullMatchIgnoreSecondDisplayName && trim(strtolower(preg_replace('/ \(.*\)$/', '', $userDisplayName))) === $lowerSearch) ||
+ ($this->shareeEnumerationFullMatchEmail && strtolower($userEmail) === $lowerSearch))
) {
if (strtolower($uid) === $lowerSearch) {
$foundUserById = true;
@@ -228,7 +238,7 @@ class UserPlugin implements ISearchPlugin {
}
}
- if ($this->shareeEnumerationFullMatch && $offset === 0 && !$foundUserById) {
+ if ($this->shareeEnumerationFullMatch && $this->shareeEnumerationFullMatchUserId && $offset === 0 && !$foundUserById) {
// On page one we try if the search result has a direct hit on the
// user id and if so, we add that to the exact match list
$user = $this->userManager->get($search);
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index e17bb7ee79d..e28f0c38bf3 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -1912,6 +1912,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_dn', 'no') === 'yes';
+ }
+
/**
* Copied from \OC_Util::isSharingDisabledForUser
*
diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php
index bad3af6837f..f1ca9ff8a01 100644
--- a/lib/public/Share/IManager.php
+++ b/lib/public/Share/IManager.php
@@ -450,6 +450,22 @@ interface IManager {
public function allowEnumerationFullMatch(): bool;
/**
+ * Check if the search should match the email
+ *
+ * @return bool
+ * @since 22.2.10
+ */
+ public function matchEmail(): bool;
+
+ /**
+ * Check if the search should ignore the second in parentheses display name if there is any
+ *
+ * @return bool
+ * @since 22.2.10
+ */
+ public function ignoreSecondDisplayName(): bool;
+
+ /**
* Check if sharing is disabled for the given user
*
* @param string $userId
diff --git a/tests/lib/Collaboration/Collaborators/UserPluginTest.php b/tests/lib/Collaboration/Collaborators/UserPluginTest.php
index acbcd42f04f..8987c8be6f6 100644
--- a/tests/lib/Collaboration/Collaborators/UserPluginTest.php
+++ b/tests/lib/Collaboration/Collaborators/UserPluginTest.php
@@ -104,21 +104,12 @@ class UserPluginTest extends TestCase {
);
}
- public function mockConfig($shareWithGroupOnly, $shareeEnumeration, $shareeEnumerationLimitToGroup, $shareeEnumerationPhone = false) {
+ public function mockConfig($mockedSettings) {
$this->config->expects($this->any())
->method('getAppValue')
->willReturnCallback(
- function ($appName, $key, $default) use ($shareWithGroupOnly, $shareeEnumeration, $shareeEnumerationLimitToGroup, $shareeEnumerationPhone) {
- if ($appName === 'core' && $key === 'shareapi_only_share_with_group_members') {
- return $shareWithGroupOnly ? 'yes' : 'no';
- } elseif ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
- return $shareeEnumeration ? 'yes' : 'no';
- } elseif ($appName === 'core' && $key === 'shareapi_restrict_user_enumeration_to_group') {
- return $shareeEnumerationLimitToGroup ? 'yes' : 'no';
- } elseif ($appName === 'core' && $key === 'shareapi_restrict_user_enumeration_to_phone') {
- return $shareeEnumerationPhone ? 'yes' : 'no';
- }
- return $default;
+ function ($appName, $key, $default) use ($mockedSettings) {
+ return $mockedSettings[$appName][$key] ?? $default;
}
);
}
@@ -470,7 +461,13 @@ class UserPluginTest extends TestCase {
array $users = [],
$shareeEnumerationPhone = false
) {
- $this->mockConfig($shareWithGroupOnly, $shareeEnumeration, false, $shareeEnumerationPhone);
+ $this->mockConfig(["core" => [
+ 'shareapi_only_share_with_group_members' => $shareWithGroupOnly ? 'yes' : 'no',
+ 'shareapi_allow_share_dialog_user_enumeration' => $shareeEnumeration? 'yes' : 'no',
+ 'shareapi_restrict_user_enumeration_to_group' => false ? 'yes' : 'no',
+ 'shareapi_restrict_user_enumeration_to_phone' => $shareeEnumerationPhone ? 'yes' : 'no',
+ ]]);
+
$this->instantiatePlugin();
$this->session->expects($this->any())
@@ -586,6 +583,83 @@ class UserPluginTest extends TestCase {
['uid' => 'test2', 'groups' => ['groupB']],
],
['exact' => [], 'wide' => ['test1']],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
+ ],
+ [
+ 'test',
+ ['groupA'],
+ [
+ ['uid' => 'test1', 'displayName' => 'Test user 1', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'displayName' => 'Test user 2', 'groups' => ['groupA']],
+ ],
+ ['exact' => [], 'wide' => []],
+ ['core' => ['shareapi_allow_share_dialog_user_enumeration' => 'no']],
+ ],
+ [
+ 'test1',
+ ['groupA'],
+ [
+ ['uid' => 'test1', 'displayName' => 'Test user 1', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'displayName' => 'Test user 2', 'groups' => ['groupA']],
+ ],
+ ['exact' => ['test1'], 'wide' => []],
+ ['core' => ['shareapi_allow_share_dialog_user_enumeration' => 'no']],
+ ],
+ [
+ 'test1',
+ ['groupA'],
+ [
+ ['uid' => 'test1', 'displayName' => 'Test user 1', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'displayName' => 'Test user 2', 'groups' => ['groupA']],
+ ],
+ ['exact' => [], 'wide' => []],
+ [
+ 'core' => [
+ 'shareapi_allow_share_dialog_user_enumeration' => 'no',
+ 'shareapi_restrict_user_enumeration_full_match_userid' => 'no',
+ ],
+ ]
+ ],
+ [
+ 'Test user 1',
+ ['groupA'],
+ [
+ ['uid' => 'test1', 'displayName' => 'Test user 1', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'displayName' => 'Test user 2', 'groups' => ['groupA']],
+ ],
+ ['exact' => ['test1'], 'wide' => []],
+ [
+ 'core' => [
+ 'shareapi_allow_share_dialog_user_enumeration' => 'no',
+ 'shareapi_restrict_user_enumeration_full_match_userid' => 'no',
+ ],
+ ]
+ ],
+ [
+ 'Test user 1',
+ ['groupA'],
+ [
+ ['uid' => 'test1', 'displayName' => 'Test user 1 (Second displayName for user 1)', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'displayName' => 'Test user 2 (Second displayName for user 2)', 'groups' => ['groupA']],
+ ],
+ ['exact' => [], 'wide' => []],
+ ['core' => ['shareapi_allow_share_dialog_user_enumeration' => 'no'],
+ ]
+ ],
+ [
+ 'Test user 1',
+ ['groupA'],
+ [
+ ['uid' => 'test1', 'displayName' => 'Test user 1 (Second displayName for user 1)', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'displayName' => 'Test user 2 (Second displayName for user 2)', 'groups' => ['groupA']],
+ ],
+ ['exact' => ['test1'], 'wide' => []],
+ [
+ 'core' => [
+ 'shareapi_allow_share_dialog_user_enumeration' => 'no',
+ 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn' => 'yes',
+ ],
+ ]
],
[
'test1',
@@ -595,6 +669,7 @@ class UserPluginTest extends TestCase {
['uid' => 'test2', 'groups' => ['groupB']],
],
['exact' => ['test1'], 'wide' => []],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
],
[
'test',
@@ -604,6 +679,7 @@ class UserPluginTest extends TestCase {
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
['exact' => [], 'wide' => ['test1', 'test2']],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
],
[
'test',
@@ -613,6 +689,7 @@ class UserPluginTest extends TestCase {
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
['exact' => [], 'wide' => ['test1', 'test2']],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
],
[
'test',
@@ -622,6 +699,7 @@ class UserPluginTest extends TestCase {
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
['exact' => [], 'wide' => ['test1', 'test2']],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
],
[
'test',
@@ -631,6 +709,7 @@ class UserPluginTest extends TestCase {
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
['exact' => [], 'wide' => []],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
],
[
'test',
@@ -640,6 +719,7 @@ class UserPluginTest extends TestCase {
['uid' => 'test2', 'groups' => []],
],
['exact' => [], 'wide' => []],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
],
[
'test',
@@ -649,6 +729,7 @@ class UserPluginTest extends TestCase {
['uid' => 'test2', 'groups' => []],
],
['exact' => [], 'wide' => []],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
],
];
}
@@ -656,19 +737,38 @@ class UserPluginTest extends TestCase {
/**
* @dataProvider dataSearchEnumeration
*/
- public function testSearchEnumerationLimit($search, $userGroups, $matchingUsers, $result) {
- $this->mockConfig(false, true, true);
+ public function testSearchEnumerationLimit($search, $userGroups, $matchingUsers, $result, $mockedSettings) {
+ $this->mockConfig($mockedSettings);
$userResults = [];
foreach ($matchingUsers as $user) {
$userResults[$user['uid']] = $user['uid'];
}
- $mappedResultExact = array_map(function ($user) {
- return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => $user];
+ $usersById = [];
+ foreach ($matchingUsers as $user) {
+ $usersById[$user['uid']] = $user;
+ }
+
+ $mappedResultExact = array_map(function ($user) use ($usersById, $search) {
+ return [
+ 'label' => $search === $user ? $user : $usersById[$user]['displayName'],
+ 'value' => ['shareType' => 0, 'shareWith' => $user],
+ 'icon' => 'icon-user',
+ 'subline' => null,
+ 'status' => [],
+ 'shareWithDisplayNameUnique' => $user,
+ ];
}, $result['exact']);
$mappedResultWide = array_map(function ($user) {
- return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => $user];
+ return [
+ 'label' => $user,
+ 'value' => ['shareType' => 0, 'shareWith' => $user],
+ 'icon' => 'icon-user',
+ 'subline' => null,
+ 'status' => [],
+ 'shareWithDisplayNameUnique' => $user,
+ ];
}, $result['wide']);
$this->userManager
@@ -679,6 +779,21 @@ class UserPluginTest extends TestCase {
}
return null;
});
+ $this->userManager
+ ->method('searchDisplayName')
+ ->willReturnCallback(function ($search) use ($matchingUsers) {
+ $users = array_filter(
+ $matchingUsers,
+ function ($user) use ($search) {
+ return str_contains(strtolower($user['displayName']), strtolower($search));
+ });
+ return array_map(
+ function ($user) {
+ return $this->getUserMock($user['uid'], $user['displayName']);
+ },
+ $users
+ );
+ });
$this->groupManager->method('displayNamesInGroup')
->willReturn($userResults);