]> source.dussan.org Git - nextcloud-server.git/commitdiff
set expire date for all share types
authorBjoern Schiessle <bjoern@schiessle.org>
Wed, 29 Mar 2017 14:50:23 +0000 (16:50 +0200)
committerBjoern Schiessle <bjoern@schiessle.org>
Mon, 3 Apr 2017 08:29:32 +0000 (10:29 +0200)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
apps/files_sharing/lib/Controller/ShareAPIController.php
apps/sharebymail/lib/ShareByMailProvider.php
core/css/share.scss
core/js/sharedialogshareelistview.js
core/js/shareitemmodel.js
lib/private/Share20/DefaultShareProvider.php
lib/private/Share20/Manager.php

index bd3535536e420e92812946a48cfd3d530c60ed90..b810a5150822afc5deb17bb446fef0af81ee4ec6 100644 (file)
@@ -163,6 +163,11 @@ class ShareAPIController extends OCSController {
                $result['file_parent'] = $node->getParent()->getId();
                $result['file_target'] = $share->getTarget();
 
+               $expiration = $share->getExpirationDate();
+               if ($expiration !== null) {
+                       $result['expiration'] = $expiration->format('Y-m-d 00:00:00');
+               }
+
                if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
                        $sharedWith = $this->userManager->get($share->getSharedWith());
                        $result['share_with'] = $share->getSharedWith();
@@ -179,11 +184,6 @@ class ShareAPIController extends OCSController {
                        $result['token'] = $share->getToken();
                        $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
 
-                       $expiration = $share->getExpirationDate();
-                       if ($expiration !== null) {
-                               $result['expiration'] = $expiration->format('Y-m-d 00:00:00');
-                       }
-
                } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
                        $result['share_with'] = $share->getSharedWith();
                        $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
@@ -741,32 +741,30 @@ class ShareAPIController extends OCSController {
                        }
 
                } else {
-                       // For other shares only permissions is valid.
-                       if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_EMAIL && $permissions === null) {
-                               throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
-                       } elseif ($permissions !== null) {
+                       if ($permissions !== null) {
                                $permissions = (int)$permissions;
                                $share->setPermissions($permissions);
                        }
 
                        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
-                               if ($expireDate === '') {
-                                       $share->setExpirationDate(null);
-                               } else if ($expireDate !== null) {
-                                       try {
-                                               $expireDate = $this->parseDate($expireDate);
-                                       } catch (\Exception $e) {
-                                               throw new OCSBadRequestException($e->getMessage());
-                                       }
-                                       $share->setExpirationDate($expireDate);
-                               }
-
                                if ($password === '') {
                                        $share->setPassword(null);
                                } else if ($password !== null) {
                                        $share->setPassword($password);
                                }
                        }
+
+                       if ($expireDate === '') {
+                               $share->setExpirationDate(null);
+                       } else if ($expireDate !== null) {
+                               try {
+                                       $expireDate = $this->parseDate($expireDate);
+                               } catch (\Exception $e) {
+                                       throw new OCSBadRequestException($e->getMessage());
+                               }
+                               $share->setExpirationDate($expireDate);
+                       }
+
                }
 
                if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) {
index f49a4d07eb9427eda6f18379cc51c5a70361b9d4..415011d2d6d798d686fef9232373690a5e383b95 100644 (file)
@@ -24,6 +24,7 @@ namespace OCA\ShareByMail;
 use OC\HintException;
 use OC\Share20\Exception\InvalidShare;
 use OCP\Activity\IManager;
+use OCP\DB\QueryBuilder\IQueryBuilder;
 use OCP\Files\Folder;
 use OCP\Files\IRootFolder;
 use OCP\Files\Node;
@@ -440,6 +441,7 @@ class ShareByMailProvider implements IShareProvider {
                        ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
                        ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
                        ->set('password', $qb->createNamedParameter($share->getPassword()))
+                       ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
                        ->execute();
 
                return $share;
@@ -699,6 +701,13 @@ class ShareByMailProvider implements IShareProvider {
                        $share->setShareOwner($owner->getUID());
                }
 
+               if ($data['expiration'] !== null) {
+                       $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
+                       if ($expiration !== false) {
+                               $share->setExpirationDate($expiration);
+                       }
+               }
+
                $share->setNodeId((int)$data['file_source']);
                $share->setNodeType($data['item_type']);
 
index 2c97af4aa0d836527744de4b08e06f22e586df17..552e20c80cccf62a7e86ad8fc9bf741cfcfac15e 100644 (file)
@@ -194,3 +194,6 @@ a {
        width: inherit !important;
 }
 
+.ui-datepicker {
+       z-index: 1111 !important;
+}
index 2f701ace759c017779e19692536adacb6c3871b5..b58c646be27404dff9042ddcba70983b06bbe7da 100644 (file)
                                        '<span class="shareOption menuitem">' +
                                                '<input id="expireDate-{{cid}}-{{shareId}}" type="checkbox" name="expirationDate" class="expireDate checkbox" {{#if hasExpireDate}}checked="checked"{{/if}}" />' +
                                                '<label for="expireDate-{{cid}}-{{shareId}}">{{expireDateLabel}}</label>' +
-                                               '<div class="expirationDateContainer-{{cid}}-{{shareId}} {{#unless isExpirationSet}}hidden{{/unless}}">' +
+                                               '<div class="expirationDateContainer-{{cid}}-{{shareId}} {{#unless hasExpireDate}}hidden{{/unless}}">' +
                                                '    <label for="expirationDatePicker-{{cid}}-{{shareId}}" class="hidden-visually" value="{{expirationDate}}">{{expirationLabel}}</label>' +
-                                               '    <input id="expirationDatePicker-{{cid}}-{{shareId}}" class="datepicker" type="text" placeholder="{{expirationDatePlaceholder}}" value="{{expirationValue}}" />' +
+                                               '    <input id="expirationDatePicker-{{cid}}-{{shareId}}" class="datepicker" type="text" placeholder="{{expirationDatePlaceholder}}" value="{{expireDate}}" />' +
                                                '</div>' +
                                        '</span>' +
                                '</li>' +
                        'click .password' : 'onMailSharePasswordProtectChange',
                        'click .secureDrop' : 'onSecureDropChange',
                        'keyup input.passwordField': 'onMailSharePasswordKeyUp',
-                       'focusout input.passwordField': 'onMailSharePasswordEntered'
+                       'focusout input.passwordField': 'onMailSharePasswordEntered',
+                       'change .datepicker': 'onChangeExpirationDate',
+                       'click .datepicker' : 'showDatePicker'
                },
 
                initialize: function(options) {
                                isFileSharedByMail: shareType === OC.Share.SHARE_TYPE_EMAIL && !this.model.isFolder(),
                                isPasswordSet: hasPassword,
                                secureDropMode: !this.model.hasReadPermission(shareIndex),
+                               hasExpireDate: this.model.getExpireDate(shareIndex) !== null,
+                               expireDate: this.model.getExpireDate(shareIndex),
                                passwordPlaceholder: hasPassword ? PASSWORD_PLACEHOLDER : PASSWORD_PLACEHOLDER_MESSAGE,
                        });
                },
                        var state = element.prop('checked');
                        datePicker.toggleClass('hidden', !state);
                        if (!state) {
-                               // discard expiration date
-                               this.model.get('linkShare').expiration = '';
-                               /*
-                               this.model.saveLinkShare({
-                                       expireDate: ''
-                               });
-                               */
+                               this.setExpirationDate(shareId, '');
                        } else {
-                               var expirationDatePicker = '#expirationDatePicker-' + this.cid + '-' + shareId;
-                               this.$(expirationDatePicker).focus();
+                               this.showDatePicker(event);
+
                        }
                },
 
+               showDatePicker: function(event) {
+                       var element = $(event.target);
+                       var li = element.closest('li[data-share-id]');
+                       var shareId = li.data('share-id');
+                       var expirationDatePicker = '#expirationDatePicker-' + this.cid + '-' + shareId;
+                       $(expirationDatePicker).datepicker({dateFormat : 'dd-mm-yy'});
+                       $(expirationDatePicker).focus();
+               },
+
+               onChangeExpirationDate: function(event) {
+                       datePicker = $(event.target);
+                       expireDate = datePicker.val();
+                       var element = $(event.target);
+                       var li = element.closest('li[data-share-id]');
+                       var shareId = li.data('share-id');
+                       this.setExpirationDate(shareId, expireDate);
+               },
+
+               setExpirationDate: function(shareId, expireDate) {
+                       this.model.updateShare(shareId, {expireDate: expireDate}, {});
+               },
+
                onMailSharePasswordProtectChange: function(event) {
                        var element = $(event.target);
                        var li = element.closest('li[data-share-id]');
index 8b0f71568c9e6d881637a5475946f6226ed7046e..6bb8d75b91f16c2eb4ee531de24fd0e522711d7e 100644 (file)
                        return this.get('reshare').share_type;
                },
 
+               getExpireDate: function(shareIndex) {
+                       return this._shareExpireDate(shareIndex);
+               },
+
                /**
                 * Returns all share entries that only apply to the current item
                 * (file/folder)
                        return (share.permissions & permission) === permission;
                },
 
+
+               _shareExpireDate: function(shareIndex) {
+                       var share = this.get('shares')[shareIndex];
+                       if(!_.isObject(share)) {
+                               throw "Unknown Share";
+                       }
+                       var date2 = share.expiration;
+                       return date2;
+               },
+
                /**
                 * @returns {boolean}
                 */
index cf7666f99e7c5a61a0f66f65527b8d5264420d08..0d02123e00135bc8990ef7161658fa5d2f1cbe23 100644 (file)
@@ -202,6 +202,7 @@ class DefaultShareProvider implements IShareProvider {
                                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
                                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
                                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
+                               ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
                                ->execute();
                } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
                        $qb = $this->dbConn->getQueryBuilder();
@@ -212,6 +213,7 @@ class DefaultShareProvider implements IShareProvider {
                                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
                                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
                                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
+                               ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
                                ->execute();
 
                        /*
@@ -224,6 +226,7 @@ class DefaultShareProvider implements IShareProvider {
                                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
                                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
                                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
+                               ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
                                ->execute();
 
                        /*
index 79429c44ffa8934347f7681a7f0ce661202f2a3e..0dade2f7126c6f08a25f8ec0f2922294936f5df0 100644 (file)
@@ -938,22 +938,11 @@ class Manager implements IManager {
                 */
                if ($shareType === \OCP\Share::SHARE_TYPE_LINK) {
                        $shares2 = [];
-                       $today = new \DateTime();
 
                        while(true) {
                                $added = 0;
                                foreach ($shares as $share) {
-                                       // Check if the share is expired and if so delete it
-                                       if ($share->getExpirationDate() !== null &&
-                                               $share->getExpirationDate() <= $today
-                                       ) {
-                                               try {
-                                                       $this->deleteShare($share);
-                                               } catch (NotFoundException $e) {
-                                                       //Ignore since this basically means the share is deleted
-                                               }
-                                               continue;
-                                       }
+
                                        $added++;
                                        $shares2[] = $share;
 
@@ -985,6 +974,22 @@ class Manager implements IManager {
                        $shares = $shares2;
                }
 
+
+               // remove all shares which are already expired
+               foreach ($shares as $key => $share) {
+                       try {
+                               $this->checkExpireDate($share);
+                       } catch (ShareNotFound $e) {
+                               unset($shares[$key]);
+                               try {
+                                       $this->deleteShare($share);
+                               } catch (NotFoundException $e) {
+                                       //Ignore since this basically means the share is deleted
+                               }
+                       }
+               }
+
+
                return $shares;
        }
 
@@ -998,7 +1003,23 @@ class Manager implements IManager {
                        return [];
                }
 
-               return $provider->getSharedWith($userId, $shareType, $node, $limit, $offset);
+               $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset);
+
+               // remove all shares which are already expired
+               foreach ($shares as $key => $share) {
+                       try {
+                               $this->checkExpireDate($share);
+                       } catch (ShareNotFound $e) {
+                               unset($shares[$key]);
+                               try {
+                                       $this->deleteShare($share);
+                               } catch (NotFoundException $e) {
+                                       //Ignore since this basically means the share is deleted
+                               }
+                       }
+               }
+
+               return $shares;
        }
 
        /**
@@ -1019,13 +1040,7 @@ class Manager implements IManager {
 
                $share = $provider->getShareById($id, $recipient);
 
-               // Validate link shares expiration date
-               if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK &&
-                       $share->getExpirationDate() !== null &&
-                       $share->getExpirationDate() <= new \DateTime()) {
-                       $this->deleteShare($share);
-                       throw new ShareNotFound();
-               }
+               $this->checkExpireDate($share);
 
                return $share;
        }
@@ -1087,11 +1102,7 @@ class Manager implements IManager {
                        throw new ShareNotFound();
                }
 
-               if ($share->getExpirationDate() !== null &&
-                       $share->getExpirationDate() <= new \DateTime()) {
-                       $this->deleteShare($share);
-                       throw new ShareNotFound();
-               }
+               $this->checkExpireDate($share);
 
                /*
                 * Reduce the permissions for link shares if public upload is not enabled
@@ -1104,6 +1115,15 @@ class Manager implements IManager {
                return $share;
        }
 
+       protected function checkExpireDate($share) {
+               if ($share->getExpirationDate() !== null &&
+                       $share->getExpirationDate() <= new \DateTime()) {
+                       $this->deleteShare($share);
+                       throw new ShareNotFound();
+               }
+
+       }
+
        /**
         * Verify the password of a public share
         *