diff options
-rw-r--r-- | apps/files_external/js/settings.js | 45 | ||||
-rw-r--r-- | core/routes.php | 4 | ||||
-rw-r--r-- | core/user/controller.php | 31 |
3 files changed, 49 insertions, 31 deletions
diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index 7ea82f4bcb3..cfbd3751ac4 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -233,41 +233,24 @@ $(document).ready(function() { } }, initSelection: function(element, callback) { - - var promises = []; - - var results = []; - - $(element.val().split(",")).each(function (i,userId) { - var def = new $.Deferred(); - promises.push(def.promise()); - - var pos = userId.indexOf('(group)'); - if (pos !== -1) { - //add as group - results.push({name:userId, displayname:userId.substr(0, pos), type:'group'}); - def.resolve(); - } else { - $.ajax(OC.generateUrl('apps/files_external/applicable'), { - data: { - pattern: userId - }, - dataType: "json" - }).done(function(data) { - if (data.status === "success") { - if (data.users[userId]) { - results.push({name:userId, displayname:data.users[userId], type:'user'}); - } - def.resolve(); - } else { - //FIXME add error handling + $.ajax(OC.generateUrl('displaynames'), { + data: { + users: element.val().split(",") + }, + dataType: "json" + }).done(function(data) { + var results = []; + if (data.status === "success") { + $.each(data.users, function(user, displayname) { + if (displayname !== false) { + results.push({name:user, displayname:displayname, type:'user'}); } }); + callback(results); + } else { + //FIXME add error handling } }); - $.when.apply(undefined, promises).then(function(){ - callback(results); - }); }, id: function(element) { return element.name; diff --git a/core/routes.php b/core/routes.php index c8fda2ee3dc..9f305bb43ce 100644 --- a/core/routes.php +++ b/core/routes.php @@ -32,6 +32,10 @@ $this->create('core_ajax_share', '/core/ajax/share.php') // Translations $this->create('core_ajax_translations', '/core/ajax/translations.php') ->actionInclude('core/ajax/translations.php'); +// User display names +$this->create('core_user_displaynames', '/displaynames') + ->get() + ->action('OC\Core\User\Controller', 'getDisplayNames'); // Tags $this->create('core_tags_tags', '/tags/{type}') ->get() diff --git a/core/user/controller.php b/core/user/controller.php new file mode 100644 index 00000000000..cbcbd936183 --- /dev/null +++ b/core/user/controller.php @@ -0,0 +1,31 @@ +<?php +/** + * Copyright (c) 2014 Jörn Dreyer <jfd@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Core\User; + +class Controller { + public static function getDisplayNames($args) { + \OC_JSON::checkLoggedIn(); + \OC_JSON::callCheck(); + + $users = $_GET['users']; + $result = array(); + $userManager = \OC::$server->getUserManager(); + + foreach ($users as $user) { + $userObject = $userManager->get($user); + if (is_object($userObject)) { + $result[$user] = $userObject->getDisplayName(); + } else { + $result[$user] = false; + } + } + + \OC_JSON::success(array('users'=>$result)); + } +} |