Make sure to only add system users once

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2017-06-14 15:07:21 +02:00
parent ae693129db
commit 4f98852f52
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
1 changed files with 35 additions and 8 deletions

View File

@ -607,10 +607,11 @@ class ShareesAPIController extends OCSController {
}
foreach ($emailAddresses as $emailAddress) {
$exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) {
if (isset($contact['isLocalSystemBook'])) {
if ($exactEmailMatch) {
$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
if (isset($contact['isLocalSystemBook'])) {
if ($exactEmailMatch) {
$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
if (!$this->hasUserInResult($cloud->getUser())) {
$this->result['exact']['users'][] = [
'label' => $contact['FN'] . " ($emailAddress)",
'value' => [
@ -618,10 +619,12 @@ class ShareesAPIController extends OCSController {
'shareWith' => $cloud->getUser(),
],
];
return ['results' => [], 'exact' => [], 'exactIdMatch' => true];
}
if ($this->shareeEnumeration) {
$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
return ['results' => [], 'exact' => [], 'exactIdMatch' => true];
}
if ($this->shareeEnumeration) {
$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
if (!$this->hasUserInResult($cloud->getUser())) {
$this->result['users'][] = [
'label' => $contact['FN'] . " ($emailAddress)",
'value' => [
@ -630,9 +633,11 @@ class ShareesAPIController extends OCSController {
],
];
}
continue;
}
continue;
}
if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) {
if ($exactEmailMatch) {
$result['exactIdMatch'] = true;
}
@ -711,6 +716,28 @@ class ShareesAPIController extends OCSController {
$this->result['lookup'] = $result;
}
/**
* Check if a given user is already part of the result
*
* @param string $userId
* @return bool
*/
protected function hasUserInResult($userId) {
foreach ($this->result['exact']['users'] as $result) {
if ($result['value']['shareWith'] === $userId) {
return true;
}
}
foreach ($this->result['users'] as $result) {
if ($result['value']['shareWith'] === $userId) {
return true;
}
}
return false;
}
/**
* Generates a bunch of pagination links for the current page
*