Skip to content

Commit 4ef93bf

Browse files
committed
Add settings to ignore second display name in search
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent 2c04711 commit 4ef93bf

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ public function getForm() {
8989
'restrictUserEnumerationToGroup' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no'),
9090
'restrictUserEnumerationToPhone' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no'),
9191
'restrictUserEnumerationFullMatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes'),
92-
'restrictUserEnumerationFullMatchUserId' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes'),
92+
'shareeEnumerationFullMatchUserId' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes'),
93+
'shareeEnumerationIgnoreSecondDisplayName' => $this->config->getAppValue('core', 'shareapi_ignore_second_display_name', 'no'),
9394
'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(false),
9495
'passwordExcludedGroups' => $excludedPasswordGroupsList,
9596
'passwordExcludedGroupsFeatureEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false),

apps/settings/templates/settings/admin/sharing.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,15 @@
256256
} ?> />
257257
<label for="shareapi_restrict_user_enumeration_full_match_userid"><?php p($l->t('Match username when restricting to full match'));?></label><br />
258258
</p>
259+
<p id="shareapi_ignore_second_display_name_setting" class="double-indent <?php if ($_['shareAPIEnabled'] === 'no' || $_['restrictUserEnumerationFullMatchUserId'] === 'no') {
260+
p('hidden');
261+
}?>">
262+
<input type="checkbox" name="shareapi_ignore_second_display_name" value="1" id="shareapi_ignore_second_display_name" class="checkbox"
263+
<?php if ($_['shareeEnumerationIgnoreSecondDisplayName'] === 'yes') {
264+
print_unescaped('checked="checked"');
265+
} ?> />
266+
<label for="shareapi_ignore_second_display_name"><?php p($l->t('Ignore second display name in parentheses if any. Example: "First display name (second ignored display name)"'));?></label><br />
267+
</p>
259268

260269
<p>
261270
<input type="checkbox" id="publicShareDisclaimer" class="checkbox noJSAutoUpdate"

apps/settings/tests/Settings/Admin/SharingTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function testGetFormWithoutExcludedGroups(): void {
8383
['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
8484
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
8585
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
86+
['core', 'shareapi_ignore_second_display_name', 'yes', 'yes'],
8687
['core', 'shareapi_enabled', 'yes', 'yes'],
8788
['core', 'shareapi_default_expire_date', 'no', 'no'],
8889
['core', 'shareapi_expire_after_n_days', '7', '7'],
@@ -116,6 +117,7 @@ public function testGetFormWithoutExcludedGroups(): void {
116117
'restrictUserEnumerationToGroup' => 'no',
117118
'restrictUserEnumerationToPhone' => 'no',
118119
'restrictUserEnumerationFullMatch' => 'yes',
120+
'shareeEnumerationIgnoreSecondDisplayName' => 'yes',
119121
'enforceLinkPassword' => false,
120122
'onlyShareWithGroupMembers' => false,
121123
'shareAPIEnabled' => 'yes',
@@ -158,6 +160,7 @@ public function testGetFormWithExcludedGroups(): void {
158160
['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
159161
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
160162
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
163+
['core', 'shareapi_ignore_second_display_name', 'yes', 'yes'],
161164
['core', 'shareapi_enabled', 'yes', 'yes'],
162165
['core', 'shareapi_default_expire_date', 'no', 'no'],
163166
['core', 'shareapi_expire_after_n_days', '7', '7'],
@@ -191,6 +194,7 @@ public function testGetFormWithExcludedGroups(): void {
191194
'restrictUserEnumerationToGroup' => 'no',
192195
'restrictUserEnumerationToPhone' => 'no',
193196
'restrictUserEnumerationFullMatch' => 'yes',
197+
'shareeEnumerationIgnoreSecondDisplayName' => 'yes',
194198
'enforceLinkPassword' => false,
195199
'onlyShareWithGroupMembers' => false,
196200
'shareAPIEnabled' => 'yes',

build/integration/features/bootstrap/CollaborationContext.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ protected function resetAppConfigs(): void {
123123
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_to_phone');
124124
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match');
125125
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match_userid');
126+
$this->deleteServerConfig('core', 'shareapi_ignore_second_display_name');
126127
$this->deleteServerConfig('core', 'shareapi_only_share_with_group_members');
127128
}
128129

lib/private/Collaboration/Collaborators/UserPlugin.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class UserPlugin implements ISearchPlugin {
5656
protected $shareeEnumerationFullMatch;
5757
/* @var bool */
5858
protected $shareeEnumerationFullMatchUserId;
59+
/* @var bool */
60+
protected $shareeEnumerationIgnoreSecondDisplayName;
5961

6062
/** @var IConfig */
6163
private $config;
@@ -90,6 +92,7 @@ public function __construct(IConfig $config,
9092
$this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
9193
$this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
9294
$this->shareeEnumerationFullMatchUserId = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes') === 'yes';
95+
$this->shareeEnumerationIgnoreSecondDisplayName = $this->config->getAppValue('core', 'shareapi_ignore_second_display_name', 'no') === 'yes';
9396
}
9497

9598
public function search($search, $limit, $offset, ISearchResult $searchResult) {
@@ -181,6 +184,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
181184
$this->shareeEnumerationFullMatch &&
182185
$lowerSearch !== '' && (strtolower($uid) === $lowerSearch ||
183186
strtolower($userDisplayName) === $lowerSearch ||
187+
($this->shareeEnumerationIgnoreSecondDisplayName && strtolower(preg_replace('/ (.*)$/', '', $userDisplayName)) === $lowerSearch) ||
184188
strtolower($userEmail ?? '') === $lowerSearch)
185189
) {
186190
if (strtolower($uid) === $lowerSearch) {

0 commit comments

Comments
 (0)