From 70b19761aaef961efe90ef509fb0501afc6b538d Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 22 Jan 2018 21:47:25 +0100 Subject: [PATCH] Provide list of editable fields via OCS API Fixes #7983 Signed-off-by: Roeland Jago Douma --- apps/provisioning_api/appinfo/routes.php | 1 + .../lib/Controller/UsersController.php | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/apps/provisioning_api/appinfo/routes.php b/apps/provisioning_api/appinfo/routes.php index c4932ebb28..ea1a073f5e 100644 --- a/apps/provisioning_api/appinfo/routes.php +++ b/apps/provisioning_api/appinfo/routes.php @@ -44,6 +44,7 @@ return [ ['root' => '/cloud', 'name' => 'Users#addUser', 'url' => '/users', 'verb' => 'POST'], ['root' => '/cloud', 'name' => 'Users#getUser', 'url' => '/users/{userId}', 'verb' => 'GET'], ['root' => '/cloud', 'name' => 'Users#getCurrentUser', 'url' => '/user', 'verb' => 'GET'], + ['root' => '/cloud', 'name' => 'Users#getEditableField', 'url' => '/user/fields', 'verb' => 'GET'], ['root' => '/cloud', 'name' => 'Users#editUser', 'url' => '/users/{userId}', 'verb' => 'PUT'], ['root' => '/cloud', 'name' => 'Users#deleteUser', 'url' => '/users/{userId}', 'verb' => 'DELETE'], ['root' => '/cloud', 'name' => 'Users#enableUser', 'url' => '/users/{userId}/enable', 'verb' => 'PUT'], diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 9098797f1a..1c7522d430 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -296,6 +296,38 @@ class UsersController extends OCSController { return $data; } + /** + * @NoAdminRequired + * @NoSubAdminRequired + */ + public function getEditableField() { + $permittedFields = []; + + // Editing self (display, email) + if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; + $permittedFields[] = AccountManager::PROPERTY_EMAIL; + } + + $permittedFields[] = 'password'; + if ($this->config->getSystemValue('force_language', false) === false) { + $permittedFields[] = 'language'; + } + + if ($this->appManager->isEnabledForUser('federatedfilesharing')) { + $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application(); + $shareProvider = $federatedFileSharing->getFederatedShareProvider(); + if ($shareProvider->isLookupServerUploadEnabled()) { + $permittedFields[] = AccountManager::PROPERTY_PHONE; + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; + $permittedFields[] = AccountManager::PROPERTY_TWITTER; + } + } + + return new DataResponse($permittedFields); + } + /** * @NoAdminRequired * @NoSubAdminRequired