]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add support for share expiration
authorMichael Gapczynski <mtgap@owncloud.com>
Sat, 1 Sep 2012 22:53:48 +0000 (18:53 -0400)
committerMichael Gapczynski <mtgap@owncloud.com>
Sat, 1 Sep 2012 22:53:48 +0000 (18:53 -0400)
core/ajax/share.php
core/js/share.js
lib/public/share.php

index debdf612c0e54d0affdd34f9881c3245787a7566..8c2e85523e3e97582371c0057ffcc29705f57578 100644 (file)
@@ -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']) {
index 4c164f65b24d6891ad1d020f73552d256385082a..2f3b5c2fa505027125db0a3f4cb15b632daa2f4d 100644 (file)
@@ -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();
        });
index 165e3df452f763414f9f4bee9adee8ac15c192ec..a9fd23bfac8540c6205feab78a002a38f7dd92c6 100644 (file)
@@ -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)) {