summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php38
-rw-r--r--apps/sharebymail/lib/ShareByMailProvider.php9
-rw-r--r--core/css/share.scss3
-rw-r--r--core/js/sharedialogshareelistview.js44
-rw-r--r--core/js/shareitemmodel.js14
-rw-r--r--lib/private/Share20/DefaultShareProvider.php3
-rw-r--r--lib/private/Share20/Manager.php70
7 files changed, 124 insertions, 57 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index bd3535536e4..b810a515082 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -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) {
diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php
index f49a4d07eb9..415011d2d6d 100644
--- a/apps/sharebymail/lib/ShareByMailProvider.php
+++ b/apps/sharebymail/lib/ShareByMailProvider.php
@@ -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']);
diff --git a/core/css/share.scss b/core/css/share.scss
index 2c97af4aa0d..552e20c80cc 100644
--- a/core/css/share.scss
+++ b/core/css/share.scss
@@ -194,3 +194,6 @@ a {
width: inherit !important;
}
+.ui-datepicker {
+ z-index: 1111 !important;
+}
diff --git a/core/js/sharedialogshareelistview.js b/core/js/sharedialogshareelistview.js
index 2f701ace759..b58c646be27 100644
--- a/core/js/sharedialogshareelistview.js
+++ b/core/js/sharedialogshareelistview.js
@@ -105,9 +105,9 @@
'<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>' +
@@ -166,7 +166,9 @@
'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) {
@@ -237,6 +239,8 @@
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,
});
},
@@ -464,19 +468,35 @@
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]');
diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js
index 8b0f71568c9..6bb8d75b91f 100644
--- a/core/js/shareitemmodel.js
+++ b/core/js/shareitemmodel.js
@@ -363,6 +363,10 @@
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)
@@ -449,6 +453,16 @@
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}
*/
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php
index cf7666f99e7..0d02123e001 100644
--- a/lib/private/Share20/DefaultShareProvider.php
+++ b/lib/private/Share20/DefaultShareProvider.php
@@ -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();
/*
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 79429c44ffa..0dade2f7126 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -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
*