From 80393d9c0ff44c0614960cc6b7b7d8cc5bd17743 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 5 Mar 2014 13:12:58 +0100 Subject: [PATCH 1/2] Do not allow setting an expiration date in the past Fix #7297 --- core/ajax/share.php | 8 ++++++++ core/js/share.js | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 86ee018e38..abcb4b5c22 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -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(); } diff --git a/core/js/share.js b/core/js/share.js index 0939259b7d..0b65e15309 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -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')); + } } }); }); From 7ab2632085440d3e792b4ccca3c527d26f10cad2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 19 Mar 2014 12:11:14 +0100 Subject: [PATCH 2/2] Use tipsy to display error when selecting a date in the past --- core/js/share.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/js/share.js b/core/js/share.js index 0b65e15309..02d16cbd89 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -718,13 +718,21 @@ $(document).ready(function() { $(document).on('change', '#dropdown #expirationDate', function() { var itemType = $('#dropdown').data('item-type'); var itemSource = $('#dropdown').data('item-source'); + + $(this).tipsy('hide'); + $(this).removeClass('error'); + $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: $(this).val() }, function(result) { if (!result || result.status !== 'success') { + var expirationDateField = $('#dropdown #expirationDate'); if (!result.data.message) { - OC.dialogs.alert(t('core', 'Error setting expiration date'), t('core', 'Error')); + expirationDateField.attr('original-title', t('core', 'Error setting expiration date')); } else { - OC.dialogs.alert(result.data.message, t('core', 'Error')); + expirationDateField.attr('original-title', result.data.message); } + expirationDateField.tipsy({gravity: 'n', fade: true}); + expirationDateField.tipsy('show'); + expirationDateField.addClass('error'); } }); });