From 2249bb68fccdf7fb18960a950fb22ba0f35d0a8d Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Mon, 11 Apr 2022 18:27:59 +0200 Subject: [PATCH] Add settings to ignore second display name in search Signed-off-by: Louis Chemineau --- apps/settings/lib/Settings/Admin/Sharing.php | 3 ++- apps/settings/templates/settings/admin/sharing.php | 9 +++++++++ apps/settings/tests/Settings/Admin/SharingTest.php | 4 ++++ .../features/bootstrap/CollaborationContext.php | 1 + lib/private/Collaboration/Collaborators/UserPlugin.php | 4 ++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/apps/settings/lib/Settings/Admin/Sharing.php b/apps/settings/lib/Settings/Admin/Sharing.php index d2c3e907b3e86..74e232b4686f1 100644 --- a/apps/settings/lib/Settings/Admin/Sharing.php +++ b/apps/settings/lib/Settings/Admin/Sharing.php @@ -89,7 +89,8 @@ public function getForm() { 'restrictUserEnumerationToGroup' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no'), 'restrictUserEnumerationToPhone' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no'), 'restrictUserEnumerationFullMatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes'), - 'restrictUserEnumerationFullMatchUserId' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes'), + 'shareeEnumerationFullMatchUserId' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes'), + 'shareeEnumerationIgnoreSecondDisplayName' => $this->config->getAppValue('core', 'shareapi_ignore_second_display_name', 'no'), 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(false), 'passwordExcludedGroups' => $excludedPasswordGroupsList, 'passwordExcludedGroupsFeatureEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false), diff --git a/apps/settings/templates/settings/admin/sharing.php b/apps/settings/templates/settings/admin/sharing.php index 09918d4bc6432..053f90398b782 100644 --- a/apps/settings/templates/settings/admin/sharing.php +++ b/apps/settings/templates/settings/admin/sharing.php @@ -256,6 +256,15 @@ } ?> />

+

+ /> +
+

'no', 'restrictUserEnumerationToPhone' => 'no', 'restrictUserEnumerationFullMatch' => 'yes', + 'shareeEnumerationIgnoreSecondDisplayName' => 'yes', 'enforceLinkPassword' => false, 'onlyShareWithGroupMembers' => false, 'shareAPIEnabled' => 'yes', @@ -158,6 +160,7 @@ public function testGetFormWithExcludedGroups(): void { ['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_ignore_second_display_name', 'yes', 'yes'], ['core', 'shareapi_enabled', 'yes', 'yes'], ['core', 'shareapi_default_expire_date', 'no', 'no'], ['core', 'shareapi_expire_after_n_days', '7', '7'], @@ -191,6 +194,7 @@ public function testGetFormWithExcludedGroups(): void { 'restrictUserEnumerationToGroup' => 'no', 'restrictUserEnumerationToPhone' => 'no', 'restrictUserEnumerationFullMatch' => 'yes', + 'shareeEnumerationIgnoreSecondDisplayName' => 'yes', 'enforceLinkPassword' => false, 'onlyShareWithGroupMembers' => false, 'shareAPIEnabled' => 'yes', diff --git a/build/integration/features/bootstrap/CollaborationContext.php b/build/integration/features/bootstrap/CollaborationContext.php index bc01a32f12cf4..6bbf4453c8d1b 100644 --- a/build/integration/features/bootstrap/CollaborationContext.php +++ b/build/integration/features/bootstrap/CollaborationContext.php @@ -123,6 +123,7 @@ protected function resetAppConfigs(): void { $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_ignore_second_display_name'); $this->deleteServerConfig('core', 'shareapi_only_share_with_group_members'); } diff --git a/lib/private/Collaboration/Collaborators/UserPlugin.php b/lib/private/Collaboration/Collaborators/UserPlugin.php index 4d8bc4cbf3ad7..ba08b96c38625 100644 --- a/lib/private/Collaboration/Collaborators/UserPlugin.php +++ b/lib/private/Collaboration/Collaborators/UserPlugin.php @@ -56,6 +56,8 @@ class UserPlugin implements ISearchPlugin { protected $shareeEnumerationFullMatch; /* @var bool */ protected $shareeEnumerationFullMatchUserId; + /* @var bool */ + protected $shareeEnumerationIgnoreSecondDisplayName; /** @var IConfig */ private $config; @@ -90,6 +92,7 @@ public function __construct(IConfig $config, $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->shareeEnumerationIgnoreSecondDisplayName = $this->config->getAppValue('core', 'shareapi_ignore_second_display_name', 'no') === 'yes'; } public function search($search, $limit, $offset, ISearchResult $searchResult) { @@ -181,6 +184,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) { $this->shareeEnumerationFullMatch && $lowerSearch !== '' && (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch || + (strtolower(preg_replace('/ (.*)$/', '', $userDisplayName)) === $lowerSearch && $shareeEnumerationIgnoreSecondDisplayName) || strtolower($userEmail ?? '') === $lowerSearch) ) { if (strtolower($uid) === $lowerSearch) {