diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-05-28 10:28:33 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-05-28 10:28:33 +0200 |
commit | cd311c1ac11cfcb71e220df788b28f2d25adba5d (patch) | |
tree | 52e97cf60e714ca080d18c5bf39521645ea884bf | |
parent | d5d3cbd50d4effd280d3a7a4ee1c3cafca1ac9c8 (diff) | |
parent | 488c4a92dab13ab1f76ed04c7ac6cc29f14cf4dd (diff) | |
download | nextcloud-server-cd311c1ac11cfcb71e220df788b28f2d25adba5d.tar.gz nextcloud-server-cd311c1ac11cfcb71e220df788b28f2d25adba5d.zip |
Merge pull request #16423 from rullzer/backport_15738
[stable8] Fix to make sure expiration date is properly set
-rw-r--r-- | core/js/share.js | 36 | ||||
-rw-r--r-- | 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 128ac729e5d..b8cc74fdc61 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -802,6 +802,24 @@ OC.Share={ $('#defaultExpireMessage').show('blind'); } $.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; } }; @@ -946,17 +964,9 @@ $(document).ready(function() { if (this.checked) { 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); @@ -1090,8 +1100,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')); @@ -1100,8 +1112,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 7eb22261e10..90cc77120db 100644 --- a/core/js/tests/specs/shareSpec.js +++ b/core/js/tests/specs/shareSpec.js @@ -309,6 +309,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; }); @@ -364,6 +365,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(); |