From 0252bfba27bc4e78d3f55c9bc834d6ac42de1bb9 Mon Sep 17 00:00:00 2001 From: Nalem7 <61624650+nabim777@users.noreply.github.com> Date: Thu, 5 Sep 2024 16:34:14 +0545 Subject: [PATCH] [WP#56328]Fix error message when upload is restricted by file access control in `Nextcloud` (#688) (#696) * Fix the misleading error message when upload is restricted by file access control app * Added php unit test * update change log --------- Signed-off-by: Sagar Signed-off-by: nabim777 Co-authored-by: Sagar Gurung <46086950+SagarGi@users.noreply.github.com> --- CHANGELOG.md | 1 + lib/Controller/DirectUploadController.php | 5 ++++- tests/lib/Controller/DirectUploadControllerTest.php | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0313e00b..74e002231 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix avatar not found in openproject - Enhance project search when creating workpackages from Nextcloud - Drop application's support for Nextcloud 26 +- Fix issue preventing direct uploading of resources in Nextcloud that are managed by app `Files Access Control` ## 2.6.4 - 2024-08-15 ### Changed diff --git a/lib/Controller/DirectUploadController.php b/lib/Controller/DirectUploadController.php index 41775edf1..0bc2bbfd3 100644 --- a/lib/Controller/DirectUploadController.php +++ b/lib/Controller/DirectUploadController.php @@ -40,6 +40,7 @@ use OCP\AppFramework\Http\DataResponse; use OCP\Files\File; use OCP\Files\FileInfo; +use OCP\Files\ForbiddenException as FileAccessForbiddenException; use OCP\Files\InvalidCharacterInPathException; use OCP\Files\InvalidContentException; use OCP\Files\InvalidPathException; @@ -275,7 +276,9 @@ public function directUpload(string $token):DataResponse { return new DataResponse([ 'error' => $this->l->t($e->getMessage()) ], Http::STATUS_BAD_REQUEST); - } catch (ForbiddenException $e) { + } catch (ForbiddenException | FileAccessForbiddenException $e) { + // the FileAccessForbiddenException can occur when we are not allowed to perform certain file operation + // which is controlled by Nextcloud app File Access Control. return new DataResponse([ 'error' => $this->l->t($e->getMessage()) ], Http::STATUS_FORBIDDEN); diff --git a/tests/lib/Controller/DirectUploadControllerTest.php b/tests/lib/Controller/DirectUploadControllerTest.php index 3a7d7e93e..df6fc04dc 100644 --- a/tests/lib/Controller/DirectUploadControllerTest.php +++ b/tests/lib/Controller/DirectUploadControllerTest.php @@ -25,6 +25,7 @@ use OC\Files\View; use OCP\Files\Folder; +use OCP\Files\ForbiddenException as FileAccessForbiddenException; use OCP\Files\InvalidContentException; use OCP\IL10N; use OCP\IRequest; @@ -185,6 +186,7 @@ public function testDirectUploadFileNotUploaded(string $tmpName, int $error):voi public function newFileExceptionsDataProvider() { return [ [new InvalidContentException('Virus detected'), 'Virus detected', 415], + [new FileAccessForbiddenException('Access denied by the access control', false), 'Access denied by the access control', 403], [new \Exception('could not upload'), 'could not upload', 500], ]; }