From 0a6f02801f333c17ca6455906bc816020883477d Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 29 Jul 2016 15:37:08 +0200 Subject: [PATCH 01/19] introduce share by mail, ui part Signed-off-by: Bjoern Schiessle --- .../lib/Controller/ShareesAPIController.php | 90 +++++-------------- core/js/sharedialogview.js | 26 ++++-- lib/private/Share/Constants.php | 4 +- 3 files changed, 45 insertions(+), 75 deletions(-) diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php index 99c6b55240da4..d5d877f4673d9 100644 --- a/apps/files_sharing/lib/Controller/ShareesAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php @@ -404,68 +404,6 @@ protected function fixRemoteURL($remote) { return $remote; } - /** - * @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 * @@ -487,17 +425,16 @@ public function search($search = '', $itemType = null, $page = 1, $perPage = 200 $shareTypes = [ Share::SHARE_TYPE_USER, + Share::SHARE_TYPE_EMAIL, + Share::SHARE_TYPE_REMOTE ]; if ($this->shareManager->allowGroupSharing()) { $shareTypes[] = Share::SHARE_TYPE_GROUP; } - $shareTypes[] = Share::SHARE_TYPE_EMAIL; - $shareTypes[] = Share::SHARE_TYPE_REMOTE; - - if (is_array($shareType)) { - $shareTypes = array_intersect($shareTypes, $shareType); + if (isset($_GET['shareType']) && is_array($_GET['shareType'])) { + $shareTypes = array_intersect($shareTypes, $_GET['shareType']); sort($shareTypes); } else if (is_numeric($shareType)) { $shareTypes = array_intersect($shareTypes, [(int) $shareType]); @@ -583,6 +520,25 @@ protected function searchSharees($search, $itemType, array $shareTypes, $page, $ return $response; } + /** + * add option to send share by mail + * + * @param string $search + */ + protected function getEmail($search) { + $this->result['emails'] = []; + + if (substr_count($search, '@') >= 1 && substr_count($search, ' ') === 0 && $this->offset === 0) { + $this->result['exact']['emails'][] = [ + 'label' => $search, + 'value' => [ + 'shareType' => Share::SHARE_TYPE_EMAIL, + 'shareWith' => $search, + ], + ]; + } + } + /** * Generates a bunch of pagination links for the current page * diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 7efb361f512dd..78622faea29c7 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -154,10 +154,12 @@ var users = result.ocs.data.exact.users.concat(result.ocs.data.users); var groups = result.ocs.data.exact.groups.concat(result.ocs.data.groups); var remotes = result.ocs.data.exact.remotes.concat(result.ocs.data.remotes); + var emails = result.ocs.data.exact.emails.concat(result.ocs.data.emails); var usersLength; var groupsLength; var remotesLength; + var emailsLength; var i, j; @@ -212,10 +214,18 @@ break; } } + } else if (share.share_type === OC.Share.SHARE_TYPE_EMAIL) { + emailsLength = emails.length; + for (j = 0; j < emailsLength; j++) { + if (emails[j].value.shareWith === share.share_with) { + emails.splice(j, 1); + break; + } } } + } - var suggestions = users.concat(groups).concat(remotes); + var suggestions = users.concat(groups).concat(remotes).concat(emails); if (suggestions.length > 0) { $('.shareWithField').removeClass('error') @@ -268,6 +278,10 @@ sharee: text }); } + } else if (item.value.shareType === OC.Share.SHARE_TYPE_EMAIL) { + text = t('core', '{sharee} (email)', { + sharee: text + }); } var insert = $("