From 4025b95e0316595d5e3bc04a9b32caf2aeda4a37 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 25 Aug 2020 16:05:16 +0200 Subject: [PATCH 1/2] show better quota warning for group folders and external storage instead of showing the generic 'Your storage is full' message, better explain that it's the group folder/external storage that is full Signed-off-by: Robin Appelman --- apps/files/js/files.js | 50 +++++++++++++++++++++++--------- apps/files/lib/Helper.php | 1 + lib/private/legacy/OC_Helper.php | 4 ++- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 28e4c5f575..cdc1c70ffc 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -72,6 +72,7 @@ $('#free_space').val(response.data.freeSpace); $('#upload.button').attr('data-original-title', response.data.maxHumanFilesize); $('#usedSpacePercent').val(response.data.usedSpacePercent); + $('#usedSpacePercent').data('mount-type', response.data.mountType); $('#owner').val(response.data.owner); $('#ownerDisplayName').val(response.data.ownerDisplayName); Files.displayStorageWarnings(); @@ -155,21 +156,30 @@ var usedSpacePercent = $('#usedSpacePercent').val(), owner = $('#owner').val(), - ownerDisplayName = $('#ownerDisplayName').val(); + ownerDisplayName = $('#ownerDisplayName').val(), + mountType = $('#usedSpacePercent').data('mount-type'); if (usedSpacePercent > 98) { if (owner !== OC.getCurrentUser().uid) { OC.Notification.show(t('files', 'Storage of {owner} is full, files can not be updated or synced anymore!', {owner: ownerDisplayName}), {type: 'error'} ); - return; + } else if (mountType === 'group') { + OC.Notification.show(t('files', + 'This group folder is full, files can not be updated or synced anymore!'), + {type: 'error'} + ); + } else if (mountType === 'external') { + OC.Notification.show(t('files', + 'This external storage is full, files can not be updated or synced anymore!'), + {type : 'error'} + ); + } else { + OC.Notification.show(t('files', + 'Your storage is full, files can not be updated or synced anymore!'), + {type: 'error'} + ); } - OC.Notification.show(t('files', - 'Your storage is full, files can not be updated or synced anymore!'), - {type : 'error'} - ); - return; - } - if (usedSpacePercent > 90) { + } else if (usedSpacePercent > 90) { if (owner !== OC.getCurrentUser().uid) { OC.Notification.show(t('files', 'Storage of {owner} is almost full ({usedSpacePercent}%)', { @@ -180,12 +190,24 @@ type: 'error' } ); - return; + } else if (mountType === 'group') { + OC.Notification.show(t('files', + 'This group folder is almost full ({usedSpacePercent}%)', + {usedSpacePercent: usedSpacePercent}), + {type : 'error'} + ); + } else if (mountType === 'external') { + OC.Notification.show(t('files', + 'This external storage is almost full ({usedSpacePercent}%)', + {usedSpacePercent: usedSpacePercent}), + {type : 'error'} + ); + } else { + OC.Notification.show(t('files', 'Your storage is almost full ({usedSpacePercent}%)', + {usedSpacePercent: usedSpacePercent}), + {type : 'error'} + ); } - OC.Notification.show(t('files', 'Your storage is almost full ({usedSpacePercent}%)', - {usedSpacePercent: usedSpacePercent}), - {type : 'error'} - ); } }, diff --git a/apps/files/lib/Helper.php b/apps/files/lib/Helper.php index 3431fb2ffc..1f728565ca 100644 --- a/apps/files/lib/Helper.php +++ b/apps/files/lib/Helper.php @@ -63,6 +63,7 @@ class Helper { 'usedSpacePercent' => (int)$storageInfo['relative'], 'owner' => $storageInfo['owner'], 'ownerDisplayName' => $storageInfo['ownerDisplayName'], + 'mountType' => $storageInfo['mountType'], ]; } diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php index 8cd492de11..d9c0c16de0 100644 --- a/lib/private/legacy/OC_Helper.php +++ b/lib/private/legacy/OC_Helper.php @@ -495,7 +495,8 @@ class OC_Helper { $used = 0; } $quota = \OCP\Files\FileInfo::SPACE_UNLIMITED; - $storage = $rootInfo->getStorage(); + $mount = $rootInfo->getMountPoint(); + $storage = $mount->getStorage(); $sourceStorage = $storage; if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { $includeExtStorage = false; @@ -553,6 +554,7 @@ class OC_Helper { 'relative' => $relative, 'owner' => $ownerId, 'ownerDisplayName' => $ownerDisplayName, + 'mountType' => $mount->getMountType() ]; } From a004eedd1effdea70e3bb2afb062c94069d7b648 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 26 Aug 2020 15:46:24 +0200 Subject: [PATCH 2/2] fix tests Signed-off-by: Robin Appelman --- .../tests/unit/Connector/Sabre/DirectoryTest.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php index 69b2dd5877..db79ea21b0 100644 --- a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php @@ -32,6 +32,7 @@ use OC\Files\FileInfo; use OC\Files\Storage\Wrapper\Quota; use OCA\DAV\Connector\Sabre\Directory; use OCP\Files\ForbiddenException; +use OCP\Files\Mount\IMountPoint; class TestViewDirectory extends \OC\Files\View { private $updatables; @@ -269,9 +270,12 @@ class DirectoryTest extends \Test\TestCase { } public function testGetQuotaInfoUnlimited() { + $mountPoint = $this->createMock(IMountPoint::class); $storage = $this->getMockBuilder(Quota::class) ->disableOriginalConstructor() ->getMock(); + $mountPoint->method('getStorage') + ->willReturn($storage); $storage->expects($this->any()) ->method('instanceOfStorage') @@ -292,8 +296,8 @@ class DirectoryTest extends \Test\TestCase { ->willReturn(200); $this->info->expects($this->once()) - ->method('getStorage') - ->willReturn($storage); + ->method('getMountPoint') + ->willReturn($mountPoint); $this->view->expects($this->once()) ->method('getFileInfo') @@ -304,9 +308,12 @@ class DirectoryTest extends \Test\TestCase { } public function testGetQuotaInfoSpecific() { + $mountPoint = $this->createMock(IMountPoint::class); $storage = $this->getMockBuilder(Quota::class) ->disableOriginalConstructor() ->getMock(); + $mountPoint->method('getStorage') + ->willReturn($storage); $storage->expects($this->any()) ->method('instanceOfStorage') @@ -328,8 +335,8 @@ class DirectoryTest extends \Test\TestCase { ->willReturn(200); $this->info->expects($this->once()) - ->method('getStorage') - ->willReturn($storage); + ->method('getMountPoint') + ->willReturn($mountPoint); $this->view->expects($this->once()) ->method('getFileInfo')