Skip to content

Commit

Permalink
fix(FolderController): Return folders as object with id as key
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin authored and backportbot[bot] committed Nov 13, 2024
1 parent 89a7c44 commit ffc9d8d
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 @@ -100,7 +100,7 @@ private function formatFolder(array $folder): array {
* Gets all Groupfolders
* @NoAdminRequired
* @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 @@ -111,8 +111,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 @@ -121,7 +124,7 @@ public function getFolders(bool $applicable = false): DataResponse {
$folders = $this->foldersFilter->getForApiUser($folders);
}
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 @@ -24,8 +24,8 @@ public function __construct(IUserSession $userSession, IGroupManager $groupManag
}

/**
* @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 @@ -248,8 +248,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 @@ -328,7 +328,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 ffc9d8d

Please sign in to comment.