From 49b0d4ce24ec418b251f018bfef349e58d117347 Mon Sep 17 00:00:00 2001 From: skjnldsv Date: Fri, 16 Aug 2024 10:22:27 +0200 Subject: [PATCH] feat: enhance quota exceeded logging for admins Signed-off-by: skjnldsv --- apps/dav/lib/Connector/Sabre/QuotaPlugin.php | 14 ++++++++++++++ .../tests/unit/Connector/Sabre/QuotaPluginTest.php | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/apps/dav/lib/Connector/Sabre/QuotaPlugin.php b/apps/dav/lib/Connector/Sabre/QuotaPlugin.php index deaa4cf672b4b..f54858dbd109c 100644 --- a/apps/dav/lib/Connector/Sabre/QuotaPlugin.php +++ b/apps/dav/lib/Connector/Sabre/QuotaPlugin.php @@ -190,8 +190,22 @@ public function checkQuota(string $path, $length = null) { // Strip any duplicate slashes $path = str_replace('//', '/', $path); + // TODO: I suspect the below existence check more properly belongs in + // beforeCreateFile(), similar to what already exists in + // beforeCopy and beforeMove() + // NOTE: && or || here is equivalent in terms of outcome (but && our intention) + // because only other times the full path SHOULD get to us here is when + // existence has already been confirmed - see beforeCopy() & beforeMove()) + if (($req->getHeader('Destination') === null || $req->getHeader('Destination') === '') && !$this->server->tree->nodeExists($path)) { + $path = dirname($path); + } + + $targetOwner = $this->view->getOwner($path); $freeSpace = $this->getFreeSpace($path); if ($freeSpace >= 0 && $length > $freeSpace) { + if ($targetOwner !== \OC_User::getUser()) { + throw new InsufficientStorage("Quota exceeded in $path (owner: $targetOwner), $length required, $freeSpace available"); + } throw new InsufficientStorage("Insufficient space in $path, $length required, $freeSpace available"); } } diff --git a/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php index 815837799fd24..9eede1f70a8c3 100644 --- a/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php @@ -12,6 +12,11 @@ use OCP\Files\FileInfo; use Test\TestCase; +/** + * Class QuotaPluginTest + * + * @group DB + */ class QuotaPluginTest extends TestCase { /** @var \Sabre\DAV\Server | \PHPUnit\Framework\MockObject\MockObject */ private $server;