Do not allow setting an expiration date in the past

Fix #7297
This commit is contained in:
Joas Schilling 2014-03-05 13:12:58 +01:00
parent 7edd8df07f
commit 80393d9c0f
2 changed files with 13 additions and 1 deletions

View File

@ -80,6 +80,14 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
break;
case 'setExpirationDate':
if (isset($_POST['date'])) {
$l = OC_L10N::get('core');
$date = new \DateTime($_POST['date']);
$today = new \DateTime('now');
if ($date < $today) {
OC_JSON::error(array('data' => array('message' => $l->t('Expiration date is in the past.'))));
return;
}
$return = OCP\Share::setExpirationDate($_POST['itemType'], $_POST['itemSource'], $_POST['date']);
($return) ? OC_JSON::success() : OC_JSON::error();
}

View File

@ -720,7 +720,11 @@ $(document).ready(function() {
var itemSource = $('#dropdown').data('item-source');
$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: $(this).val() }, function(result) {
if (!result || result.status !== 'success') {
OC.dialogs.alert(t('core', 'Error setting expiration date'), t('core', 'Error'));
if (!result.data.message) {
OC.dialogs.alert(t('core', 'Error setting expiration date'), t('core', 'Error'));
} else {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
}
}
});
});