Skip to content

Commit

Permalink
Merge pull request #22421 from nextcloud/group-folder-quota-warning
Browse files Browse the repository at this point in the history
show better quota warning for group folders and external storage
  • Loading branch information
rullzer authored Aug 26, 2020
2 parents df99d8f + 06ae93b commit 7685d1f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 19 deletions.
15 changes: 11 additions & 4 deletions apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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 {
private $updatables;
Expand Down Expand Up @@ -270,9 +271,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 @@ -293,8 +297,8 @@ public function testGetQuotaInfoUnlimited() {
->willReturn(200);

$this->info->expects($this->once())
->method('getStorage')
->willReturn($storage);
->method('getMountPoint')
->willReturn($mountPoint);

$this->view->expects($this->once())
->method('getFileInfo')
Expand All @@ -305,9 +309,12 @@ public function testGetQuotaInfoUnlimited() {
}

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 @@ -329,8 +336,8 @@ public function testGetQuotaInfoSpecific() {
->willReturn(200);

$this->info->expects($this->once())
->method('getStorage')
->willReturn($storage);
->method('getMountPoint')
->willReturn($mountPoint);

$this->view->expects($this->once())
->method('getFileInfo')
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 @@ -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}%)',
{
Expand All @@ -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'}
);
}
},

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 @@ -63,6 +63,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/OC_Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,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 @@ -553,6 +554,7 @@ public static function getStorageInfo($path, $rootInfo = null) {
'relative' => $relative,
'owner' => $ownerId,
'ownerDisplayName' => $ownerDisplayName,
'mountType' => $mount->getMountType()
];
}

Expand Down

0 comments on commit 7685d1f

Please sign in to comment.