diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index 27ed0254dd..6c287d6a76 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -233,10 +233,17 @@ $(document).ready(function() { } }, initSelection: function(element, callback) { + var users = {}; + users['users'] = []; + var toSplit = element.val().split(","); + for (var i = 0; i < toSplit.length; i++) { + users['users'].push(toSplit[i]); + } + $.ajax(OC.generateUrl('displaynames'), { - data: { - users: element.val().split(",") - }, + type: 'POST', + contentType: 'application/json', + data: JSON.stringify(users), dataType: "json" }).done(function(data) { var results = []; diff --git a/core/lostpassword/application.php b/core/application.php similarity index 78% rename from core/lostpassword/application.php rename to core/application.php index ba2f3fc633..3380184775 100644 --- a/core/lostpassword/application.php +++ b/core/application.php @@ -8,10 +8,11 @@ * See the COPYING-README file. */ -namespace OC\Core\LostPassword; +namespace OC\Core; use \OCP\AppFramework\App; use OC\Core\LostPassword\Controller\LostController; +use OC\Core\User\UserController; class Application extends App { @@ -38,6 +39,14 @@ class Application extends App { \OC_App::isEnabled('files_encryption') ); }); + $container->registerService('UserController', function($c) { + return new UserController( + $c->query('AppName'), + $c->query('Request'), + $c->query('ServerContainer')->getUserManager(), + new \OC_Defaults() + ); + }); } diff --git a/core/routes.php b/core/routes.php index 37eb2f8a56..28a3680dd9 100644 --- a/core/routes.php +++ b/core/routes.php @@ -6,13 +6,14 @@ * See the COPYING-README file. */ -use OC\Core\LostPassword\Application; +use OC\Core\Application; $application = new Application(); $application->registerRoutes($this, array('routes' => array( array('name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'), array('name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'), array('name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'), + array('name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'), ) )); @@ -35,10 +36,6 @@ $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 deleted file mode 100644 index cbcbd93618..0000000000 --- a/core/user/controller.php +++ /dev/null @@ -1,31 +0,0 @@ - - * 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)); - } -} diff --git a/core/user/usercontroller.php b/core/user/usercontroller.php new file mode 100644 index 0000000000..2570e3b5b0 --- /dev/null +++ b/core/user/usercontroller.php @@ -0,0 +1,66 @@ + + * Copyright (c) 2014 Lukas Reschke + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Core\User; + +use \OCP\AppFramework\Controller; +use \OCP\AppFramework\Http\JSONResponse; +use \OCP\IRequest; + +class UserController extends Controller { + /** + * @var \OCP\IUserManager + */ + protected $userManager; + + /** + * @var \OC_Defaults + */ + protected $defaults; + + public function __construct($appName, + IRequest $request, + $userManager, + $defaults + ) { + parent::__construct($appName, $request); + $this->userManager = $userManager; + $this->defaults = $defaults; + } + + /** + * Lookup user display names + * + * @NoAdminRequired + * + * @param array $users + * + * @return JSONResponse + */ + public function getDisplayNames($users) { + $result = array(); + + foreach ($users as $user) { + $userObject = $this->userManager->get($user); + if (is_object($userObject)) { + $result[$user] = $userObject->getDisplayName(); + } else { + $result[$user] = $user; + } + } + + $json = array( + 'users' => $result, + 'status' => 'success' + ); + + return new JSONResponse($json); + + } +}