From d0eefd17d3c47de8d13d41e57a2a6966af94428f Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 27 Mar 2017 22:03:10 +0200 Subject: allow the user to set a expire date for all shares Signed-off-by: Bjoern Schiessle --- core/css/share.scss | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core/css/share.scss') diff --git a/core/css/share.scss b/core/css/share.scss index 0e6eb3ccf8b..3ca2e4ea643 100644 --- a/core/css/share.scss +++ b/core/css/share.scss @@ -184,3 +184,7 @@ a { padding-top: 12px; color: rgba($color-main-text, .4); } + +.popovermenu .datepicker { + margin-left: 35px; +} -- cgit v1.2.3 From c191173d5914f77ebac425e315d2b962077bd654 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 28 Mar 2017 14:39:38 +0200 Subject: allow password protected mail shares Signed-off-by: Bjoern Schiessle --- .../lib/Controller/ShareAPIController.php | 23 ++++- apps/sharebymail/lib/ShareByMailProvider.php | 83 +++++++++++++--- apps/sharebymail/templates/altmailpassword.php | 32 +++++++ apps/sharebymail/templates/mailpassword.php | 59 ++++++++++++ apps/sharebymail/tests/ShareByMailProviderTest.php | 1 + core/css/share.scss | 6 ++ core/js/sharedialogshareelistview.js | 104 ++++++++++++++++++++- lib/private/Share20/Manager.php | 25 ++++- 8 files changed, 315 insertions(+), 18 deletions(-) create mode 100644 apps/sharebymail/templates/altmailpassword.php create mode 100644 apps/sharebymail/templates/mailpassword.php (limited to 'core/css/share.scss') diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 80ba7534da0..bd3535536e4 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -742,12 +742,31 @@ class ShareAPIController extends OCSController { } else { // For other shares only permissions is valid. - if ($permissions === null) { + if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_EMAIL && $permissions === null) { throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given')); - } else { + } elseif ($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 ($permissions !== null && $share->getShareOwner() !== $this->currentUser) { diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index 86f2a8fd49a..f49a4d07eb9 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -275,10 +275,10 @@ class ShareByMailProvider implements IShareProvider { protected function createMailBody($template, $filename, $link, $owner, $initiator) { $mailBodyTemplate = new Template('sharebymail', $template, ''); - $mailBodyTemplate->assign ('filename', $filename); + $mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename)); $mailBodyTemplate->assign ('link', $link); - $mailBodyTemplate->assign ('owner', $owner); - $mailBodyTemplate->assign ('initiator', $initiator); + $mailBodyTemplate->assign ('owner', \OCP\Util::sanitizeHTML($owner)); + $mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator)); $mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner); $mailBody = $mailBodyTemplate->fetchPage(); @@ -290,6 +290,55 @@ class ShareByMailProvider implements IShareProvider { $this->l->t('Failed to create the E-mail')); } + /** + * send password to recipient of a mail share + * + * @param string $filename + * @param string $initiator + * @param string $shareWith + */ + protected function sendPassword($filename, $initiator, $shareWith, $password) { + $initiatorUser = $this->userManager->get($initiator); + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; + $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); + + $message = $this->mailer->createMessage(); + $htmlBody = $this->createMailBodyToSendPassword('mailpassword', $filename, $initiatorDisplayName, $password); + $textBody = $this->createMailBodyToSendPassword('altmailpassword', $filename,$initiatorDisplayName, $password); + $message->setTo([$shareWith]); + $message->setSubject($subject); + $message->setBody($textBody, 'text/plain'); + $message->setHtmlBody($htmlBody); + $this->mailer->send($message); + + } + + /** + * create mail body to send password to recipient + * + * @param string $filename + * @param string $initiator + * @param string $password + * @return string plain text mail + * @throws HintException + */ + protected function createMailBodyToSendPassword($template, $filename, $initiator, $password) { + + $mailBodyTemplate = new Template('sharebymail', $template, ''); + $mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename)); + $mailBodyTemplate->assign ('password', \OCP\Util::sanitizeHTML($password)); + $mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator)); + $mailBody = $mailBodyTemplate->fetchPage(); + + if (is_string($mailBody)) { + return $mailBody; + } + + throw new HintException('Failed to create the E-mail', + $this->l->t('Failed to create the E-mail')); + } + + /** * generate share token * @@ -368,19 +417,30 @@ class ShareByMailProvider implements IShareProvider { * Update a share * * @param IShare $share + * @param string|null $plainTextPassword * @return IShare The share object */ - public function update(IShare $share) { + public function update(IShare $share, $plainTextPassword = null) { + + $originalShare = $this->getShareById($share->getId()); + + // a real password was given + $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; + + if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { + $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword); + } /* - * We allow updating the permissions of mail shares + * We allow updating the permissions and password of mail shares */ $qb = $this->dbConnection->getQueryBuilder(); - $qb->update('share') - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) - ->execute(); + $qb->update('share') + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) + ->set('password', $qb->createNamedParameter($share->getPassword())) + ->execute(); return $share; } @@ -625,6 +685,7 @@ class ShareByMailProvider implements IShareProvider { $shareTime->setTimestamp((int)$data['stime']); $share->setShareTime($shareTime); $share->setSharedWith($data['share_with']); + $share->setPassword($data['password']); if ($data['uid_initiator'] !== null) { $share->setShareOwner($data['uid_owner']); diff --git a/apps/sharebymail/templates/altmailpassword.php b/apps/sharebymail/templates/altmailpassword.php new file mode 100644 index 00000000000..f6e4c5b4158 --- /dev/null +++ b/apps/sharebymail/templates/altmailpassword.php @@ -0,0 +1,32 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +/** @var OC_Theme $theme */ +/** @var array $_ */ +print_unescaped($l->t("Hey there,\n\n%s shared »%s« with you.\nYou should have already received a separate mail with a link to access it.\n\nIt is protected with the following password: %s\n\n", [$_['initiator'], $_['filename'], $_['password']])); +// TRANSLATORS term at the end of a mail +p($l->t("Cheers!")); +print_unescaped("\n"); +?> + + -- +getName() . ' - ' . $theme->getSlogan()); ?> +getBaseUrl()); diff --git a/apps/sharebymail/templates/mailpassword.php b/apps/sharebymail/templates/mailpassword.php new file mode 100644 index 00000000000..49a4853292b --- /dev/null +++ b/apps/sharebymail/templates/mailpassword.php @@ -0,0 +1,59 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +/** @var OC_Theme $theme */ +/** @var array $_ */ +?> + + + +
+ + + + + + + + + + + + + + + + + +
+ <?php p($theme->getName()); ?> +
 
  + t('Hey there,

%s shared %s with you.
You should have already received a separate mail with a link to access it.

It is protected with the following password: %s

', [$_['initiator'], $_['filename'], $_['password']])); + // TRANSLATORS term at the end of a mail + p($l->t('Cheers!')); + ?> +
 
 --
+ getName()); ?> - + getSlogan()); ?> +
getBaseUrl());?> +
 
+
diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php index 65eded3eb7d..013507fd35f 100644 --- a/apps/sharebymail/tests/ShareByMailProviderTest.php +++ b/apps/sharebymail/tests/ShareByMailProviderTest.php @@ -32,6 +32,7 @@ use OCP\ILogger; use OCP\IURLGenerator; use OCP\IUserManager; use OCP\Mail\IMailer; +use OCP\Security\IHasher; use OCP\Security\ISecureRandom; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager; diff --git a/core/css/share.scss b/core/css/share.scss index 3ca2e4ea643..2c97af4aa0d 100644 --- a/core/css/share.scss +++ b/core/css/share.scss @@ -188,3 +188,9 @@ a { .popovermenu .datepicker { margin-left: 35px; } + +.popovermenu .passwordField { + margin-left: 35px; + width: inherit !important; +} + diff --git a/core/js/sharedialogshareelistview.js b/core/js/sharedialogshareelistview.js index 8f8f3dfe10f..6679078a495 100644 --- a/core/js/sharedialogshareelistview.js +++ b/core/js/sharedialogshareelistview.js @@ -13,6 +13,10 @@ /* globals Handlebars */ (function() { + + var PASSWORD_PLACEHOLDER = '**********'; + var PASSWORD_PLACEHOLDER_MESSAGE = t('core', 'Choose a password for the mail share'); + if (!OC.Share) { OC.Share = {}; } @@ -97,7 +101,20 @@ '' + '' + '' + - '
  • ' + + '{{#if isMailShare}}' + + '
  • ' + + '' + + '' + + '' + + '
    ' + + ' ' + + ' ' + + ' ' + + '
    ' + + '
    ' + + '
  • ' + + '{{/if}}' + + '
  • ' + '{{unshareLabel}}' + '
  • ' + '' + @@ -135,7 +152,10 @@ 'click .unshare': 'onUnshare', 'click .icon-more': 'onToggleMenu', 'click .permissions': 'onPermissionChange', - 'click .expireDate' : 'onExpireDateChange' + 'click .expireDate' : 'onExpireDateChange', + 'click .password' : 'onMailSharePasswordProtectChange', + 'keyup input.passwordField': 'onMailSharePasswordKeyUp', + 'focusout input.passwordField': 'onMailSharePasswordEntered' }, initialize: function(options) { @@ -182,6 +202,11 @@ shareWithTitle = shareWith; } + var share = this.model.get('shares')[shareIndex]; + var password = share.password; + var hasPassword = password !== null && password !== ''; + + return _.extend(hasPermissionOverride, { cid: this.cid, hasSharePermission: this.model.hasSharePermission(shareIndex), @@ -198,7 +223,9 @@ isRemoteShare: shareType === OC.Share.SHARE_TYPE_REMOTE, isMailShare: shareType === OC.Share.SHARE_TYPE_EMAIL, isCircleShare: shareType === OC.Share.SHARE_TYPE_CIRCLE, - isFileSharedByMail: shareType === OC.Share.SHARE_TYPE_EMAIL && !this.model.isFolder() + isFileSharedByMail: shareType === OC.Share.SHARE_TYPE_EMAIL && !this.model.isFolder(), + isPasswordSet: hasPassword, + passwordPlaceholder: hasPassword ? PASSWORD_PLACEHOLDER : PASSWORD_PLACEHOLDER_MESSAGE, }); }, @@ -211,6 +238,7 @@ updatePermissionLabel: t('core', 'can change'), deletePermissionLabel: t('core', 'can delete'), expireDateLabel: t('core', 'set expiration data'), + passwordLabel: t('core', 'password protect'), crudsLabel: t('core', 'access control'), triangleSImage: OC.imagePath('core', 'actions/triangle-s'), isResharingAllowed: this.configModel.get('isResharingAllowed'), @@ -435,6 +463,76 @@ } }, + onMailSharePasswordProtectChange: function(event) { + var element = $(event.target); + var li = element.closest('li[data-share-id]'); + var shareId = li.data('share-id'); + var passwordContainerClass = '.passwordContainer-' + this.cid + '-' + shareId; + var passwordContainer = $(passwordContainerClass); + var inputClass = '#passwordField-' + this.cid + '-' + shareId; + var passwordField = $(inputClass); + var state = element.prop('checked'); + passwordContainer.toggleClass('hidden', !state); + if (!state) { + this.model.updateShare(shareId, {password: ''}); + passwordField.attr('value', ''); + passwordField.attr('placeholder', PASSWORD_PLACEHOLDER_MESSAGE); + } else { + var passwordField = '#passwordField-' + this.cid + '-' + shareId; + this.$(passwordField).focus(); + } + }, + + onMailSharePasswordKeyUp: function(event) { + if(event.keyCode === 13) { + this.onMailSharePasswordEntered(event); + } + }, + + onMailSharePasswordEntered: function(event) { + var passwordField = $(event.target); + var li = passwordField.closest('li[data-share-id]'); + var shareId = li.data('share-id'); + var passwordContainerClass = '.passwordContainer-' + this.cid + '-' + shareId; + var loading = this.$el.find(passwordContainerClass + ' .icon-loading-small'); + if (!loading.hasClass('hidden')) { + // still in process + return; + } + + passwordField.removeClass('error'); + var password = passwordField.val(); + // in IE9 the password might be the placeholder due to bugs in the placeholders polyfill + if(password === '' || password === PASSWORD_PLACEHOLDER || password === PASSWORD_PLACEHOLDER_MESSAGE) { + return; + } + + loading + .removeClass('hidden') + .addClass('inlineblock'); + + + this.model.updateShare(shareId, { + password: password + }, { + error: function(model, msg) { + // destroy old tooltips + passwordField.tooltip('destroy'); + loading.removeClass('inlineblock').addClass('hidden'); + passwordField.addClass('error'); + passwordField.attr('title', msg); + passwordField.tooltip({placement: 'bottom', trigger: 'manual'}); + passwordField.tooltip('show'); + }, + success: function(model, msg) { + passwordField.blur(); + passwordField.attr('value', ''); + passwordField.attr('placeholder', PASSWORD_PLACEHOLDER); + loading.removeClass('inlineblock').addClass('hidden'); + } + }); + }, + onPermissionChange: function(event) { event.preventDefault(); event.stopPropagation(); diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index a02eb9205d0..5eea40d3773 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -730,11 +730,30 @@ class Manager implements IManager { } } + $plainTextPassword = null; + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { + // Password updated. + if ($share->getPassword() !== $originalShare->getPassword()) { + //Verify the password + $this->verifyPassword($share->getPassword()); + + // If a password is set. Hash it! + if ($share->getPassword() !== null) { + $plainTextPassword = $share->getPassword(); + $share->setPassword($this->hasher->hash($plainTextPassword)); + } + } + } + $this->pathCreateChecks($share->getNode()); // Now update the share! $provider = $this->factory->getProviderForType($share->getShareType()); - $share = $provider->update($share); + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { + $share = $provider->update($share, $plainTextPassword); + } else { + $share = $provider->update($share); + } if ($expirationDateUpdated === true) { \OC_Hook::emit('OCP\Share', 'post_set_expiration_date', [ @@ -1091,7 +1110,9 @@ class Manager implements IManager { * @return bool */ public function checkPassword(\OCP\Share\IShare $share, $password) { - if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK) { + $passwordProtected = $share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK + || $share->getShareType() !== \OCP\Share::SHARE_TYPE_EMAIL; + if (!$passwordProtected) { //TODO maybe exception? return false; } -- cgit v1.2.3 From b84fd7c3615c9d7b1830b6d51f6ad5b943d06b9f Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 29 Mar 2017 16:50:23 +0200 Subject: set expire date for all share types Signed-off-by: Bjoern Schiessle --- .../lib/Controller/ShareAPIController.php | 38 ++++++------ apps/sharebymail/lib/ShareByMailProvider.php | 9 +++ core/css/share.scss | 3 + core/js/sharedialogshareelistview.js | 44 ++++++++++---- core/js/shareitemmodel.js | 14 +++++ lib/private/Share20/DefaultShareProvider.php | 3 + lib/private/Share20/Manager.php | 70 ++++++++++++++-------- 7 files changed, 124 insertions(+), 57 deletions(-) (limited to 'core/css/share.scss') 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 @@ '' + '' + '' + - '
    ' + + '
    ' + ' ' + - ' ' + + ' ' + '
    ' + '' + '' + @@ -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 * -- cgit v1.2.3 From 637920f669b2f42e7ba6cf672c2271bee42d07e3 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Fri, 7 Apr 2017 20:44:54 +0200 Subject: Fix share dropdown opacity issue Signed-off-by: Jan-Christoph Borchardt --- core/css/share.scss | 1 + 1 file changed, 1 insertion(+) (limited to 'core/css/share.scss') diff --git a/core/css/share.scss b/core/css/share.scss index 552e20c80cc..de545955aa9 100644 --- a/core/css/share.scss +++ b/core/css/share.scss @@ -106,6 +106,7 @@ .shareOption { white-space: nowrap; display: inline-block; + opacity: 1 !important; } .unshare img, .showCruds img { -- cgit v1.2.3