From 67d3fcdbe80bd52ef04ba43bb5465519ca85b436 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 12 Jul 2018 17:09:28 +0200 Subject: [PATCH] handle spaces in group id's on xml api output Signed-off-by: Robin Appelman --- lib/Controller/FolderController.php | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php index 91c2faa94..992715ff8 100644 --- a/lib/Controller/FolderController.php +++ b/lib/Controller/FolderController.php @@ -49,6 +49,10 @@ public function __construct( $this->manager = $manager; $this->mountProvider = $mountProvider; $this->rootFolder = $rootFolder; + + $this->registerResponder('xml', function ($data) { + return $this->buildOCSResponseXML('xml', $data); + }); } public function getFolders() { @@ -149,4 +153,34 @@ public function renameFolder($id, $mountpoint) { $this->manager->renameFolder($id, $mountpoint); return new DataResponse(true); } + + /** + * Overwrite response builder to customize xml handling to deal with spaces in folder names + * + * @param string $format json or xml + * @param DataResponse $data the data which should be transformed + * @since 8.1.0 + * @return \OC\AppFramework\OCS\BaseResponse + */ + private function buildOCSResponseXML($format, DataResponse $data) { + $folderData = $data->getData(); + if (isset($folderData['id'])) { + // single folder response + $folderData = $this->folderDataForXML($folderData); + } else if (count($folderData) && isset(current($folderData)['id'])) { + // folder list + $folderData = array_map([$this, 'folderDataForXML'], $folderData); + } + $data->setData($folderData); + return new \OC\AppFramework\OCS\V1Response($data, $format); + } + + private function folderDataForXML($data) { + $groups = $data['groups']; + $data['groups'] = []; + foreach($groups as $id => $permissions) { + $data['groups'][] = ['@group_id' => $id, '@permissions' => $permissions]; + } + return $data; + } }