Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable18] show better quota warning for group folders and external storage #22443

Merged
merged 2 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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 {

Expand Down Expand Up @@ -98,7 +99,7 @@ private function getDir($path = '/') {
return new Directory($this->view, $this->info);
}


public function testDeleteRootFolderFails() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

Expand All @@ -111,7 +112,7 @@ public function testDeleteRootFolderFails() {
$dir->delete();
}


public function testDeleteForbidden() {
$this->expectException(\OCA\DAV\Connector\Sabre\Exception\Forbidden::class);

Expand All @@ -130,7 +131,7 @@ public function testDeleteForbidden() {
$dir->delete();
}


public function testDeleteFolderWhenAllowed() {
// deletion allowed
$this->info->expects($this->once())
Expand All @@ -147,7 +148,7 @@ public function testDeleteFolderWhenAllowed() {
$dir->delete();
}


public function testDeleteFolderFailsWhenNotAllowed() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

Expand All @@ -159,7 +160,7 @@ public function testDeleteFolderFailsWhenNotAllowed() {
$dir->delete();
}


public function testDeleteFolderThrowsWhenDeletionFailed() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

Expand Down Expand Up @@ -217,7 +218,7 @@ public function testGetChildren() {
$dir->getChildren();
}


public function testGetChildrenNoPermission() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

Expand All @@ -230,7 +231,7 @@ public function testGetChildrenNoPermission() {
$dir->getChildren();
}


public function testGetChildNoPermission() {
$this->expectException(\Sabre\DAV\Exception\NotFound::class);

Expand All @@ -242,7 +243,7 @@ public function testGetChildNoPermission() {
$dir->getChild('test');
}


public function testGetChildThrowStorageNotAvailableException() {
$this->expectException(\Sabre\DAV\Exception\ServiceUnavailable::class);

Expand All @@ -254,7 +255,7 @@ public function testGetChildThrowStorageNotAvailableException() {
$dir->getChild('.');
}


public function testGetChildThrowInvalidPath() {
$this->expectException(\OCA\DAV\Connector\Sabre\Exception\InvalidPath::class);

Expand All @@ -269,9 +270,12 @@ public function testGetChildThrowInvalidPath() {
}

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')
Expand All @@ -292,17 +296,20 @@ public function testGetQuotaInfoUnlimited() {
->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')
Expand All @@ -324,8 +331,8 @@ public function testGetQuotaInfoSpecific() {
->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
Expand Down Expand Up @@ -404,7 +411,7 @@ private function moveTest($source, $destination, $updatables, $deletables) {
$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');
Expand Down
50 changes: 36 additions & 14 deletions apps/files/js/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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}%)',
{
Expand All @@ -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'}
);
}
},

Expand Down
1 change: 1 addition & 0 deletions apps/files/lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static function buildFileStorageStatistics($dir) {
'usedSpacePercent' => (int)$storageInfo['relative'],
'owner' => $storageInfo['owner'],
'ownerDisplayName' => $storageInfo['ownerDisplayName'],
'mountType' => $storageInfo['mountType'],
];
}

Expand Down
4 changes: 3 additions & 1 deletion lib/private/legacy/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ public static function getStorageInfo($path, $rootInfo = null) {
$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;
Expand Down Expand Up @@ -552,6 +553,7 @@ public static function getStorageInfo($path, $rootInfo = null) {
'relative' => $relative,
'owner' => $ownerId,
'ownerDisplayName' => $ownerDisplayName,
'mountType' => $mount->getMountType()
];
}

Expand Down