[Pkg-owncloud-commits] [owncloud] 110/123: Fix to make sure expiration date is properly set

David Prévot taffit at moszumanska.debian.org
Tue May 19 23:55: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 efd6fec57dcac0b4b9d79a9d98940329b40e6343
Author: Roeland Jago Douma <roeland at famdouma.nl>
Date:   Fri Apr 17 09:36:50 2015 +0200

    Fix to make sure expiration date is properly set
    
    This did not happen correctly when the password was enforced since a
    different code path was taken.
    
    * moved generation of the default date string to separate function
    * added unit test
---
 core/js/share.js                 | 36 ++++++++++++++++++++++++++----------
 core/js/tests/specs/shareSpec.js | 27 +++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/core/js/share.js b/core/js/share.js
index 6723b82..9f01a5f 100644
--- a/core/js/share.js
+++ b/core/js/share.js
@@ -839,6 +839,24 @@ OC.Share={
 			$('#defaultExpireMessage').slideDown(OC.menuSpeed);
 		}
 		$.datepicker.setDefaults(datePickerOptions);
+	},
+	/**
+	 * Get the default Expire date
+	 *
+	 * @return {String} The expire date
+	 */
+	getDefaultExpirationDate:function() {
+		var expireDateString = '';
+		if (oc_appconfig.core.defaultExpireDateEnabled) {
+			var date = new Date().getTime();
+			var expireAfterMs = oc_appconfig.core.defaultExpireDate * 24 * 60 * 60 * 1000;
+			var expireDate = new Date(date + expireAfterMs);
+			var month = expireDate.getMonth() + 1;
+			var year = expireDate.getFullYear();
+			var day = expireDate.getDate();
+			expireDateString = year + "-" + month + '-' + day + ' 00:00:00';
+		}
+		return expireDateString;
 	}
 };
 
@@ -987,17 +1005,9 @@ $(document).ready(function() {
 			// Reset link
 			$('#linkText').val('');
 			var expireDateString = '';
-			if (oc_appconfig.core.defaultExpireDateEnabled) {
-				var date = new Date().getTime();
-				var expireAfterMs = oc_appconfig.core.defaultExpireDate * 24 * 60 * 60 * 1000;
-				var expireDate = new Date(date + expireAfterMs);
-				var month = expireDate.getMonth() + 1;
-				var year = expireDate.getFullYear();
-				var day = expireDate.getDate();
-				expireDateString = year + "-" + month + '-' + day + ' 00:00:00';
-			}
 			// Create a link
 			if (oc_appconfig.core.enforcePasswordForPublicLink === false) {
+				expireDateString = OC.Share.getDefaultExpirationDate();
 				$loading.removeClass('hidden');
 				$button.addClass('hidden');
 				$button.prop('disabled', true);
@@ -1135,8 +1145,10 @@ $(document).ready(function() {
 				permissions = OC.PERMISSION_READ;
 			}
 
+			var expireDateString = OC.Share.getDefaultExpirationDate();
+
 			$loading.removeClass('hidden');
-			OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $('#linkPassText').val(), permissions, itemSourceName, function(data) {
+			OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $('#linkPassText').val(), permissions, itemSourceName, expireDateString, function(data) {
 				$loading.addClass('hidden');
 				linkPassText.val('');
 				linkPassText.attr('placeholder', t('core', 'Password protected'));
@@ -1145,8 +1157,12 @@ $(document).ready(function() {
 					OC.Share.showLink(data.token, "password set", itemSource);
 					OC.Share.updateIcon(itemType, itemSource);
 				}
+				$('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares}));
 			});
 
+			if (expireDateString !== '') {
+				OC.Share.showExpirationDate(expireDateString);
+			}
 		}
 	});
 
diff --git a/core/js/tests/specs/shareSpec.js b/core/js/tests/specs/shareSpec.js
index 3e9a0b2..aea333e 100644
--- a/core/js/tests/specs/shareSpec.js
+++ b/core/js/tests/specs/shareSpec.js
@@ -419,6 +419,7 @@ describe('OC.Share tests', function() {
 					};
 					loadItemStub.returns(shareData);
 					oc_appconfig.core.defaultExpireDate = 7;
+					oc_appconfig.core.enforcePasswordForPublicLink = false;
 					oc_appconfig.core.defaultExpireDateEnabled = false;
 					oc_appconfig.core.defaultExpireDateEnforced = false;
 				});
@@ -474,6 +475,32 @@ describe('OC.Share tests', function() {
 					$('#dropdown [name=expirationCheckbox]').click();
 					expect($('#dropdown [name=expirationCheckbox]').prop('checked')).toEqual(true);
 				});
+				it('enforces default date when enforced date setting is enabled and password is enforced', function() {
+					/* jshint camelcase:false */
+					oc_appconfig.core.enforcePasswordForPublicLink = true;
+					oc_appconfig.core.defaultExpireDateEnabled = true;
+					oc_appconfig.core.defaultExpireDateEnforced = true;
+					showDropDown();
+					$('#dropdown [name=linkCheckbox]').click();
+
+					//Enter password
+					$('#dropdown #linkPassText').val('foo');
+					$('#dropdown #linkPassText').trigger(new $.Event('keyup', {keyCode: 13}));
+					fakeServer.requests[0].respond(
+						200,
+						{ 'Content-Type': 'application/json' },
+						JSON.stringify({data: {token: 'xyz'}, status: 'success'})
+					);
+
+					expect($('#dropdown [name=expirationCheckbox]').prop('checked')).toEqual(true);
+					// TODO: those zeros must go...
+					expect($('#dropdown #expirationDate').val()).toEqual('2014-1-27 00:00:00');
+
+					// disabling is not allowed
+					expect($('#dropdown [name=expirationCheckbox]').prop('disabled')).toEqual(true);
+					$('#dropdown [name=expirationCheckbox]').click();
+					expect($('#dropdown [name=expirationCheckbox]').prop('checked')).toEqual(true);
+				});
 				it('displayes email form when sending emails is enabled', function() {
 					$('input[name=mailPublicNotificationEnabled]').val('yes');
 					showDropDown();

-- 
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