[Pkg-owncloud-commits] [owncloud] 75/129: Fix file upload, conflict dialog, also in public link

David Prévot taffit at moszumanska.debian.org
Thu Nov 5 01:04:25 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit d3d18b1abc1aa00ba78b71b67aa61223a1628fea
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Wed Oct 21 11:46:51 2015 +0200

    Fix file upload, conflict dialog, also in public link
    
    - Use "FileList" instead of "OCA.Files.App.fileList" that doesn't exist in public
    link page.
    - Fix public link upload by properly adding the form data using a new
      utility function "addFormData". That one is needed because IE8 upload
      and regular upload use a different format...
---
 apps/files/js/file-upload.js          | 44 ++++++++++++----
 apps/files/tests/js/fileUploadSpec.js | 96 +++++++++++++++++++++++++++++++++++
 2 files changed, 129 insertions(+), 11 deletions(-)

diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js
index 77b85ec..d419cb3 100644
--- a/apps/files/js/file-upload.js
+++ b/apps/files/js/file-upload.js
@@ -18,7 +18,7 @@
  *    - TODO music upload button
  */
 
-/* global jQuery, oc_requesttoken, humanFileSize */
+/* global jQuery, oc_requesttoken, humanFileSize, FileList */
 
 /**
  * Function that will allow us to know if Ajax uploads are supported
@@ -48,6 +48,26 @@ function supportAjaxUploadWithProgress() {
 }
 
 /**
+ * Add form data into the given form data
+ *
+ * @param {Array|Object} formData form data which can either be an array or an object
+ * @param {Object} newData key-values to add to the form data
+ *
+ * @return updated form data
+ */
+function addFormData(formData, newData) {
+	// in IE8, formData is an array instead of object
+	if (_.isArray(formData)) {
+		_.each(newData, function(value, key) {
+			formData.push({name: key, value: value});
+		});
+	} else {
+		formData = _.extend(formData, newData);
+	}
+	return formData;
+}
+
+/**
  * keeps track of uploads in progress and implements callbacks for the conflicts dialog
  * @namespace
  */
@@ -143,9 +163,9 @@ OC.Upload = {
 			data.data.append('resolution', 'replace');
 		} else {
 			if (!data.formData) {
-				data.formData = [];
+				data.formData = {};
 			}
-			data.formData.push({name:'resolution', value:'replace'}); //hack for ie8
+			addFormData(data.formData, {resolution: 'replace'});
 		}
 		data.submit();
 	},
@@ -159,9 +179,9 @@ OC.Upload = {
 			data.data.append('resolution', 'autorename');
 		} else {
 			if (!data.formData) {
-				data.formData = [];
+				data.formData = {};
 			}
-			data.formData.push({name:'resolution', value:'autorename'}); //hack for ie8
+			addFormData(data.formData, {resolution: 'autorename'});
 		}
 		data.submit();
 	},
@@ -185,7 +205,7 @@ OC.Upload = {
 	 * @param {function} callbacks.onCancel
 	 */
 	checkExistingFiles: function (selection, callbacks) {
-		var fileList = OCA.Files.App.fileList;
+		var fileList = FileList;
 		var conflicts = [];
 		// only keep non-conflicting uploads
 		selection.uploads = _.filter(selection.uploads, function(upload) {
@@ -402,17 +422,19 @@ OC.Upload = {
 				submit: function(e, data) {
 					OC.Upload.rememberUpload(data);
 					if (!data.formData) {
-						data.formData = [];
+						data.formData = {};
 					}
 
 					var fileDirectory = '';
 					if(typeof data.files[0].relativePath !== 'undefined') {
 						fileDirectory = data.files[0].relativePath;
 					}
-					// FIXME: prevent re-adding the same
-					data.formData.push({name: 'requesttoken', value: oc_requesttoken});
-					data.formData.push({name: 'dir', value: data.targetDir || FileList.getCurrentDirectory()});
-					data.formData.push({name: 'file_directory', value: fileDirectory});
+
+					addFormData(data.formData, {
+						requesttoken: oc_requesttoken,
+						dir: data.targetDir || FileList.getCurrentDirectory(),
+						file_directory: fileDirectory
+					});
 				},
 				fail: function(e, data) {
 					OC.Upload.log('fail', e, data);
diff --git a/apps/files/tests/js/fileUploadSpec.js b/apps/files/tests/js/fileUploadSpec.js
index cad8468..a49a5d4 100644
--- a/apps/files/tests/js/fileUploadSpec.js
+++ b/apps/files/tests/js/fileUploadSpec.js
@@ -117,4 +117,100 @@ describe('OC.Upload tests', function() {
 			);
 		});
 	});
+	describe('Upload conflicts', function() {
+		var oldFileList;
+		var conflictDialogStub;
+		var callbacks;
+
+		beforeEach(function() {
+			oldFileList = FileList;
+			$('#testArea').append(
+				'<div id="tableContainer">' +
+				'<table id="filestable">' +
+				'<thead><tr>' +
+				'<th id="headerName" class="hidden column-name">' +
+				'<input type="checkbox" id="select_all_files" class="select-all">' +
+				'<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' +
+				'<span id="selectedActionsList" class="selectedActions hidden">' +
+				'<a href class="download"><img src="actions/download.svg">Download</a>' +
+				'<a href class="delete-selected">Delete</a></span>' +
+				'</th>' +
+				'<th class="hidden column-size"><a class="columntitle" data-sort="size"><span class="sort-indicator"></span></a></th>' +
+				'<th class="hidden column-mtime"><a class="columntitle" data-sort="mtime"><span class="sort-indicator"></span></a></th>' +
+				'</tr></thead>' +
+				'<tbody id="fileList"></tbody>' +
+				'<tfoot></tfoot>' +
+				'</table>' +
+				'</div>'
+			);
+			FileList = new OCA.Files.FileList($('#tableContainer'));
+
+			FileList.add({name: 'conflict.txt', mimetype: 'text/plain'});
+			FileList.add({name: 'conflict2.txt', mimetype: 'text/plain'});
+
+			conflictDialogStub = sinon.stub(OC.dialogs, 'fileexists');
+			callbacks = {
+				onNoConflicts: sinon.stub()
+			};
+		});
+		afterEach(function() {
+			conflictDialogStub.restore();
+
+			FileList.destroy();
+			FileList = oldFileList;
+		});
+		it('does not show conflict dialog when no client side conflict', function() {
+			var selection = {
+				// yes, the format of uploads is weird...
+				uploads: [
+					{files: [{name: 'noconflict.txt'}]},
+					{files: [{name: 'noconflict2.txt'}]}
+				]
+			};
+
+			OC.Upload.checkExistingFiles(selection, callbacks);
+
+			expect(conflictDialogStub.notCalled).toEqual(true);
+			expect(callbacks.onNoConflicts.calledOnce).toEqual(true);
+			expect(callbacks.onNoConflicts.calledWith(selection)).toEqual(true);
+		});
+		it('shows conflict dialog when no client side conflict', function() {
+			var selection = {
+				// yes, the format of uploads is weird...
+				uploads: [
+					{files: [{name: 'conflict.txt'}]},
+					{files: [{name: 'conflict2.txt'}]},
+					{files: [{name: 'noconflict.txt'}]}
+				]
+			};
+
+			var deferred = $.Deferred();
+			conflictDialogStub.returns(deferred.promise());
+			deferred.resolve();
+
+			OC.Upload.checkExistingFiles(selection, callbacks);
+
+			expect(conflictDialogStub.callCount).toEqual(3);
+			expect(conflictDialogStub.getCall(1).args[0])
+				.toEqual({files: [ { name: 'conflict.txt' } ]});
+			expect(conflictDialogStub.getCall(1).args[1])
+				.toEqual({ name: 'conflict.txt', mimetype: 'text/plain', directory: '/' });
+			expect(conflictDialogStub.getCall(1).args[2]).toEqual({ name: 'conflict.txt' });
+
+			// yes, the dialog must be called several times...
+			expect(conflictDialogStub.getCall(2).args[0]).toEqual({
+				files: [ { name: 'conflict2.txt' } ]
+			});
+			expect(conflictDialogStub.getCall(2).args[1])
+				.toEqual({ name: 'conflict2.txt', mimetype: 'text/plain', directory: '/' });
+			expect(conflictDialogStub.getCall(2).args[2]).toEqual({ name: 'conflict2.txt' });
+
+			expect(callbacks.onNoConflicts.calledOnce).toEqual(true);
+			expect(callbacks.onNoConflicts.calledWith({
+				uploads: [
+					{files: [{name: 'noconflict.txt'}]}
+				]
+			})).toEqual(true);
+		});
+	});
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list