]> source.dussan.org Git - nextcloud-server.git/commitdiff
introduce share by mail, ui part
authorBjoern Schiessle <bjoern@schiessle.org>
Fri, 29 Jul 2016 13:37:08 +0000 (15:37 +0200)
committerBjoern Schiessle <bjoern@schiessle.org>
Tue, 1 Nov 2016 18:51:11 +0000 (19:51 +0100)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
apps/files_sharing/lib/Controller/ShareesAPIController.php
core/js/sharedialogview.js
lib/private/Share/Constants.php

index 99c6b55240da45bfa76ee9c31044c4f6284bd217..d5d877f4673d97a48d84beceb4aefcc84d7e2a6d 100644 (file)
@@ -404,68 +404,6 @@ class ShareesAPIController extends OCSController {
                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 @@ class ShareesAPIController extends OCSController {
 
                $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 @@ class ShareesAPIController extends OCSController {
                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
         *
index 7efb361f512dd9771aa1023f96d0eb3ceb1506e3..78622faea29c7171983c294917c559179c5798b4 100644 (file)
                                                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;
 
                                                                                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')
                                                sharee: text
                                        });
                                }
+                       } else if (item.value.shareType === OC.Share.SHARE_TYPE_EMAIL) {
+                               text = t('core', '{sharee} (email)', {
+                                       sharee: text
+                               });
                        }
                        var insert = $("<div class='share-autocomplete-item'/>");
                        var avatar = $("<div class='avatardiv'></div>").appendTo(insert);
                                var infoTemplate = this._getRemoteShareInfoTemplate();
                                remoteShareInfo = infoTemplate({
                                        docLink: this.configModel.getFederatedShareDocLink(),
-                                       tooltip: t('core', 'Share with people on other Nextclouds using the syntax username@example.com/nextcloud')
+                                       tooltip: t('core', 'Share with people on other servers using the syntax username@example.com/nextcloud')
                                });
                        }
 
                },
 
                _renderSharePlaceholderPart: function () {
-                       var sharePlaceholder = t('core', 'Share with users');
+                       var sharePlaceholder = t('core', 'Share with users, or by mail...');
 
                        if (this.configModel.get('allowGroupSharing')) {
                                if (this.configModel.get('isRemoteShareAllowed')) {
-                                       sharePlaceholder = t('core', 'Share with users, groups or remote users…');
+                                       sharePlaceholder = t('core', 'Share with users, groups, remote users, or by mail…');
                                } else {
-                                       sharePlaceholder = t('core', 'Share with users or groups…');
+                                       sharePlaceholder = t('core', 'Share with users, groups or by mail...');
                                }
                        } else if (this.configModel.get('isRemoteShareAllowed')) {
-                                       sharePlaceholder = t('core', 'Share with users or remote users…');
+                                       sharePlaceholder = t('core', 'Share with users, remote users or by mail...');
                        }
 
                        return sharePlaceholder;
index 13a5a044e8a32cce30da0f130b82d728bb79e86e..f13f83f8ba9aa15795b9cc7e6ab20f5f512f4916 100644 (file)
@@ -29,9 +29,9 @@ class Constants {
        const SHARE_TYPE_USER = 0;
        const SHARE_TYPE_GROUP = 1;
        const SHARE_TYPE_LINK = 3;
-       const SHARE_TYPE_EMAIL = 4;   // ToDo Check if it is still in use otherwise remove it
+       const SHARE_TYPE_EMAIL = 4;
        const SHARE_TYPE_CONTACT = 5; // ToDo Check if it is still in use otherwise remove it
-       const SHARE_TYPE_REMOTE = 6;  // ToDo Check if it is still in use otherwise remove it
+       const SHARE_TYPE_REMOTE = 6;
 
        const FORMAT_NONE = -1;
        const FORMAT_STATUSES = -2;