Skip to content

Commit

Permalink
feat: enhance quota exceeded logging for admins
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <[email protected]>
  • Loading branch information
skjnldsv committed Aug 27, 2024
1 parent ead3f66 commit 49b0d4c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions apps/dav/lib/Connector/Sabre/QuotaPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
5 changes: 5 additions & 0 deletions apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 49b0d4c

Please sign in to comment.