Skip to content

Commit

Permalink
Do not remove current user on findOne
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Oct 20, 2021
1 parent 873e8e2 commit 5e23800
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
28 changes: 14 additions & 14 deletions lib/private/Contacts/ContactsMenu/ContactsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,18 @@ public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offs
$options
);

$userId = $user->getUID();
$contacts = array_filter($allContacts, function ($contact) use ($userId) {
// When searching for multiple results, we strip out the current user
if (array_key_exists('UID', $contact)) {
return $contact['UID'] !== $userId;
}
return true;
});

$entries = array_map(function (array $contact) {
return $this->contactArrayToEntry($contact);
}, $allContacts);
}, $contacts);
return $this->filterContacts(
$user,
$entries,
Expand All @@ -125,12 +134,11 @@ public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offs

/**
* Filters the contacts. Applied filters:
* 1. filter the current user
* 2. if the `shareapi_allow_share_dialog_user_enumeration` config option is
* 1. if the `shareapi_allow_share_dialog_user_enumeration` config option is
* enabled it will filter all local users
* 3. if the `shareapi_exclude_groups` config option is enabled and the
* 2. if the `shareapi_exclude_groups` config option is enabled and the
* current user is in an excluded group it will filter all local users.
* 4. if the `shareapi_only_share_with_group_members` config option is
* 3. if the `shareapi_only_share_with_group_members` config option is
* enabled it will filter all users which doens't have a common group
* with the current user.
*
Expand Down Expand Up @@ -171,10 +179,6 @@ private function filterContacts(
$selfUID = $self->getUID();

return array_values(array_filter($entries, function (IEntry $entry) use ($skipLocal, $ownGroupsOnly, $selfGroups, $selfUID, $disallowEnumeration, $restrictEnumerationGroup, $restrictEnumerationPhone, $allowEnumerationFullMatch, $filter) {
if ($entry->getProperty('UID') === $selfUID) {
return false;
}

if ($entry->getProperty('isLocalSystemBook')) {
if ($skipLocal) {
return false;
Expand Down Expand Up @@ -266,11 +270,7 @@ public function findOne(IUser $user, $shareType, $shareWith) {
return null;
}

$userId = $user->getUID();
$allContacts = $this->contactsManager->search($shareWith, $filter);
$contacts = array_filter($allContacts, function ($contact) use ($userId) {
return $contact['UID'] !== $userId;
});
$contacts = $this->contactsManager->search($shareWith, $filter);
$match = null;

foreach ($contacts as $contact) {
Expand Down
27 changes: 13 additions & 14 deletions tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testGetContactsWithoutFilter() {
],
],
]);
$user->expects($this->once())
$user->expects($this->exactly(2))
->method('getUID')
->willReturn('user123');

Expand Down Expand Up @@ -129,7 +129,7 @@ public function testGetContactsHidesOwnEntry() {
],
],
]);
$user->expects($this->once())
$user->expects($this->exactly(2))
->method('getUID')
->willReturn('user123');

Expand Down Expand Up @@ -157,7 +157,7 @@ public function testGetContactsWithoutBinaryImage() {
'PHOTO' => base64_encode('photophotophoto'),
],
]);
$user->expects($this->once())
$user->expects($this->exactly(2))
->method('getUID')
->willReturn('user123');

Expand Down Expand Up @@ -186,7 +186,7 @@ public function testGetContactsWithoutAvatarURI() {
'PHOTO' => 'VALUE=uri:https://photo',
],
]);
$user->expects($this->once())
$user->expects($this->exactly(2))
->method('getUID')
->willReturn('user123');

Expand All @@ -210,7 +210,7 @@ public function testGetContactsWhenUserIsInExcludeGroups() {

/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->once())
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');

Expand Down Expand Up @@ -253,7 +253,7 @@ public function testGetContactsOnlyShareIfInTheSameGroup() {

/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->once())
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');

Expand Down Expand Up @@ -332,7 +332,7 @@ public function testGetContactsOnlyEnumerateIfInTheSameGroup() {

/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->once())
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');

Expand Down Expand Up @@ -411,7 +411,7 @@ public function testGetContactsOnlyEnumerateIfPhoneBookMatch() {

/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->once())
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');

Expand Down Expand Up @@ -469,7 +469,7 @@ public function testGetContactsOnlyEnumerateIfPhoneBookMatchWithOwnGroupsOnly()

/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->once())
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');

Expand Down Expand Up @@ -555,7 +555,7 @@ public function testGetContactsOnlyEnumerateIfPhoneBookOrSameGroup() {

/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->once())
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');

Expand Down Expand Up @@ -624,7 +624,7 @@ public function testGetContactsOnlyEnumerateIfPhoneBookOrSameGroupInOwnGroupsOnl

/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->once())
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');

Expand Down Expand Up @@ -963,9 +963,8 @@ public function testFindOneNoMatches() {
'isLocalSystemBook' => false
],
]);
$user->expects($this->once())
->method('getUID')
->willReturn('user123');
$user->expects($this->never())
->method('getUID');

$entry = $this->contactsStore->findOne($user, 0, 'a567');

Expand Down

0 comments on commit 5e23800

Please sign in to comment.