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

fix(FolderController): Return folders as object with id as key #3415

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 7 additions & 4 deletions lib/Controller/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private function formatFolder(array $folder): array {
* Gets all Groupfolders
*
* @param bool $applicable Filter by applicable groups
* @return DataResponse<Http::STATUS_OK, list<GroupFoldersFolder>, array{}>
* @return DataResponse<Http::STATUS_OK, array<string, GroupFoldersFolder>, array{}>
* @throws OCSNotFoundException Storage not found
*
* 200: Groupfolders returned
Expand All @@ -103,8 +103,11 @@ public function getFolders(bool $applicable = false): DataResponse {
throw new OCSNotFoundException();
}

$folders = array_values($this->manager->getAllFoldersWithSize($storageId));
$folders = array_map($this->formatFolder(...), $folders);
$folders = [];
foreach ($this->manager->getAllFoldersWithSize($storageId) as $id => $folder) {
// Make them string-indexed for OpenAPI JSON output
$folders[(string)$id] = $this->formatFolder($folder);
}
$isAdmin = $this->delegationService->isAdminNextcloud() || $this->delegationService->isDelegatedAdmin();
if ($isAdmin && !$applicable) {
return new DataResponse($folders);
Expand All @@ -115,7 +118,7 @@ public function getFolders(bool $applicable = false): DataResponse {
}

if ($applicable || !$this->delegationService->hasApiAccess()) {
$folders = array_values(array_filter(array_map($this->filterNonAdminFolder(...), $folders)));
$folders = array_filter(array_map($this->filterNonAdminFolder(...), $folders));
}

return new DataResponse($folders);
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/FoldersFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function __construct(
}

/**
* @param list<GroupFoldersFolder> $folders List of all folders
* @return list<GroupFoldersFolder>
* @param GroupFoldersFolder[] $folders List of all folders
* @return GroupFoldersFolder[]
*/
public function getForApiUser(array $folders): array {
$user = $this->userSession->getUser();
Expand Down
4 changes: 2 additions & 2 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/Folder"
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,9 @@ export interface operations {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Folder"][];
"application/json": {
[key: string]: components["schemas"]["Folder"];
};
};
};
/** @description Storage not found */
Expand Down
Loading