Skip to content

Commit 12b97ea

Browse files
committed
Add setting to ignore email during search
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent cd95fce commit 12b97ea

7 files changed

Lines changed: 25 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public function getForm() {
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'),
9292
'restrictUserEnumerationFullMatchUserId' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes'),
93+
'restrictUserEnumerationFullMatchEmail' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes'),
9394
'restrictUserEnumerationFullMatchIgnoreSecondDisplayName' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_display_name', 'no'),
9495
'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(false),
9596
'passwordExcludedGroups' => $excludedPasswordGroupsList,

apps/settings/src/admin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ window.addEventListener('DOMContentLoaded', () => {
157157

158158
$('#shareapi_restrict_user_enumeration_full_match').on('change', function() {
159159
$('#shareapi_restrict_user_enumeration_full_match_userid_setting').toggleClass('hidden', !this.checked)
160+
$('#shareapi_restrict_user_enumeration_full_match_email_setting').toggleClass('hidden', !this.checked)
160161
$('#shareapi_restrict_user_enumeration_full_match_ignore_second_display_name_setting').toggleClass('hidden', !this.checked)
161162
})
162163

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_restrict_user_enumeration_full_match_email_setting" class="double-indent <?php if ($_['shareAPIEnabled'] === 'no' || $_['restrictUserEnumerationFullMatch'] === 'no') {
260+
p('hidden');
261+
}?>">
262+
<input type="checkbox" name="shareapi_restrict_user_enumeration_full_match_email" value="1" id="shareapi_restrict_user_enumeration_full_match_email" class="checkbox"
263+
<?php if ($_['restrictUserEnumerationFullMatchEmail'] === 'yes') {
264+
print_unescaped('checked="checked"');
265+
} ?> />
266+
<label for="shareapi_restrict_user_enumeration_full_match_email"><?php p($l->t('Match email when restricting to full match'));?></label><br />
267+
</p>
259268
<p id="shareapi_restrict_user_enumeration_full_match_ignore_second_display_name_setting" class="double-indent <?php if ($_['shareAPIEnabled'] === 'no' || $_['restrictUserEnumerationFullMatch'] === 'no') {
260269
p('hidden');
261270
}?>">

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function testGetFormWithoutExcludedGroups(): void {
8484
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
8585
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
8686
['core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes', 'yes'],
87+
['core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes', 'yes'],
8788
['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_display_name', 'no', 'no'],
8889
['core', 'shareapi_enabled', 'yes', 'yes'],
8990
['core', 'shareapi_default_expire_date', 'no', 'no'],
@@ -119,6 +120,7 @@ public function testGetFormWithoutExcludedGroups(): void {
119120
'restrictUserEnumerationToPhone' => 'no',
120121
'restrictUserEnumerationFullMatch' => 'yes',
121122
'restrictUserEnumerationFullMatchUserId' => 'yes',
123+
'restrictUserEnumerationFullMatchEmail' => 'yes',
122124
'restrictUserEnumerationFullMatchIgnoreSecondDisplayName' => 'no',
123125
'enforceLinkPassword' => false,
124126
'onlyShareWithGroupMembers' => false,
@@ -163,6 +165,7 @@ public function testGetFormWithExcludedGroups(): void {
163165
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
164166
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
165167
['core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes', 'yes'],
168+
['core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes', 'yes'],
166169
['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_display_name', 'no', 'no'],
167170
['core', 'shareapi_enabled', 'yes', 'yes'],
168171
['core', 'shareapi_default_expire_date', 'no', 'no'],
@@ -198,6 +201,7 @@ public function testGetFormWithExcludedGroups(): void {
198201
'restrictUserEnumerationToPhone' => 'no',
199202
'restrictUserEnumerationFullMatch' => 'yes',
200203
'restrictUserEnumerationFullMatchUserId' => 'yes',
204+
'restrictUserEnumerationFullMatchEmail' => 'yes',
201205
'restrictUserEnumerationFullMatchIgnoreSecondDisplayName' => 'no',
202206
'enforceLinkPassword' => false,
203207
'onlyShareWithGroupMembers' => false,

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_restrict_user_enumeration_full_match_email');
126127
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_display_name');
127128
$this->deleteServerConfig('core', 'shareapi_only_share_with_group_members');
128129
}

lib/private/Collaboration/Collaborators/MailPlugin.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class MailPlugin implements ISearchPlugin {
5151
protected $shareeEnumerationPhone;
5252
/* @var bool */
5353
protected $shareeEnumerationFullMatch;
54+
/* @var bool */
55+
protected $shareeEnumerationFullMatchEmail;
5456

5557
/** @var IManager */
5658
private $contactsManager;
@@ -88,12 +90,17 @@ public function __construct(IManager $contactsManager,
8890
$this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
8991
$this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
9092
$this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
93+
$this->shareeEnumerationFullMatchEmail = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes';
9194
}
9295

9396
/**
9497
* {@inheritdoc}
9598
*/
9699
public function search($search, $limit, $offset, ISearchResult $searchResult) {
100+
if ($this->shareeEnumerationFullMatch && !$this->shareeEnumerationFullMatchEmail) {
101+
return false;
102+
}
103+
97104
$currentUserId = $this->userSession->getUser()->getUID();
98105

99106
$result = $userResults = ['wide' => [], 'exact' => []];

lib/private/Collaboration/Collaborators/UserPlugin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public function __construct(IConfig $config,
9292
$this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
9393
$this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
9494
$this->shareeEnumerationFullMatchUserId = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes') === 'yes';
95+
$this->shareeEnumerationFullMatchEmail = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes';
9596
$this->shareeEnumerationFullMatchIgnoreSecondDisplayName = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_display_name', 'no') === 'yes';
9697
}
9798

@@ -185,7 +186,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
185186
$lowerSearch !== '' && (strtolower($uid) === $lowerSearch ||
186187
strtolower($userDisplayName) === $lowerSearch ||
187188
($this->shareeEnumerationFullMatchIgnoreSecondDisplayName && trim(strtolower(preg_replace('/ \(.*\)$/', '', $userDisplayName))) === $lowerSearch) ||
188-
strtolower($userEmail ?? '') === $lowerSearch)
189+
($this->shareeEnumerationFullMatchEmail && strtolower($userEmail ?? '') === $lowerSearch))
189190
) {
190191
if (strtolower($uid) === $lowerSearch) {
191192
$foundUserById = true;

0 commit comments

Comments
 (0)