Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle spaces in group id's on xml api output #142

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}