8000 feat(api): Get all contents of a specific folder by dushimsam · Pull Request #2555 · fossology/fossology · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(api): Get all contents of a specific folder #2555

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

Merged
merged 2 commits into from
Oct 3, 2023
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
39 changes: 39 additions & 0 deletions src/www/ui/api/Controllers/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,43 @@ public function unlinkFolder($request, $response, $args)
}
return $response->withJson($info->getArray(), $info->getCode());
}

/**
* Get the all folder contents
*
* @param ServerRequestInterface $request
* @param ResponseHelper $response
* @param array $args
* @return ResponseHelper
*/
public function getAllFolderContents($request, $response, $args)
{
$folderId = $args['id'];
$folderDao = $this->restHelper->getFolderDao();

if ($folderDao->getFolder($folderId) === null) {
$error = new Info(404, "Folder id not found!", InfoType::ERROR);
} else if (! $folderDao->isFolderAccessible($folderId, $this->restHelper->getUserId())) {
$error = new Info(403, "Folder is not accessible!", InfoType::ERROR);
}

if (isset($error)) {
return $response->withJson($error->getArray(), $error->getCode());
}

/** @var AjaxFolderContents $folderContents */
$folderContents = $this->restHelper->getPlugin('foldercontents');
$symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
$symfonyRequest->request->set('folder', $folderId);
$symfonyRequest->request->set('fromRest', true);
$contentList = $folderContents->handle($symfonyRequest);
$removableContents = $folderDao->getRemovableContents($folderId);

foreach ($contentList as &$value) {
if (in_array($value['id'], $removableContents)) {
$value['removable'] = true;
}
}
return $response->withJson($contentList, 200);
}
}
109 changes: 74 additions & 35 deletions src/www/ui/api/documentation/openapi.yaml
8000
Original file line number Diff line number Diff line change
Expand Up @@ -2371,8 +2371,8 @@ paths:
schema:
type: string
enum:
- active
- inactive
- active
- inactive
- name: limit
description: Limits of responses per request
required: false
Expand Down Expand Up @@ -2724,7 +2724,7 @@ paths:
schema:
$ref: '#/components/schemas/Info'
default:
$ref: '#/components/responses/defaultResponse'
$ref: '#/components/responses/defaultResponse'

/jobs/dashboard/statistics:
get:
Expand Down Expand Up @@ -3132,6 +3132,45 @@ paths:
default:
$ref: '#/components/responses/defaultResponse'

/folders/{id}/contents:
parameters:
- name: id
in: path
required: true
description: ID of the folder
schema:
type: integer
get:
operationId: getAllFolderContents
tags:
- Folders
summary: Get all contents of a folder
description:
Get all contents of a folder by id
responses:
'200':
description: Contents of the given folder
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/GetFolderContent'
'403':
description: Folder is not accessible
content:
application/json:
schema:
$ref: '#/components/schemas/Info'
'404':
description: Folder does not exist
content:
application/json:
schema:
$ref: '#/components/schemas/Info'
default:
$ref: '#/components/responses/defaultResponse'

/uploads/{id}/item/{ItemId}/totalcopyrights:
parameters:
- name: id
Expand All @@ -3153,8 +3192,8 @@ paths:
schema:
type: string
enum:
- active
- inactive
- active
- inactive
get:
operationId: getTotalFileCopyrights
tags:
Expand Down Expand Up @@ -4287,7 +4326,7 @@ paths:
Verify a license as new or variant of another license
requestBody:
description: The shortname of the parent license |
Same name if it's to be verified as a new license
Same name if it's to be verified as a new license
required: true
content:
application/json:
Expand Down Expand Up @@ -4432,7 +4471,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/GetPHPInfo'
$ref: '#/components/schemas/GetPHPInfo'
'403':
description: Access denied
content:
Expand Down Expand Up @@ -4669,6 +4708,18 @@ components:
nullable: true
hash:
$ref: '#/components/schemas/Hash'
GetFolderContent:
type: object
properties:
id:
type: integer
description: Id of the folder content.
content:
type: string
description: Content of the folder.
removable:
type: boolean
description: Is the folder removable.
UploadSummary:
type: object
properties:
Expand Down Expand Up @@ -5002,18 +5053,6 @@ components:
parent:
type: integer
description: Id of the parent folder (if any, null otherwise).
GetFolderContent:
type: object
properties:
id:
type: integer
description: Id of the folder content.
content:
type: string
description: Content of the folder.
removable:
type: boolean
description: Is the folder removable.
TokenRequest:
type: object
properties:
Expand Down Expand Up @@ -5417,12 +5456,12 @@ components:
description: field type
type: string
enum:
- int
- text
- textarea
- password
- dropdown
- boolean
- int
- text
- textarea
- password
- dropdown
- boolean
label:
description: field label
type: string
Expand Down Expand Up @@ -5622,16 +5661,16 @@ components:
successfulAgents:
type: array
items:
properties:
agent_id:
type: integer
example: 20
agent_rev:
type: string
example: "4.1.0.282-rc1.ffb851"
agent_name:
type: string
example: "reso"
properties:
agent_id:
type: integer
example: 20
agent_rev:
type: string
example: "4.1.0.282-rc1.ffb851"
agent_name:
type: string
example: "reso"
uploadId:
type: integer
example: 10
Expand Down
1 change: 1 addition & 0 deletions src/www/ui/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ function (\Slim\Routing\RouteCollectorProxy $app) {
$app->put('/{id:\\d+}', FolderController::class . ':copyFolder');
$app->get('/{id:\\d+}/contents/unlinkable', FolderController::class . ':getUnlinkableFolderContents');
$app->put('/contents/{contentId:\\d+}/unlink', FolderController::class . ':unlinkFolder');
$app->get('/{id:\\d+}/contents', FolderController::class . ':getAllFolderContents');
$app->any('/{params:.*}', BadRequestController::class);
});

Expand Down
11 changes: 10 additions & 1 deletion src/www/ui/async/AjaxFolderContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@ public function handle(Request $request)
$childUploads = $this->folderDao->getFolderChildUploads($folderId, Auth::getGroupId());
foreach ($childUploads as $upload) {
$uploadStatus = new UploadStatus();
$uploadDate = explode(".",$upload['upload_ts'])[0];
$uploadDate = explode(".", $upload['upload_ts'])[0];
$uploadStatus = " (" . $uploadStatus->getTypeName($upload['status_fk']) . ")";
$results[$upload['foldercontents_pk']] = $upload['upload_filename'] . _(" from ") . Convert2BrowserTime($uploadDate) . $uploadStatus;
}

if (!$request->get('removable')) {
if ($request->get('fromRest')) {
return array_map(function($key, $value) {
return array(
'id' => $key,
'content' => $value,
'removable' => false
);
}, array_keys($results), $results);
}
return new JsonResponse($results);
}

Expand Down
0