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
This commit is contained in:
parent
73a3086945
commit
efd6fec57d
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue