Add support for share expiration
This commit is contained in:
parent
aad7dc8390
commit
6c29334b48
|
@ -55,6 +55,12 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
|
|||
($return) ? OC_JSON::success() : OC_JSON::error();
|
||||
}
|
||||
break;
|
||||
case 'setExpirationDate':
|
||||
if (isset($_POST['date'])) {
|
||||
$return = OCP\Share::setExpirationDate($_POST['itemType'], $_POST['itemSource'], $_POST['date']);
|
||||
($return) ? OC_JSON::success() : OC_JSON::error();
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (isset($_GET['fetch'])) {
|
||||
switch ($_GET['fetch']) {
|
||||
|
|
|
@ -143,6 +143,9 @@ OC.Share={
|
|||
html += '<input id="linkPassText" type="password" placeholder="Password" style="display:none; width:90%;" />';
|
||||
html += '</div>';
|
||||
}
|
||||
html += '<div id="expiration">';
|
||||
html += '<input type="checkbox" name="expirationCheckbox" id="expirationCheckbox" value="1" /><label for="expirationCheckbox">Set expiration date</label>';
|
||||
html += '<input id="expirationDate" type="text" placeholder="Expiration date" style="display:none; width:90%;" />';
|
||||
html += '</div>';
|
||||
$(html).appendTo(appendTo);
|
||||
// Reset item shares
|
||||
|
@ -422,6 +425,30 @@ $(document).ready(function() {
|
|||
}
|
||||
});
|
||||
|
||||
$('#expirationCheckbox').live('change', function() {
|
||||
if (this.checked) {
|
||||
console.log('checked');
|
||||
$('#expirationDate').before('<br />');
|
||||
$('#expirationDate').show();
|
||||
$('#expirationDate').datepicker({
|
||||
dateFormat : 'dd-mm-yy'
|
||||
});
|
||||
} else {
|
||||
console.log('unchecled');
|
||||
$('#expirationDate').hide();
|
||||
}
|
||||
});
|
||||
|
||||
$('#expirationDate').live('change', function() {
|
||||
var itemType = $('#dropdown').data('item-type');
|
||||
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('Error', 'Error setting expiration date');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#emailPrivateLink').live('submit', function() {
|
||||
OC.Share.emailPrivateLink();
|
||||
});
|
||||
|
|
|
@ -395,6 +395,16 @@ class Share {
|
|||
throw new \Exception($message);
|
||||
}
|
||||
|
||||
public static function setExpirationDate($itemType, $itemSource, $date) {
|
||||
if ($item = self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), self::FORMAT_NONE, null, 1, false)) {
|
||||
error_log('setting');
|
||||
$query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `id` = ?');
|
||||
$query->execute(array($date, $item['id']));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the backend class for the specified item type
|
||||
* @param string Item type
|
||||
|
@ -582,23 +592,23 @@ class Share {
|
|||
// TODO Optimize selects
|
||||
if ($format == self::FORMAT_STATUSES) {
|
||||
if ($itemType == 'file' || $itemType == 'folder') {
|
||||
$select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `file_source`, `path`';
|
||||
$select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `file_source`, `path`, `expiration`';
|
||||
} else {
|
||||
$select = '`id`, `item_type`, `item_source`, `parent`, `share_type`';
|
||||
$select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`';
|
||||
}
|
||||
} else {
|
||||
if (isset($uidOwner)) {
|
||||
if ($itemType == 'file' || $itemType == 'folder') {
|
||||
$select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`';
|
||||
$select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`, `expiration`';
|
||||
} else {
|
||||
$select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`, `stime`, `file_source`';
|
||||
$select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`, `stime`, `file_source`, `expiration`';
|
||||
}
|
||||
} else {
|
||||
if ($fileDependent) {
|
||||
if (($itemType == 'file' || $itemType == 'folder') && $format == \OC_Share_Backend_File::FORMAT_FILE_APP || $format == \OC_Share_Backend_File::FORMAT_FILE_APP_ROOT) {
|
||||
$select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `file_source`, `path`, `file_target`, `permissions`, `name`, `ctime`, `mtime`, `mimetype`, `size`, `encrypted`, `versioned`, `writable`';
|
||||
$select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `file_source`, `path`, `file_target`, `permissions`, `expiration`, `name`, `ctime`, `mtime`, `mimetype`, `size`, `encrypted`, `versioned`, `writable`';
|
||||
} else {
|
||||
$select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, `file_source`, `path`, `file_target`, `permissions`, `stime`';
|
||||
$select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`';
|
||||
}
|
||||
} else {
|
||||
$select = '*';
|
||||
|
@ -650,6 +660,13 @@ class Share {
|
|||
$row['path'] = substr($row['path'], $root);
|
||||
}
|
||||
}
|
||||
if (isset($row['expiration'])) {
|
||||
$time = new \DateTime();
|
||||
if ($row['expiration'] < date('Y-m-d H:i', $time->format('U') - $time->getOffset())) {
|
||||
self::delete($row['id']);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$items[$row['id']] = $row;
|
||||
}
|
||||
if (!empty($items)) {
|
||||
|
|
Loading…
Reference in New Issue