diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2016-10-25 14:42:59 +0200 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2016-11-01 19:54:40 +0100 |
commit | 60a3893ca848c862ee3e5d8d8d7eb035c8c0228b (patch) | |
tree | ec047e800cdb518571a5b0c4720695ac2a4a4afe | |
parent | 77f74b9780f416fad8d529e789d045ead1b81c89 (diff) | |
download | nextcloud-server-60a3893ca848c862ee3e5d8d8d7eb035c8c0228b.tar.gz nextcloud-server-60a3893ca848c862ee3e5d8d8d7eb035c8c0228b.zip |
improve search for federated cloud ids and email adresses
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareesAPIController.php | 66 |
1 files changed, 58 insertions, 8 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php index 4af332a1184..58648156a99 100644 --- a/apps/files_sharing/lib/Controller/ShareesAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php @@ -273,7 +273,7 @@ class ShareesAPIController extends OCSController { /** * @param string $search - * @return array possible sharees + * @return bool (true if a exact match was found, false otherwise) */ protected function getRemote($search) { $this->result['remotes'] = []; @@ -334,6 +334,8 @@ class ShareesAPIController extends OCSController { } $this->reachedEndFor[] = 'remotes'; + + return $foundRemoteById; } /** @@ -502,13 +504,15 @@ class ShareesAPIController extends OCSController { } // Get remote + $foundExactCloudID = false; if (in_array(Share::SHARE_TYPE_REMOTE, $shareTypes)) { - $this->getRemote($search); + $foundExactCloudID = $this->getRemote($search); } - // Get email - if (in_array(Share::SHARE_TYPE_EMAIL, $shareTypes)) { - $this->getEmails($search); + // if we have a exact match for the cloud ID we don't show the email option, + // it is extremely unlikely that a identical email address and cloud id exists + if (!$foundExactCloudID && in_array(Share::SHARE_TYPE_EMAIL, $shareTypes)) { + $this->getEmail($search); } $response = new Http\DataResponse($this->result); @@ -526,14 +530,56 @@ class ShareesAPIController extends OCSController { } /** - * add option to send share by mail - * * @param string $search + * @return bool (true if a exact match was found, false otherwise) */ protected function getEmail($search) { + $this->result['emails'] = []; - if (substr_count($search, '@') >= 1 && substr_count($search, ' ') === 0 && $this->offset === 0) { + // Search in contacts + //@todo Pagination missing + $addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']); + $foundEmailByAddress = false; + foreach ($addressBookContacts as $contact) { + if (isset($contact['isLocalSystemBook'])) { + continue; + } + if (isset($contact['EMAIL'])) { + $emailAddresses = $contact['EMAIL']; + if (!is_array($emailAddresses)) { + $emailAddresses = [$emailAddresses]; + } + foreach ($emailAddresses as $emailAddress) { + if (strtolower($contact['FN']) === strtolower($search) || strtolower($emailAddress) === strtolower($search)) { + if (strtolower($emailAddress) === strtolower($search)) { + $foundEmailByAddress = true; + } + $this->result['exact']['emails'][] = [ + 'label' => $contact['FN'] . " ($emailAddress)", + 'value' => [ + 'shareType' => Share::SHARE_TYPE_EMAIL, + 'shareWith' => $emailAddress, + ], + ]; + } else { + $this->result['emails'][] = [ + 'label' => $contact['FN'] . " ($emailAddress)", + 'value' => [ + 'shareType' => Share::SHARE_TYPE_EMAIL, + 'shareWith' => $emailAddress, + ], + ]; + } + } + } + } + + if (!$this->shareeEnumeration) { + $this->result['emails'] = []; + } + + if (!$foundEmailByAddress && filter_var($search, FILTER_VALIDATE_EMAIL)) { $this->result['exact']['emails'][] = [ 'label' => $search, 'value' => [ @@ -542,6 +588,10 @@ class ShareesAPIController extends OCSController { ], ]; } + + $this->reachedEndFor[] = 'emails'; + + return $foundEmailByAddress; } /** |