Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Consolidate estimation and exportability warnings into a single endpoint
Avoids having to query multiple endpoints on the client for closely related information

Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal committed Jun 3, 2022
commit e427f6122029036e3b9ee0726fd3d8ffceb616df
1 change: 0 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
['name' => 'Api#migrators', 'url' => '/api/v{apiVersion}/migrators', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'Api#status', 'url' => '/api/v{apiVersion}/status', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'Api#cancel', 'url' => '/api/v{apiVersion}/cancel', 'verb' => 'PUT', 'requirements' => $requirements],
['name' => 'Api#estimate', 'url' => '/api/v{apiVersion}/export/estimate', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'Api#exportable', 'url' => '/api/v{apiVersion}/export', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'Api#export', 'url' => '/api/v{apiVersion}/export', 'verb' => 'POST', 'requirements' => $requirements],
['name' => 'Api#import', 'url' => '/api/v{apiVersion}/import', 'verb' => 'POST', 'requirements' => $requirements],
Expand Down
25 changes: 6 additions & 19 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private function checkJobAndGetUser(): IUser {
*
* @throws OCSException
*/
public function estimate(?array $migrators): DataResponse {
public function exportable(?array $migrators): DataResponse {
$user = $this->checkJobAndGetUser();

if (!is_null($migrators)) {
Expand All @@ -230,29 +230,16 @@ public function estimate(?array $migrators): DataResponse {
throw new OCSException($e->getMessage());
}

return new DataResponse(['size' => $size], Http::STATUS_OK);
}

/**
* @NoAdminRequired
* @NoSubAdminRequired
*
* @throws OCSException
*/
public function exportable(?array $migrators): DataResponse {
$user = $this->checkJobAndGetUser();

if (!is_null($migrators)) {
$this->checkMigrators($migrators);
}

try {
$this->migrationService->checkExportability($user, $migrators);
} catch (NotExportableException $e) {
throw new OCSException($e->getMessage());
$warning = $e->getMessage();
}

return new DataResponse([], Http::STATUS_OK);
return new DataResponse([
'size' => $size,
'warning' => $warning ?? null,
], Http::STATUS_OK);
}

/**
Expand Down