Skip to content

Commit

Permalink
handle spaces in group id's on xml api output
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Jul 12, 2018
1 parent 78a1c7a commit 67d3fcd
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/Controller/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 67d3fcd

Please sign in to comment.