Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions lib/Service/ContactsIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getMatchingRecipient(string $userId, string $term): array {
$shareeEnumerationFullMatchUserId = $shareeEnumerationFullMatch && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes') === 'yes';
$shareeEnumerationFullMatchEmail = $shareeEnumerationFullMatch && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes';

$result = $this->contactsManager->search($term, ['UID', 'FN', 'EMAIL'], ['enumeration' => $shareeEnumeration]);
$result = $this->contactsManager->search($term, ['UID', 'FN', 'EMAIL'], ['enumeration' => $shareeEnumeration, 'fullmatch' => $shareeEnumerationFullMatch]);
if (empty($result)) {
return [];
}
Expand Down Expand Up @@ -118,18 +118,25 @@ public function getMatchingRecipient(string $userId, string $term): array {
continue;
}
$lowerTerm = strtolower($term);
if (!$isSystemUser || $isInSameGroup || ($lowerTerm !== '' && (
($shareeEnumerationFullMatch && !empty($fn) && $lowerTerm === strtolower($fn)) ||
($shareeEnumerationFullMatchUserId && $lowerTerm === strtolower($id)) ||
($shareeEnumerationFullMatchEmail && $lowerTerm === strtolower($e))))) {
$receivers[] = [
'id' => $id,
// Show full name if possible or fall back to email
'label' => (empty($fn) ? $e : "$fn ($e)"),
'email' => $e,
'photo' => $photo,
];

if ($isSystemUser && $shareeEnumerationInGroupOnly && !$isInSameGroup) {
// Check for full match. If full match is disabled, matching results already filtered out
if (!($lowerTerm !== '' && (
($shareeEnumerationFullMatch && !empty($fn) && $lowerTerm === strtolower($fn)) ||
($shareeEnumerationFullMatchUserId && $lowerTerm === strtolower($id)) ||
($shareeEnumerationFullMatchEmail && $lowerTerm === strtolower($e))))) {
// Not a full Match
continue;
}
}

$receivers[] = [
'id' => $id,
// Show full name if possible or fall back to email
'label' => (empty($fn) ? $e : "$fn ($e)"),
'email' => $e,
'photo' => $photo,
];
}
}

Expand Down
179 changes: 93 additions & 86 deletions tests/Unit/Service/ContactsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function testGetMatchingRecipientRestrictedToGroup() {
],
];

$this->common($term, $searchResult, true, true, false, false);
$this->common($term, $searchResult, true, true, false, false, false);
$user = $this->createMock(IUser::class);
$this->userManager->expects($this->once())
->method('get')
Expand Down Expand Up @@ -191,150 +191,157 @@ public function testGetMatchingRecipientRestrictedToGroup() {
$this->assertEquals($expected, $actual);
}

public function testGetMatchingRecipientRestrictedToFullMatch() {
$term = 'jo'; // searching for: John Doe
public function testGetMatchingRecipientRestrictedToGroupFullMatchUserId() {
$term = 'jf'; // searching for: Jonathan Frakes
$searchResult = [
[
// Simple match
'UID' => 'jf',
'FN' => 'Jonathan Frakes',
'EMAIL' => 'jonathan@frakes.com',
'isLocalSystemBook' => true,
],
[
'UID' => 'jd',
'FN' => 'John Doe',
'EMAIL' => [
'john@doe.info',
'doe@john.info',
],
'isLocalSystemBook' => true,
],
[
'UID' => 'js',
'FN' => 'Johann Strauss II',
'EMAIL' => 'johann@strauss.com',
],
];
$this->common($term, $searchResult, true, false, true);

$this->common($term, $searchResult, true, true, true);
$user = $this->createMock(IUser::class);
$this->userManager->expects($this->once())
->method('get')
->with('auser')
->will($this->returnValue($user));
$this->groupManager->expects($this->once())
->method('getUserGroupIds')
->will($this->returnValue(['agroup']));
$this->groupManager->expects(self::exactly(1))
->method('isInGroup')
->withConsecutive(['jf', 'agroup'])
->willReturnOnConsecutiveCalls(false);

$expected = [
[
'id' => 'js',
'label' => 'Johann Strauss II (johann@strauss.com)',
'email' => 'johann@strauss.com',
'id' => 'jf',
'label' => 'Jonathan Frakes (jonathan@frakes.com)',
'email' => 'jonathan@frakes.com',
'photo' => null,
],
];

$actual = $this->contactsIntegration->getMatchingRecipient("", $term);
$actual = $this->contactsIntegration->getMatchingRecipient("auser", $term);

$this->assertEquals($expected, $actual);
}

public function testGetMatchingRecipientRestrictedToFullMatchFullName() {
$term = 'john doe'; // searching for: John Doe
public function testGetMatchingRecipientRestrictedToGroupFullMatchFullName() {
$term = 'Jonathan Frakes'; // searching for: Jonathan Frakes
$searchResult = [
[
// Array of addresses
'UID' => 'jd',
'FN' => 'John Doe',
'EMAIL' => [
'john@doe.info',
'doe@john.info',
],
// Simple match
'UID' => 'jf',
'FN' => 'Jonathan Frakes',
'EMAIL' => 'jonathan@frakes.com',
'isLocalSystemBook' => true,
]
],
];

$this->common($term, $searchResult, true, false, true);
$this->common($term, $searchResult, true, true, true);
$user = $this->createMock(IUser::class);
$this->userManager->expects($this->once())
->method('get')
->with('auser')
->will($this->returnValue($user));
$this->groupManager->expects($this->once())
->method('getUserGroupIds')
->will($this->returnValue(['agroup']));
$this->groupManager->expects(self::exactly(1))
->method('isInGroup')
->withConsecutive(['jf', 'agroup'])
->willReturnOnConsecutiveCalls(false);

$expected = [
[
'id' => 'jd',
'label' => 'John Doe (john@doe.info)',
'email' => 'john@doe.info',
'photo' => null,
],
[
'id' => 'jd',
'label' => 'John Doe (doe@john.info)',
'email' => 'doe@john.info',
'id' => 'jf',
'label' => 'Jonathan Frakes (jonathan@frakes.com)',
'email' => 'jonathan@frakes.com',
'photo' => null,
],
];

$actual = $this->contactsIntegration->getMatchingRecipient("", $term);
$actual = $this->contactsIntegration->getMatchingRecipient("auser", $term);

$this->assertEquals($expected, $actual);
}

public function testGetMatchingRecipientRestrictedToFullMatchUserId() {
$term = 'jd'; // searching for: John Doe
public function testGetMatchingRecipientRestrictedToGroupFullMatchEmail() {
$term = 'jonathan@frakes.com'; // searching for: Jonathan Frakes
$searchResult = [
[
// Array of addresses
'UID' => 'jd',
'FN' => 'John Doe',
'EMAIL' => [
'john@doe.info',
'doe@john.info',
],
// Simple match
'UID' => 'jf',
'FN' => 'Jonathan Frakes',
'EMAIL' => 'jonathan@frakes.com',
'isLocalSystemBook' => true,
]
],
];

$this->common($term, $searchResult, true, false, true);
$this->common($term, $searchResult, true, true, true);
$user = $this->createMock(IUser::class);
$this->userManager->expects($this->once())
->method('get')
->with('auser')
->will($this->returnValue($user));
$this->groupManager->expects($this->once())
->method('getUserGroupIds')
->will($this->returnValue(['agroup']));
$this->groupManager->expects(self::exactly(1))
->method('isInGroup')
->withConsecutive(['jf', 'agroup'])
->willReturnOnConsecutiveCalls(false);

$expected = [
[
'id' => 'jd',
'label' => 'John Doe (john@doe.info)',
'email' => 'john@doe.info',
'photo' => null,
],
[
'id' => 'jd',
'label' => 'John Doe (doe@john.info)',
'email' => 'doe@john.info',
'id' => 'jf',
'label' => 'Jonathan Frakes (jonathan@frakes.com)',
'email' => 'jonathan@frakes.com',
'photo' => null,
],
];

$actual = $this->contactsIntegration->getMatchingRecipient("", $term);
$actual = $this->contactsIntegration->getMatchingRecipient("auser", $term);

$this->assertEquals($expected, $actual);
}

public function testGetMatchingRecipientRestrictedToGroupFullMatchFalse() {
$term = 'jf'; // searching for: Jonathan Frakes


public function testGetMatchingRecipientRestrictedToFullMatchEmail() {
$term = 'doe@john.info'; // searching for: John Doe
$searchResult = [
[
// Array of addresses
'UID' => 'jd',
'FN' => 'John Doe',
'EMAIL' => [
'john@doe.info',
'doe@john.info',
],
// Simple match
'UID' => 'jf',
'FN' => 'Jonathan Frakes',
'EMAIL' => 'jonathan@frakes.com',
'isLocalSystemBook' => true,
]
],
];

$this->common($term, $searchResult, true, false, true);
$this->common($term, $searchResult, true, true, false, false, false);

$expected = [
[
'id' => 'jd',
'label' => 'John Doe (doe@john.info)',
'email' => 'doe@john.info',
'photo' => null,
],
];
$user = $this->createMock(IUser::class);
$this->userManager->expects($this->once())
->method('get')
->with('auser')
->will($this->returnValue($user));
$this->groupManager->expects($this->once())
->method('getUserGroupIds')
->will($this->returnValue(['agroup']));
$this->groupManager->expects(self::exactly(1))
->method('isInGroup')
->withConsecutive(['jf', 'agroup'])
->willReturnOnConsecutiveCalls(false);

$actual = $this->contactsIntegration->getMatchingRecipient("", $term);
$expected = [];

$actual = $this->contactsIntegration->getMatchingRecipient("auser", $term);
$this->assertEquals($expected, $actual);
}

Expand All @@ -359,7 +366,7 @@ public function common($term, $searchResult, $allowSystemUsers, $allowSystemUser
->will($this->returnValue(true));
$this->contactsManager->expects($this->once())
->method('search')
->with($term, ['UID', 'FN', 'EMAIL'], ['enumeration' => $allowSystemUsers])
->with($term, ['UID', 'FN', 'EMAIL'], ['enumeration' => $allowSystemUsers, 'fullmatch' => $shareeEnumerationFullMatch])
->will($this->returnValue($searchResult));
}

Expand Down