]> source.dussan.org Git - nextcloud-server.git/commitdiff
Search on lookup server
authorRoeland Jago Douma <roeland@famdouma.nl>
Fri, 18 Nov 2016 13:08:42 +0000 (14:08 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Mon, 21 Nov 2016 10:30:00 +0000 (11:30 +0100)
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
apps/files_sharing/lib/Controller/ShareesAPIController.php
apps/lookup_server_connector/lib/UpdateLookupServer.php
core/js/sharedialogview.js

index 09912b7758a05be19b42850207437e62e3eb3c55..d9540aba1d9dc71574a38c99d6b1908b1be31535 100644 (file)
@@ -28,6 +28,7 @@ use OCP\AppFramework\Http;
 use OCP\AppFramework\OCS\OCSBadRequestException;
 use OCP\AppFramework\OCSController;
 use OCP\Contacts\IManager;
+use OCP\Http\Client\IClientService;
 use OCP\IGroup;
 use OCP\IGroupManager;
 use OCP\ILogger;
@@ -65,6 +66,9 @@ class ShareesAPIController extends OCSController {
        /** @var \OCP\Share\IManager */
        protected $shareManager;
 
+       /** @var IClientService */
+       protected $clientService;
+
        /** @var bool */
        protected $shareWithGroupOnly = false;
 
@@ -89,6 +93,7 @@ class ShareesAPIController extends OCSController {
                'groups' => [],
                'remotes' => [],
                'emails' => [],
+               'lookup' => [],
        ];
 
        protected $reachedEndFor = [];
@@ -104,6 +109,7 @@ class ShareesAPIController extends OCSController {
         * @param IURLGenerator $urlGenerator
         * @param ILogger $logger
         * @param \OCP\Share\IManager $shareManager
+        * @param IClientService $clientService
         */
        public function __construct($appName,
                                                                IRequest $request,
@@ -114,7 +120,8 @@ class ShareesAPIController extends OCSController {
                                                                IUserSession $userSession,
                                                                IURLGenerator $urlGenerator,
                                                                ILogger $logger,
-                                                               \OCP\Share\IManager $shareManager) {
+                                                               \OCP\Share\IManager $shareManager,
+                                                               IClientService $clientService) {
                parent::__construct($appName, $request);
 
                $this->groupManager = $groupManager;
@@ -125,6 +132,7 @@ class ShareesAPIController extends OCSController {
                $this->urlGenerator = $urlGenerator;
                $this->logger = $logger;
                $this->shareManager = $shareManager;
+               $this->clientService = $clientService;
        }
 
        /**
@@ -414,10 +422,11 @@ class ShareesAPIController extends OCSController {
         * @param int $page
         * @param int $perPage
         * @param int|int[] $shareType
+        * @param bool $lookup
         * @return Http\DataResponse
         * @throws OCSBadRequestException
         */
-       public function search($search = '', $itemType = null, $page = 1, $perPage = 200, $shareType = null) {
+       public function search($search = '', $itemType = null, $page = 1, $perPage = 200, $shareType = null, $lookup = true) {
                if ($perPage <= 0) {
                        throw new OCSBadRequestException('Invalid perPage argument');
                }
@@ -459,7 +468,7 @@ class ShareesAPIController extends OCSController {
                $this->limit = (int) $perPage;
                $this->offset = $perPage * ($page - 1);
 
-               return $this->searchSharees($search, $itemType, $shareTypes, $page, $perPage);
+               return $this->searchSharees($search, $itemType, $shareTypes, $page, $perPage, $lookup);
        }
 
        /**
@@ -485,10 +494,11 @@ class ShareesAPIController extends OCSController {
         * @param array $shareTypes
         * @param int $page
         * @param int $perPage
+        * @param bool $lookup
         * @return Http\DataResponse
         * @throws OCSBadRequestException
         */
-       protected function searchSharees($search, $itemType, array $shareTypes, $page, $perPage) {
+       protected function searchSharees($search, $itemType, array $shareTypes, $page, $perPage, $lookup) {
                // Verify arguments
                if ($itemType === null) {
                        throw new OCSBadRequestException('Missing itemType');
@@ -510,11 +520,17 @@ class ShareesAPIController extends OCSController {
                        $remoteResults = $this->getRemote($search);
                }
 
+               // Get emails
                $mailResults = ['results' => [], 'exact' => [], 'exactIdMatch' => false];
                if (in_array(Share::SHARE_TYPE_EMAIL, $shareTypes)) {
                        $mailResults = $this->getEmail($search);
                }
 
+               // Get from lookup server
+               if ($lookup) {
+                       $this->getLookup($search);
+               }
+
                // if we have a exact match, either for the federated cloud id or for the
                // email address we only return the exact match. It is highly unlikely
                // that the exact same email address and federated cloud id exists
@@ -609,6 +625,26 @@ class ShareesAPIController extends OCSController {
                return $result;
        }
 
+       protected function getLookup($search) {
+               $client = $this->clientService->newClient();
+
+               $response = $client->get('http://127.0.0.1:3000/users?search='.urlencode($search));
+               $body = json_decode($response->getBody(), true);
+
+               $result = [];
+               foreach ($body as $lookup) {
+                       $result[] = [
+                               'label' => $lookup['federationId'],
+                               'value' => [
+                                       'shareType' => Share::SHARE_TYPE_REMOTE,
+                                       'shareWith' => $lookup['federationId'],
+                               ],
+                               'extra' => $lookup,
+                       ];
+               }
+               $this->result['lookup'] = $result;
+       }
+
        /**
         * Generates a bunch of pagination links for the current page
         *
index fc20ddcd143e96a0b69850ebdc29cd8cec8061e5..abbc0e2b2d5859adf075cd423a86e647221d38af 100644 (file)
@@ -49,7 +49,7 @@ class UpdateLookupServer {
        /** @var Signer */
        private $signer;
        /** @var string URL point to lookup server */
-       private $lookupServer = 'http://192.168.176.105/lookup-server/server/';
+       private $lookupServer = 'http://127.0.0.1:3000/index2.php/users';
 
        /**
         * @param AccountManager $accountManager
index 0a29dec73ca26263e6e6be65cfb3ee3ca0ca2320..6377d16dd4c70f8f8095c5bd216b3aec9326e23b 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 lookup = result.ocs.data.lookup;
                                                if (typeof(result.ocs.data.emails) !== 'undefined') {
                                                        var emails = result.ocs.data.exact.emails.concat(result.ocs.data.emails);
                                                } else {
                                                var groupsLength;
                                                var remotesLength;
                                                var emailsLength;
+                                               var lookupLength;
 
                                                var i, j;
 
                                                        }
                                                }
 
-                                               var suggestions = users.concat(groups).concat(remotes).concat(emails);
+                                               var suggestions = users.concat(groups).concat(remotes).concat(emails).concat(lookup);
 
                                                if (suggestions.length > 0) {
                                                        $('.shareWithField').removeClass('error')