Skip to content

Commit

Permalink
[WP#56328]Fix error message when upload is restricted by file access …
Browse files Browse the repository at this point in the history
…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 <sagargurung1001@gmail.com>
Signed-off-by: nabim777 <nabinalemagar019@gmail.com>
Co-authored-by: Sagar Gurung <46086950+SagarGi@users.noreply.github.com>
  • Loading branch information
nabim777 and SagarGi committed Sep 5, 2024
1 parent 5b20bc5 commit 0252bfb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/Controller/DirectUploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/Controller/DirectUploadControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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],
];
}
Expand Down

0 comments on commit 0252bfb

Please sign in to comment.