Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed
- Remove latest stable OpenProject version from warning message [#891](https://github.com/nextcloud/integration_openproject/pull/891)
- Replace internal method with public API for updating file metadata [#908](https://github.com/nextcloud/integration_openproject/pull/908)

### Fixed
- Show meaningful error message when deleting group folders [#884](https://github.com/nextcloud/integration_openproject/pull/884)
Expand Down
13 changes: 4 additions & 9 deletions lib/Controller/DirectUploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use InvalidArgumentException;
use OC\Files\Filesystem;
use OC\Files\Node\Folder;
use OC\Files\View;
use OC\ForbiddenException;
use OC\User\NoUserException;
use OCA\OpenProject\Exception\OpenprojectFileNotUploadedException;
Expand Down Expand Up @@ -79,10 +78,6 @@ class DirectUploadController extends ApiController {

private $l;

/**
* @var View
*/
private $fileView;
public function __construct(
string $appName,
IRequest $request,
Expand All @@ -92,8 +87,7 @@ public function __construct(
DirectUploadService $directUploadService,
DatabaseService $databaseService,
IL10N $l,
?string $userId,
View $fileView
?string $userId
) {
parent::__construct($appName, $request, 'POST');
$this->userId = $userId;
Expand All @@ -104,7 +98,6 @@ public function __construct(
$this->databaseService = $databaseService;
$this->userSession = $userSession;
$this->l = $l;
$this->fileView = $fileView;
}

/**
Expand Down Expand Up @@ -245,7 +238,9 @@ public function directUpload(string $token):DataResponse {
$fileId = $fileInfo->getId();
// setting the creation time for the uploaded file
$creationTime = (new DateTime())->getTimestamp();
$this->fileView->putFileInfo($fileInfo->getPath(), ['creation_time' => $creationTime]);
$fileInfo->getStorage()->getCache()->update($fileId, [
'creation_time' => $creationTime
]);
} catch (OpenprojectUnauthorizedUserException $e) {
return new DataResponse([
'error' => $this->l->t($e->getMessage())
Expand Down
15 changes: 12 additions & 3 deletions tests/lib/Controller/DirectUploadControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace OCA\OpenProject\Controller;

use OC\Files\View;
use OCP\Files\Folder;
use OCP\Files\ForbiddenException as FileAccessForbiddenException;
use OCP\Files\InvalidContentException;
Expand Down Expand Up @@ -202,8 +201,14 @@ public function testDirectUploadException(
}

public function testNegativeFreeSpace(): void {
$cacheMock = $this->getMockBuilder('\OCP\Files\Cache\ICache')->getMock();
$cacheMock->method('update')->willReturn(true);
$storageMock = $this->getMockBuilder('\OCP\Files\Storage\IStorage')->disableOriginalConstructor()->getMock();
$storageMock->method('getCache')->willReturn($cacheMock);

$fileMock = $this->getMockBuilder('\OC\Files\Node\File')->disableOriginalConstructor()->getMock();
$fileMock->method('getId')->willReturn(123);
$fileMock->method('getStorage')->willReturn($storageMock);
$nodeMock = $this->getNodeMock('folder');
$tmpFileName = '/tmp/integration_openproject_unit_test';
touch($tmpFileName);
Expand Down Expand Up @@ -285,7 +290,6 @@ private function createDirectUploadController(
'size' => $uploadedFileSize,
'error' => $uploadedFileError
]);
$viewMock = $this->getMockBuilder(View::class)->disableOriginalConstructor()->getMock();
return new DirectUploadController(
'integration_openproject',
$requestMock,
Expand All @@ -296,7 +300,6 @@ private function createDirectUploadController(
$this->getMockBuilder('OCA\OpenProject\Service\DatabaseService')->disableOriginalConstructor()->getMock(),
$this->l,
'testUser',
$viewMock
);
}

Expand All @@ -311,8 +314,14 @@ private function getNodeMock(string $type, int $id = 123): array {
$ownerMock->method('getDisplayName')->willReturn('Test User');
$ownerMock->method('getUID')->willReturn('3df8ff78-49cb-4d60-8d8b-171b29591fd3');

$cacheMock = $this->getMockBuilder('\OCP\Files\Cache\ICache')->getMock();
$cacheMock->method('update')->willReturn(true);
$storageMock = $this->getMockBuilder('\OCP\Files\Storage\IStorage')->disableOriginalConstructor()->getMock();
$storageMock->method('getCache')->willReturn($cacheMock);

$fileMock = $this->createMock('\OCP\Files\File');
$fileMock->method('getId')->willReturn(123);
$fileMock->method('getStorage')->willReturn($storageMock);

$folderMock = $this->createMock('\OCP\Files\Folder');
$folderMock->method('getId')->willReturn($id);
Expand Down