Skip to content

Commit

Permalink
Merge pull request #3415 from nextcloud/fix/foldercontroller/getfolde…
Browse files Browse the repository at this point in the history
…rs-object
  • Loading branch information
provokateurin authored Nov 13, 2024
2 parents 5ea50bd + 80a6458 commit f94c647
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
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

0 comments on commit f94c647

Please sign in to comment.