Fix enforced share expiration date to be based on share time
This commit is contained in:
parent
61598e7bb5
commit
4fea521102
|
@ -1353,6 +1353,18 @@ OC.Util = {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the time component from a given date
|
||||||
|
*
|
||||||
|
* @param {Date} date date
|
||||||
|
* @return {Date} date with stripped time
|
||||||
|
*/
|
||||||
|
stripTime: function(date) {
|
||||||
|
// FIXME: likely to break when crossing DST
|
||||||
|
// would be better to use a library like momentJS
|
||||||
|
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -436,7 +436,7 @@ OC.Share={
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (share.expiration != null) {
|
if (share.expiration != null) {
|
||||||
OC.Share.showExpirationDate(share.expiration);
|
OC.Share.showExpirationDate(share.expiration, share.stime);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -716,7 +716,24 @@ OC.Share={
|
||||||
dirname:function(path) {
|
dirname:function(path) {
|
||||||
return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
|
return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
|
||||||
},
|
},
|
||||||
showExpirationDate:function(date) {
|
/**
|
||||||
|
* Displays the expiration date field
|
||||||
|
*
|
||||||
|
* @param {Date} date current expiration date
|
||||||
|
* @param {int} [shareTime] share timestamp in seconds, defaults to now
|
||||||
|
*/
|
||||||
|
showExpirationDate:function(date, shareTime) {
|
||||||
|
var now = new Date();
|
||||||
|
var datePickerOptions = {
|
||||||
|
minDate: now,
|
||||||
|
maxDate: null
|
||||||
|
};
|
||||||
|
if (_.isNumber(shareTime)) {
|
||||||
|
shareTime = new Date(shareTime * 1000);
|
||||||
|
}
|
||||||
|
if (!shareTime) {
|
||||||
|
shareTime = now;
|
||||||
|
}
|
||||||
$('#expirationCheckbox').attr('checked', true);
|
$('#expirationCheckbox').attr('checked', true);
|
||||||
$('#expirationDate').val(date);
|
$('#expirationDate').val(date);
|
||||||
$('#expirationDate').show('blind');
|
$('#expirationDate').show('blind');
|
||||||
|
@ -726,13 +743,14 @@ OC.Share={
|
||||||
});
|
});
|
||||||
if (oc_appconfig.core.defaultExpireDateEnforced) {
|
if (oc_appconfig.core.defaultExpireDateEnforced) {
|
||||||
$('#expirationCheckbox').attr('disabled', true);
|
$('#expirationCheckbox').attr('disabled', true);
|
||||||
$.datepicker.setDefaults({
|
shareTime = OC.Util.stripTime(shareTime).getTime();
|
||||||
maxDate : new Date(date.replace(' 00:00:00', ''))
|
// max date is share date + X days
|
||||||
});
|
datePickerOptions.maxDate = new Date(shareTime + oc_appconfig.core.defaultExpireDate * 24 * 3600 * 1000);
|
||||||
}
|
}
|
||||||
if(oc_appconfig.core.defaultExpireDateEnabled) {
|
if(oc_appconfig.core.defaultExpireDateEnabled) {
|
||||||
$('#defaultExpireMessage').show('blind');
|
$('#defaultExpireMessage').show('blind');
|
||||||
}
|
}
|
||||||
|
$.datepicker.setDefaults(datePickerOptions);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -466,6 +466,12 @@ describe('Core base tests', function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('stripTime', function() {
|
||||||
|
it('strips time from dates', function() {
|
||||||
|
expect(OC.Util.stripTime(new Date(2014, 2, 24, 15, 4, 45, 24)))
|
||||||
|
.toEqual(new Date(2014, 2, 24, 0, 0, 0, 0));
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -83,16 +83,6 @@ describe('OC.Share tests', function() {
|
||||||
expect($el.attr('data-item-source')).toEqual('123');
|
expect($el.attr('data-item-source')).toEqual('123');
|
||||||
// TODO: expect that other parts are rendered correctly
|
// TODO: expect that other parts are rendered correctly
|
||||||
});
|
});
|
||||||
it('shows default expiration date when set', function() {
|
|
||||||
oc_appconfig.core.defaultExpireDateEnabled = "yes";
|
|
||||||
oc_appconfig.core.defaultExpireDate = '';
|
|
||||||
// TODO: expect that default date was set
|
|
||||||
});
|
|
||||||
it('shows default expiration date is set but disabled', function() {
|
|
||||||
oc_appconfig.core.defaultExpireDateEnabled = "no";
|
|
||||||
oc_appconfig.core.defaultExpireDate = '';
|
|
||||||
// TODO: expect that default date was NOT set
|
|
||||||
});
|
|
||||||
describe('Share with link', function() {
|
describe('Share with link', function() {
|
||||||
// TODO: test ajax calls
|
// TODO: test ajax calls
|
||||||
// TODO: test password field visibility (whenever enforced or not)
|
// TODO: test password field visibility (whenever enforced or not)
|
||||||
|
@ -265,6 +255,135 @@ describe('OC.Share tests', function() {
|
||||||
OC.linkTo('', 'public.php')+'?service=files&t=anothertoken';
|
OC.linkTo('', 'public.php')+'?service=files&t=anothertoken';
|
||||||
expect($('#dropdown #linkText').val()).toEqual(link);
|
expect($('#dropdown #linkText').val()).toEqual(link);
|
||||||
});
|
});
|
||||||
|
describe('expiration date', function() {
|
||||||
|
var shareData;
|
||||||
|
var shareItem;
|
||||||
|
var clock;
|
||||||
|
|
||||||
|
function showDropDown() {
|
||||||
|
OC.Share.showDropDown(
|
||||||
|
'file',
|
||||||
|
123,
|
||||||
|
$container,
|
||||||
|
'http://localhost/dummylink',
|
||||||
|
31,
|
||||||
|
'folder'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
// pick a fake date
|
||||||
|
clock = sinon.useFakeTimers(new Date(2014, 0, 20, 14, 0, 0).getTime());
|
||||||
|
shareItem = {
|
||||||
|
displayname_owner: 'root',
|
||||||
|
expiration: null,
|
||||||
|
file_source: 123,
|
||||||
|
file_target: '/folder',
|
||||||
|
id: 20,
|
||||||
|
item_source: '123',
|
||||||
|
item_type: 'folder',
|
||||||
|
mail_send: '0',
|
||||||
|
parent: null,
|
||||||
|
path: '/folder',
|
||||||
|
permissions: OC.PERMISSION_READ,
|
||||||
|
share_type: OC.Share.SHARE_TYPE_LINK,
|
||||||
|
share_with: null,
|
||||||
|
stime: 1403884258,
|
||||||
|
storage: 1,
|
||||||
|
token: 'tehtoken',
|
||||||
|
uid_owner: 'root'
|
||||||
|
};
|
||||||
|
shareData = {
|
||||||
|
reshare: [],
|
||||||
|
shares: []
|
||||||
|
};
|
||||||
|
loadItemStub.returns(shareData);
|
||||||
|
oc_appconfig.core.defaultExpireDate = 7;
|
||||||
|
oc_appconfig.core.defaultExpireDateEnabled = false;
|
||||||
|
oc_appconfig.core.defaultExpireDateEnforced = false;
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
clock.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not check expiration date checkbox when no date was set', function() {
|
||||||
|
shareItem.expiration = null;
|
||||||
|
shareData.shares.push(shareItem);
|
||||||
|
showDropDown();
|
||||||
|
expect($('#dropdown [name=expirationCheckbox]').prop('checked')).toEqual(false);
|
||||||
|
expect($('#dropdown #expirationDate').val()).toEqual('');
|
||||||
|
});
|
||||||
|
it('does not check expiration date checkbox for new share', function() {
|
||||||
|
showDropDown();
|
||||||
|
expect($('#dropdown [name=expirationCheckbox]').prop('checked')).toEqual(false);
|
||||||
|
expect($('#dropdown #expirationDate').val()).toEqual('');
|
||||||
|
});
|
||||||
|
it('checks expiration date checkbox and populates field when expiration date was set', function() {
|
||||||
|
shareItem.expiration = 1234;
|
||||||
|
shareData.shares.push(shareItem);
|
||||||
|
showDropDown();
|
||||||
|
expect($('#dropdown [name=expirationCheckbox]').prop('checked')).toEqual(true);
|
||||||
|
expect($('#dropdown #expirationDate').val()).toEqual('1234');
|
||||||
|
});
|
||||||
|
it('sets default date when default date setting is enabled', function() {
|
||||||
|
/* jshint camelcase:false */
|
||||||
|
oc_appconfig.core.defaultExpireDateEnabled = true;
|
||||||
|
showDropDown();
|
||||||
|
$('#dropdown [name=linkCheckbox]').click();
|
||||||
|
// enabled by default
|
||||||
|
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 allowed
|
||||||
|
$('#dropdown [name=expirationCheckbox]').click();
|
||||||
|
expect($('#dropdown [name=expirationCheckbox]').prop('checked')).toEqual(false);
|
||||||
|
});
|
||||||
|
it('enforces default date when enforced date setting is enabled', function() {
|
||||||
|
/* jshint camelcase:false */
|
||||||
|
oc_appconfig.core.defaultExpireDateEnabled = true;
|
||||||
|
oc_appconfig.core.defaultExpireDateEnforced = true;
|
||||||
|
showDropDown();
|
||||||
|
$('#dropdown [name=linkCheckbox]').click();
|
||||||
|
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('sets picker minDate to today and no maxDate by default', function() {
|
||||||
|
showDropDown();
|
||||||
|
$('#dropdown [name=linkCheckbox]').click();
|
||||||
|
$('#dropdown [name=expirationCheckbox]').click();
|
||||||
|
expect($.datepicker._defaults.minDate).toEqual(new Date());
|
||||||
|
expect($.datepicker._defaults.maxDate).toEqual(null);
|
||||||
|
});
|
||||||
|
it('limits the date range to X days after share time when enforced', function() {
|
||||||
|
/* jshint camelcase:false */
|
||||||
|
oc_appconfig.core.defaultExpireDateEnabled = true;
|
||||||
|
oc_appconfig.core.defaultExpireDateEnforced = true;
|
||||||
|
showDropDown();
|
||||||
|
$('#dropdown [name=linkCheckbox]').click();
|
||||||
|
expect($.datepicker._defaults.minDate).toEqual(new Date());
|
||||||
|
expect($.datepicker._defaults.maxDate).toEqual(new Date(2014, 0, 27, 0, 0, 0, 0));
|
||||||
|
});
|
||||||
|
it('limits the date range to X days after share time when enforced, even when redisplayed the next days', function() {
|
||||||
|
// item exists, was created two days ago
|
||||||
|
shareItem.expiration = '2014-1-27';
|
||||||
|
// share time has time component but must be stripped later
|
||||||
|
shareItem.stime = new Date(2014, 0, 20, 11, 0, 25).getTime() / 1000;
|
||||||
|
shareData.shares.push(shareItem);
|
||||||
|
/* jshint camelcase:false */
|
||||||
|
oc_appconfig.core.defaultExpireDateEnabled = true;
|
||||||
|
oc_appconfig.core.defaultExpireDateEnforced = true;
|
||||||
|
showDropDown();
|
||||||
|
expect($.datepicker._defaults.minDate).toEqual(new Date());
|
||||||
|
expect($.datepicker._defaults.maxDate).toEqual(new Date(2014, 0, 27, 0, 0, 0, 0));
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('"sharesChanged" event', function() {
|
describe('"sharesChanged" event', function() {
|
||||||
var autocompleteOptions;
|
var autocompleteOptions;
|
||||||
|
|
Loading…
Reference in New Issue