summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-11-19 10:40:16 +0100
committerGitHub <noreply@github.com>2020-11-19 10:40:16 +0100
commite5b977589af2601d031d73ec3746fbbaf9d8b8af (patch)
tree56601bc1de142419252632bac4a575ce93f41b4b
parent076130ba4650a7c719783f6ea30f281d68219ee9 (diff)
parenta297523381cad37d07e7d21bb574c4bb4139a8db (diff)
downloadnextcloud-server-e5b977589af2601d031d73ec3746fbbaf9d8b8af.tar.gz
nextcloud-server-e5b977589af2601d031d73ec3746fbbaf9d8b8af.zip
Merge pull request #24182 from nextcloud/backport/24102/stable19
[stable19] Check quota of subdirectories when uploading to them
-rw-r--r--apps/files/js/file-upload.js13
-rw-r--r--apps/files/js/filelist.js2
-rw-r--r--apps/files/tests/js/filelistSpec.js5
-rw-r--r--core/js/files/client.js7
-rw-r--r--core/js/files/fileinfo.js4
5 files changed, 27 insertions, 4 deletions
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js
index 691131293a8..3c0ca319225 100644
--- a/apps/files/js/file-upload.js
+++ b/apps/files/js/file-upload.js
@@ -918,7 +918,7 @@ OC.Uploader.prototype = _.extend({
*/
add: function(e, data) {
self.log('add', e, data);
- var that = $(this), freeSpace;
+ var that = $(this), freeSpace = 0;
var upload = new OC.FileUpload(self, data);
// can't link directly due to jQuery not liking cyclic deps on its ajax object
@@ -989,13 +989,20 @@ OC.Uploader.prototype = _.extend({
}
// check free space
- freeSpace = $('#free_space').val();
+ if (!self.fileList || upload.getTargetFolder() === self.fileList.getCurrentDirectory()) {
+ // Use global free space if there is no file list to check or the current directory is the target
+ freeSpace = $('#free_space').val()
+ } else if (upload.getTargetFolder().indexOf(self.fileList.getCurrentDirectory()) === 0) {
+ // Check subdirectory free space if file is uploaded there
+ var targetSubdir = upload._targetFolder.replace(self.fileList.getCurrentDirectory(), '')
+ freeSpace = parseInt(upload.uploader.fileList.getModelForFile(targetSubdir).get('quotaAvailableBytes'))
+ }
if (freeSpace >= 0 && selection.totalBytes > freeSpace) {
data.textStatus = 'notenoughspace';
data.errorThrown = t('files',
'Not enough free space, you are uploading {size1} but only {size2} is left', {
'size1': OC.Util.humanFileSize(selection.totalBytes),
- 'size2': OC.Util.humanFileSize($('#free_space').val())
+ 'size2': OC.Util.humanFileSize(freeSpace)
});
}
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index f7bc0ecd710..d41f8f7d838 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -1236,6 +1236,7 @@
mtime: parseInt($el.attr('data-mtime'), 10),
type: $el.attr('data-type'),
etag: $el.attr('data-etag'),
+ quotaAvailableBytes: $el.attr('data-quota'),
permissions: parseInt($el.attr('data-permissions'), 10),
hasPreview: $el.attr('data-has-preview') === 'true',
isEncrypted: $el.attr('data-e2eencrypted') === 'true'
@@ -1495,6 +1496,7 @@
"data-mime": mime,
"data-mtime": mtime,
"data-etag": fileData.etag,
+ "data-quota": fileData.quotaAvailableBytes,
"data-permissions": permissions,
"data-has-preview": fileData.hasPreview !== false,
"data-e2eencrypted": fileData.isEncrypted === true
diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js
index ee70a1452a9..90861faee55 100644
--- a/apps/files/tests/js/filelistSpec.js
+++ b/apps/files/tests/js/filelistSpec.js
@@ -2232,6 +2232,7 @@ describe('OCA.Files.FileList tests', function() {
type: 'file',
size: 12,
etag: 'abc',
+ quotaAvailableBytes: '-1',
permissions: OC.PERMISSION_ALL,
hasPreview: true,
isEncrypted: false
@@ -2243,6 +2244,7 @@ describe('OCA.Files.FileList tests', function() {
mimetype: 'application/pdf',
mtime: 234560000,
size: 58009,
+ quotaAvailableBytes: '-1',
etag: '123',
permissions: OC.PERMISSION_ALL,
hasPreview: true,
@@ -2255,6 +2257,7 @@ describe('OCA.Files.FileList tests', function() {
mimetype: 'httpd/unix-directory',
mtime: 134560000,
size: 250,
+ quotaAvailableBytes: '-1',
etag: '456',
permissions: OC.PERMISSION_ALL,
hasPreview: true,
@@ -2278,6 +2281,7 @@ describe('OCA.Files.FileList tests', function() {
mtime: 123456789,
type: 'file',
size: 12,
+ quotaAvailableBytes: '-1',
etag: 'abc',
permissions: OC.PERMISSION_ALL,
hasPreview: true,
@@ -2290,6 +2294,7 @@ describe('OCA.Files.FileList tests', function() {
mimetype: 'httpd/unix-directory',
mtime: 134560000,
size: 250,
+ quotaAvailableBytes: '-1',
etag: '456',
permissions: OC.PERMISSION_ALL,
hasPreview: true,
diff --git a/core/js/files/client.js b/core/js/files/client.js
index 0daf7c9dc3f..68ed1705e9a 100644
--- a/core/js/files/client.js
+++ b/core/js/files/client.js
@@ -79,6 +79,7 @@
Client.PROPERTY_GETCONTENTLENGTH = '{' + Client.NS_DAV + '}getcontentlength';
Client.PROPERTY_ISENCRYPTED = '{' + Client.NS_DAV + '}is-encrypted';
Client.PROPERTY_SHARE_PERMISSIONS = '{' + Client.NS_OCS + '}share-permissions';
+ Client.PROPERTY_QUOTA_AVAILABLE_BYTES = '{' + Client.NS_DAV + '}quota-available-bytes';
Client.PROTOCOL_HTTP = 'http';
Client.PROTOCOL_HTTPS = 'https';
@@ -117,6 +118,7 @@
* File sizes
*/
[Client.NS_DAV, 'getcontentlength'],
+ [Client.NS_DAV, 'quota-available-bytes'],
/**
* Preview availability
*/
@@ -394,6 +396,11 @@
data.mountType = mounTypeProp;
}
+ var quotaAvailableBytes = props['{' + Client.NS_DAV + '}quota-available-bytes']
+ if (!_.isUndefined(quotaAvailableBytes)) {
+ data.quotaAvailableBytes = quotaAvailableBytes
+ }
+
// extend the parsed data using the custom parsers
_.each(this._fileInfoParsers, function(parserFunction) {
_.extend(data, parserFunction(response, data) || {});
diff --git a/core/js/files/fileinfo.js b/core/js/files/fileinfo.js
index b4ac016f90c..b6385d40d78 100644
--- a/core/js/files/fileinfo.js
+++ b/core/js/files/fileinfo.js
@@ -137,7 +137,9 @@
/**
* @type int
*/
- sharePermissions: null
+ sharePermissions: null,
+
+ quotaAvailableBytes: -1,
};
if (!OC.Files) {