$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();
$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');
}
} 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) {
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;
->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;
$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']);
width: inherit !important;
}
+.ui-datepicker {
+ z-index: 1111 !important;
+}
'<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]');
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}
*/
->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();
->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();
/*
->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();
/*
*/
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;
$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;
}
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;
}
/**
$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;
}
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
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
*