summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib/Controller/ShareesAPIController.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2016-10-24 13:16:05 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-10-24 14:59:32 +0200
commita28528a254aa70f0e35c0cf6fa31ff082fc5eb71 (patch)
treef4ecb2c81804442717f375960023ccbdf1aaabd3 /apps/files_sharing/lib/Controller/ShareesAPIController.php
parentf054adb4291c83b05777688360780146af5f7d94 (diff)
downloadnextcloud-server-a28528a254aa70f0e35c0cf6fa31ff082fc5eb71.tar.gz
nextcloud-server-a28528a254aa70f0e35c0cf6fa31ff082fc5eb71.zip
Add ShareesAPI E-mail search
* Allow to search for SHARE_TYPE_EMAIL (4) * Added tests Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files_sharing/lib/Controller/ShareesAPIController.php')
-rw-r--r--apps/files_sharing/lib/Controller/ShareesAPIController.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php
index a2063803450..99c6b55240d 100644
--- a/apps/files_sharing/lib/Controller/ShareesAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php
@@ -83,10 +83,12 @@ class ShareesAPIController extends OCSController {
'users' => [],
'groups' => [],
'remotes' => [],
+ 'emails' => [],
],
'users' => [],
'groups' => [],
'remotes' => [],
+ 'emails' => [],
];
protected $reachedEndFor = [];
@@ -403,6 +405,68 @@ class ShareesAPIController extends OCSController {
}
/**
+ * @param string $search
+ */
+ protected function getEmails($search) {
+ $this->result['emails'] = [];
+ $this->result['exact']['emails'] = [];
+
+ $foundEmail = false;
+
+ // Search in contacts
+ //@todo Pagination missing
+ $addressBookContacts = $this->contactsManager->search($search, ['FN', 'EMAIL']);
+ foreach ($addressBookContacts as $contact) {
+ if (!isset($contact['EMAIL'])) {
+ continue;
+ }
+
+ $emails = $contact['EMAIL'];
+ if (!is_array($emails)) {
+ $emails = [$emails];
+ }
+
+ foreach ($emails as $email) {
+ if (strtolower($search) === strtolower($contact['FN']) ||
+ strtolower($search) === strtolower($email)
+ ) {
+ if (strtolower($search) === strtolower($email)) {
+ $foundEmail = true;
+ }
+
+ $this->result['exact']['emails'][] = [
+ 'label' => $contact['FN'],
+ 'value' => [
+ 'shareType' => Share::SHARE_TYPE_EMAIL,
+ 'shareWith' => $email,
+ ],
+ ];
+ } else if ($this->shareeEnumeration) {
+ $this->result['emails'][] = [
+ 'label' => $contact['FN'],
+ 'value' => [
+ 'shareType' => Share::SHARE_TYPE_EMAIL,
+ 'shareWith' => $email,
+ ],
+ ];
+ }
+ }
+ }
+
+ if (!$foundEmail && substr_count($search, '@') >= 1 && $this->offset === 0) {
+ $this->result['exact']['emails'][] = [
+ 'label' => $search,
+ 'value' => [
+ 'shareType' => Share::SHARE_TYPE_EMAIL,
+ 'shareWith' => $search,
+ ],
+ ];
+ }
+
+ $this->reachedEndFor[] = 'emails';
+ }
+
+ /**
* @NoAdminRequired
*
* @param string $search
@@ -429,6 +493,7 @@ class ShareesAPIController extends OCSController {
$shareTypes[] = Share::SHARE_TYPE_GROUP;
}
+ $shareTypes[] = Share::SHARE_TYPE_EMAIL;
$shareTypes[] = Share::SHARE_TYPE_REMOTE;
if (is_array($shareType)) {
@@ -499,6 +564,11 @@ class ShareesAPIController extends OCSController {
$this->getRemote($search);
}
+ // Get email
+ if (in_array(Share::SHARE_TYPE_EMAIL, $shareTypes)) {
+ $this->getEmails($search);
+ }
+
$response = new Http\DataResponse($this->result);
if (sizeof($this->reachedEndFor) < 3) {