diff options
author | Joas Schilling <coding@schilljs.com> | 2017-06-14 15:07:21 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-06-14 15:07:21 +0200 |
commit | 4f98852f5254db0ed17baea813cd12ced0d2e65b (patch) | |
tree | 5b2e52d7969da86f33e1c323e993a15b5f10cf74 /apps/files_sharing | |
parent | ae693129dbc69d5554c02711809ba292207f4bbc (diff) | |
download | nextcloud-server-4f98852f5254db0ed17baea813cd12ced0d2e65b.tar.gz nextcloud-server-4f98852f5254db0ed17baea813cd12ced0d2e65b.zip |
Make sure to only add system users once
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareesAPIController.php | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php index 7766d762d3b..57d51ebac6a 100644 --- a/apps/files_sharing/lib/Controller/ShareesAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php @@ -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; } @@ -712,6 +717,28 @@ class ShareesAPIController extends OCSController { } /** + * 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 * * @param int $page Current page |