diff options
-rw-r--r-- | apps/dav/lib/Upload/ChunkingPlugin.php | 19 | ||||
-rw-r--r-- | apps/dav/tests/unit/Upload/ChunkingPluginTest.php | 10 | ||||
-rw-r--r-- | apps/settings/lib/Hooks.php | 2 | ||||
-rw-r--r-- | lib/private/Preview/Generator.php | 9 | ||||
-rw-r--r-- | tests/lib/Preview/GeneratorTest.php | 81 |
5 files changed, 97 insertions, 24 deletions
diff --git a/apps/dav/lib/Upload/ChunkingPlugin.php b/apps/dav/lib/Upload/ChunkingPlugin.php index 0a89b144ae1..6dd05c24ebf 100644 --- a/apps/dav/lib/Upload/ChunkingPlugin.php +++ b/apps/dav/lib/Upload/ChunkingPlugin.php @@ -26,6 +26,7 @@ namespace OCA\DAV\Upload; use OCA\DAV\Connector\Sabre\Directory; +use OCA\DAV\Connector\Sabre\Exception\Forbidden; use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\Exception\NotFound; use Sabre\DAV\INode; @@ -87,13 +88,17 @@ class ChunkingPlugin extends ServerPlugin { * @return bool|void false to stop handling, void to skip this handler */ public function performMove($path, $destination) { - if (!$this->server->tree->nodeExists($destination)) { - // skip and let the default handler do its work - return; - } - + $fileExists = $this->server->tree->nodeExists($destination); // do a move manually, skipping Sabre's default "delete" for existing nodes - $this->server->tree->move($path, $destination); + try { + $this->server->tree->move($path, $destination); + } catch (Forbidden $e) { + $sourceNode = $this->server->tree->getNodeForPath($path); + if ($sourceNode instanceof FutureFile) { + $sourceNode->delete(); + } + throw $e; + } // trigger all default events (copied from CorePlugin::move) $this->server->emit('afterMove', [$path, $destination]); @@ -102,7 +107,7 @@ class ChunkingPlugin extends ServerPlugin { $response = $this->server->httpResponse; $response->setHeader('Content-Length', '0'); - $response->setStatus(204); + $response->setStatus($fileExists ? 204 : 201); return false; } diff --git a/apps/dav/tests/unit/Upload/ChunkingPluginTest.php b/apps/dav/tests/unit/Upload/ChunkingPluginTest.php index 465bdf58eda..6391bc0a8e5 100644 --- a/apps/dav/tests/unit/Upload/ChunkingPluginTest.php +++ b/apps/dav/tests/unit/Upload/ChunkingPluginTest.php @@ -128,14 +128,18 @@ class ChunkingPluginTest extends TestCase { ->method('nodeExists') ->with('target') ->willReturn(false); - $this->response->expects($this->never()) - ->method('setStatus'); + $this->response->expects($this->once()) + ->method('setHeader') + ->with('Content-Length', '0'); + $this->response->expects($this->once()) + ->method('setStatus') + ->with(201); $this->request->expects($this->once()) ->method('getHeader') ->with('OC-Total-Length') ->willReturn(4); - $this->assertNull($this->plugin->beforeMove('source', 'target')); + $this->assertFalse($this->plugin->beforeMove('source', 'target')); } public function testBeforeMoveFutureFileMoveIt() { diff --git a/apps/settings/lib/Hooks.php b/apps/settings/lib/Hooks.php index 78f7e28ed1c..ecb8949f3af 100644 --- a/apps/settings/lib/Hooks.php +++ b/apps/settings/lib/Hooks.php @@ -182,7 +182,7 @@ class Hooks { $event->setAuthor($actor->getUID()) ->setSubject($subject); } else { - if ($this->config->getAppValue('settings', 'disable_email.email_address_changed_by_admin', 'no') === 'yes') { + if ($this->config->getAppValue('settings', 'disable_activity.email_address_changed_by_admin', 'no') === 'yes') { return; } $text = $l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]); diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index e47a7e5927c..d55aa1cb287 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -126,9 +126,6 @@ class Generator { if ($mimeType === null) { $mimeType = $file->getMimeType(); } - if (!$this->previewManager->isMimeSupported($mimeType)) { - throw new NotFoundException(); - } $previewFolder = $this->getPreviewFolder($file); @@ -155,7 +152,7 @@ class Generator { $crop = $specification['crop'] ?? false; $mode = $specification['mode'] ?? IPreview::MODE_FILL; - // If both width and heigth are -1 we just want the max preview + // If both width and height are -1 we just want the max preview if ($width === -1 && $height === -1) { $width = $maxWidth; $height = $maxHeight; @@ -176,6 +173,10 @@ class Generator { try { $preview = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType(), $previewVersion); } catch (NotFoundException $e) { + if (!$this->previewManager->isMimeSupported($mimeType)) { + throw new NotFoundException(); + } + if ($maxPreviewImage === null) { $maxPreviewImage = $this->helper->getImage($maxPreview); } diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php index d2bfcad9955..43f5c1e0d36 100644 --- a/tests/lib/Preview/GeneratorTest.php +++ b/tests/lib/Preview/GeneratorTest.php @@ -256,25 +256,92 @@ class GeneratorTest extends \Test\TestCase { $file = $this->createMock(File::class); $file->method('isReadable') ->willReturn(true); + $file->method('getId') + ->willReturn(42); $this->previewManager->method('isMimeSupported') ->with('invalidType') ->willReturn(false); + $previewFolder = $this->createMock(ISimpleFolder::class); + $this->appData->method('getFolder') + ->with($this->equalTo(42)) + ->willReturn($previewFolder); + + $maxPreview = $this->createMock(ISimpleFile::class); + $maxPreview->method('getName') + ->willReturn('2048-2048-max.png'); + $maxPreview->method('getMimeType') + ->willReturn('image/png'); + + $previewFolder->method('getDirectoryListing') + ->willReturn([$maxPreview]); + + $previewFolder->method('getFile') + ->with($this->equalTo('1024-512-crop.png')) + ->willThrowException(new NotFoundException()); + + $this->eventDispatcher->expects($this->once()) + ->method('dispatch') + ->with( + $this->equalTo(IPreview::EVENT), + $this->callback(function (GenericEvent $event) use ($file) { + return $event->getSubject() === $file && + $event->getArgument('width') === 1024 && + $event->getArgument('height') === 512 && + $event->getArgument('crop') === true && + $event->getArgument('mode') === IPreview::MODE_COVER; + }) + ); + + $this->generator->getPreview($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType'); + } + + public function testReturnCachedPreviewsWithoutCheckingSupportedMimetype() { + $file = $this->createMock(File::class); + $file->method('isReadable') + ->willReturn(true); + $file->method('getId') + ->willReturn(42); + + + $previewFolder = $this->createMock(ISimpleFolder::class); + $this->appData->method('getFolder') + ->with($this->equalTo(42)) + ->willReturn($previewFolder); + + $maxPreview = $this->createMock(ISimpleFile::class); + $maxPreview->method('getName') + ->willReturn('2048-2048-max.png'); + $maxPreview->method('getMimeType') + ->willReturn('image/png'); + + $previewFolder->method('getDirectoryListing') + ->willReturn([$maxPreview]); + + $preview = $this->createMock(ISimpleFile::class); + $previewFolder->method('getFile') + ->with($this->equalTo('1024-512-crop.png')) + ->willReturn($preview); + + $this->previewManager->expects($this->never()) + ->method('isMimeSupported'); + $this->eventDispatcher->expects($this->once()) ->method('dispatch') ->with( $this->equalTo(IPreview::EVENT), $this->callback(function (GenericEvent $event) use ($file) { return $event->getSubject() === $file && - $event->getArgument('width') === 0 && - $event->getArgument('height') === 0 && - $event->getArgument('crop') === true && - $event->getArgument('mode') === IPreview::MODE_COVER; + $event->getArgument('width') === 1024 && + $event->getArgument('height') === 512 && + $event->getArgument('crop') === true && + $event->getArgument('mode') === IPreview::MODE_COVER; }) ); - $this->generator->getPreview($file, 0, 0, true, IPreview::MODE_COVER, 'invalidType'); + $result = $this->generator->getPreview($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType'); + $this->assertSame($preview, $result); } public function testNoProvider() { @@ -286,10 +353,6 @@ class GeneratorTest extends \Test\TestCase { $file->method('getId') ->willReturn(42); - $this->previewManager->method('isMimeSupported') - ->with($this->equalTo('myMimeType')) - ->willReturn(true); - $previewFolder = $this->createMock(ISimpleFolder::class); $this->appData->method('getFolder') ->with($this->equalTo(42)) |