summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-10-01 15:11:16 +0200
committerGitHub <noreply@github.com>2020-10-01 15:11:16 +0200
commit07c188e7e3bbb0d60070ee8824bd8ccdeaf048a7 (patch)
treed9bb512412b961fe41ae84375e12c67bea7651d2
parent79660f68281f9a5d3aa06e394886d228b353a318 (diff)
parent89315a1e87012cb966d84dc2b81e453a31c923e2 (diff)
downloadnextcloud-server-07c188e7e3bbb0d60070ee8824bd8ccdeaf048a7.tar.gz
nextcloud-server-07c188e7e3bbb0d60070ee8824bd8ccdeaf048a7.zip
Merge pull request #22443 from nextcloud/backport/22421/stable18
[stable18] show better quota warning for group folders and external storage
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php35
-rw-r--r--apps/files/js/files.js50
-rw-r--r--apps/files/lib/Helper.php1
-rw-r--r--lib/private/legacy/helper.php4
4 files changed, 61 insertions, 29 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
index 528327a681a..641b03e0781 100644
--- a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
@@ -31,6 +31,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 {
@@ -98,7 +99,7 @@ class DirectoryTest extends \Test\TestCase {
return new Directory($this->view, $this->info);
}
-
+
public function testDeleteRootFolderFails() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
@@ -111,7 +112,7 @@ class DirectoryTest extends \Test\TestCase {
$dir->delete();
}
-
+
public function testDeleteForbidden() {
$this->expectException(\OCA\DAV\Connector\Sabre\Exception\Forbidden::class);
@@ -130,7 +131,7 @@ class DirectoryTest extends \Test\TestCase {
$dir->delete();
}
-
+
public function testDeleteFolderWhenAllowed() {
// deletion allowed
$this->info->expects($this->once())
@@ -147,7 +148,7 @@ class DirectoryTest extends \Test\TestCase {
$dir->delete();
}
-
+
public function testDeleteFolderFailsWhenNotAllowed() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
@@ -159,7 +160,7 @@ class DirectoryTest extends \Test\TestCase {
$dir->delete();
}
-
+
public function testDeleteFolderThrowsWhenDeletionFailed() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
@@ -217,7 +218,7 @@ class DirectoryTest extends \Test\TestCase {
$dir->getChildren();
}
-
+
public function testGetChildrenNoPermission() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
@@ -230,7 +231,7 @@ class DirectoryTest extends \Test\TestCase {
$dir->getChildren();
}
-
+
public function testGetChildNoPermission() {
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
@@ -242,7 +243,7 @@ class DirectoryTest extends \Test\TestCase {
$dir->getChild('test');
}
-
+
public function testGetChildThrowStorageNotAvailableException() {
$this->expectException(\Sabre\DAV\Exception\ServiceUnavailable::class);
@@ -254,7 +255,7 @@ class DirectoryTest extends \Test\TestCase {
$dir->getChild('.');
}
-
+
public function testGetChildThrowInvalidPath() {
$this->expectException(\OCA\DAV\Connector\Sabre\Exception\InvalidPath::class);
@@ -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,17 +296,20 @@ class DirectoryTest extends \Test\TestCase {
->will($this->returnValue(200));
$this->info->expects($this->once())
- ->method('getStorage')
- ->will($this->returnValue($storage));
+ ->method('getMountPoint')
+ ->willReturn($mountPoint);
$dir = new Directory($this->view, $this->info);
$this->assertEquals([200, -3], $dir->getQuotaInfo()); //200 used, unlimited
}
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')
@@ -324,8 +331,8 @@ class DirectoryTest extends \Test\TestCase {
->will($this->returnValue(200));
$this->info->expects($this->once())
- ->method('getStorage')
- ->will($this->returnValue($storage));
+ ->method('getMountPoint')
+ ->willReturn($mountPoint);
$dir = new Directory($this->view, $this->info);
$this->assertEquals([200, 800], $dir->getQuotaInfo()); //200 used, 800 free
@@ -404,7 +411,7 @@ class DirectoryTest extends \Test\TestCase {
$this->assertTrue($targetNode->moveInto(basename($destination), $source, $sourceNode));
}
-
+
public function testFailingMove() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
$this->expectExceptionMessage('Could not copy directory b, target exists');
diff --git a/apps/files/js/files.js b/apps/files/js/files.js
index 4d285e426d5..977e642948c 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();
@@ -153,21 +154,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}%)',
{
@@ -178,12 +188,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 f88689af266..46c97db94b9 100644
--- a/apps/files/lib/Helper.php
+++ b/apps/files/lib/Helper.php
@@ -62,6 +62,7 @@ class Helper {
'usedSpacePercent' => (int)$storageInfo['relative'],
'owner' => $storageInfo['owner'],
'ownerDisplayName' => $storageInfo['ownerDisplayName'],
+ 'mountType' => $storageInfo['mountType'],
];
}
diff --git a/lib/private/legacy/helper.php b/lib/private/legacy/helper.php
index 19c9ca7f91c..0f7b2d1b3af 100644
--- a/lib/private/legacy/helper.php
+++ b/lib/private/legacy/helper.php
@@ -494,7 +494,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;
@@ -552,6 +553,7 @@ class OC_Helper {
'relative' => $relative,
'owner' => $ownerId,
'ownerDisplayName' => $ownerDisplayName,
+ 'mountType' => $mount->getMountType()
];
}