Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/private/DirectEditing/Manager.php20
-rw-r--r--tests/lib/DirectEditing/ManagerTest.php15
2 files changed, 28 insertions, 7 deletions
diff --git a/lib/private/DirectEditing/Manager.php b/lib/private/DirectEditing/Manager.php
index a514eaea482..ebca819eeae 100644
--- a/lib/private/DirectEditing/Manager.php
+++ b/lib/private/DirectEditing/Manager.php
@@ -123,15 +123,21 @@ class Manager implements IManager {
public function create(string $path, string $editorId, string $creatorId, $templateId = null): string {
$userFolder = $this->rootFolder->getUserFolder($this->userId);
- $file = $userFolder->newFile($path);
- $editor = $this->getEditor($editorId);
- $creators = $editor->getCreators();
- foreach ($creators as $creator) {
- if ($creator->getId() === $creatorId) {
- $creator->create($file, $creatorId, $templateId);
- return $this->createToken($editorId, $file, $path);
+ try {
+ $file = $userFolder->get($path);
+ throw new \RuntimeException('File already exists');
+ } catch (\OCP\Files\NotFoundException $e) {
+ $file = $userFolder->newFile($path);
+ $editor = $this->getEditor($editorId);
+ $creators = $editor->getCreators();
+ foreach ($creators as $creator) {
+ if ($creator->getId() === $creatorId) {
+ $creator->create($file, $creatorId, $templateId);
+ return $this->createToken($editorId, $file, $path);
+ }
}
}
+
throw new \RuntimeException('No creator found');
}
diff --git a/tests/lib/DirectEditing/ManagerTest.php b/tests/lib/DirectEditing/ManagerTest.php
index a97c02f19d2..1f18a25115f 100644
--- a/tests/lib/DirectEditing/ManagerTest.php
+++ b/tests/lib/DirectEditing/ManagerTest.php
@@ -12,6 +12,7 @@ use OCP\DirectEditing\IEditor;
use OCP\DirectEditing\IToken;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
+use OCP\Files\NotFoundException;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUserSession;
@@ -151,6 +152,10 @@ class ManagerTest extends TestCase {
$this->random->expects($this->once())
->method('generate')
->willReturn($expectedToken);
+ $this->userFolder
+ ->method('get')
+ ->with('/File.txt')
+ ->willThrowException(new NotFoundException());
$this->userFolder->expects($this->once())
->method('newFile')
->willReturn($file);
@@ -167,6 +172,10 @@ class ManagerTest extends TestCase {
$this->random->expects($this->once())
->method('generate')
->willReturn($expectedToken);
+ $this->userFolder
+ ->method('get')
+ ->with('/File.txt')
+ ->willThrowException(new NotFoundException());
$this->userFolder->expects($this->once())
->method('newFile')
->willReturn($file);
@@ -177,4 +186,10 @@ class ManagerTest extends TestCase {
$this->assertInstanceOf(NotFoundResponse::class, $secondResult);
}
+ public function testCreateFileAlreadyExists() {
+ $this->expectException(\RuntimeException::class);
+
+ $this->manager->create('/File.txt', 'testeditor', 'createEmpty');
+ }
+
}