From d1fb2c6b215e0c5cc2d322561ebf87cbe49b8c81 Mon Sep 17 00:00:00 2001 From: Josh Richards Date: Tue, 4 Apr 2023 22:48:59 -0400 Subject: [PATCH] Enhance quota exceeded logging for admins * Adds owner of target folder (i.e. when shared) * Only log owner if not current user * Clarifies user quota vs disk space issue * Special $path handling for non-Chunked-v2 uploads * Mimic current path behavior for targets that already exist * Add db access to unit tests Addresses backend portion of #37519 Signed-off-by: Josh Richards --- apps/dav/lib/Connector/Sabre/QuotaPlugin.php | 17 ++++++++++++++++- .../unit/Connector/Sabre/QuotaPluginTest.php | 8 ++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/apps/dav/lib/Connector/Sabre/QuotaPlugin.php b/apps/dav/lib/Connector/Sabre/QuotaPlugin.php index ddf4b2773e0b1..67497ed70dc2e 100644 --- a/apps/dav/lib/Connector/Sabre/QuotaPlugin.php +++ b/apps/dav/lib/Connector/Sabre/QuotaPlugin.php @@ -202,12 +202,27 @@ public function checkQuota($path, $length = null) { // use target file name for free space check in case of shared files $path = rtrim($parentPath, '/') . '/' . $info['name']; } + + // 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') && !$this->server->tree->nodeExists($path)) { + $path = dirname($path); + } + $targetOwner = $this->view->getOwner($path); $freeSpace = $this->getFreeSpace($path); if ($freeSpace >= 0 && $length > $freeSpace) { if (isset($chunkHandler)) { $chunkHandler->cleanup(); } - throw new InsufficientStorage("Insufficient space in $path, $length required, $freeSpace available"); + if ($targetOwner !== \OC_User::getUser()) { + throw new InsufficientStorage("Quota exceeded in $path (owner: $targetOwner), $length required, $freeSpace available"); + } else { + throw new InsufficientStorage("Quota exceeded in $path, $length required, $freeSpace available"); + } } } return true; diff --git a/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php index 4a9ca159bbd8c..beaa2610e9376 100644 --- a/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php @@ -41,6 +41,14 @@ * later. * See the COPYING-README file. */ + +/** + * Class QuotaPluginTest + * + * @group DB + * + */ + class QuotaPluginTest extends TestCase { /** @var \Sabre\DAV\Server | \PHPUnit\Framework\MockObject\MockObject */