From c6613ee8fcfd19a74bcd4652187c51a642a1fc4c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 28 Mar 2017 14:39:01 +0200 Subject: fix share provider id Signed-off-by: Bjoern Schiessle --- apps/sharebymail/lib/ShareByMailProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/sharebymail') diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index e09ca308f31..86f2a8fd49a 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -81,7 +81,7 @@ class ShareByMailProvider implements IShareProvider { * @return string Containing only [a-zA-Z0-9] */ public function identifier() { - return 'ocShareByMail'; + return 'ocMailShare'; } /** -- 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 'apps/sharebymail') 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 'apps/sharebymail') 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 dac6826ad7ba54c5ed8bc81d09f2497ae2b0ec6f Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 30 Mar 2017 15:23:44 +0200 Subject: setting to disable sending password by mail Signed-off-by: Bjoern Schiessle --- apps/sharebymail/appinfo/info.xml | 6 +- apps/sharebymail/js/settings-admin.js | 30 ++++++++++ apps/sharebymail/lib/Settings/Admin.php | 67 ++++++++++++++++++++++ apps/sharebymail/lib/Settings/SettingsManager.php | 49 ++++++++++++++++ apps/sharebymail/lib/ShareByMailProvider.php | 14 ++++- apps/sharebymail/templates/settings-admin.php | 18 ++++++ apps/sharebymail/tests/ShareByMailProviderTest.php | 8 ++- lib/private/Share20/ProviderFactory.php | 8 ++- 8 files changed, 194 insertions(+), 6 deletions(-) create mode 100644 apps/sharebymail/js/settings-admin.js create mode 100644 apps/sharebymail/lib/Settings/Admin.php create mode 100644 apps/sharebymail/lib/Settings/SettingsManager.php create mode 100644 apps/sharebymail/templates/settings-admin.php (limited to 'apps/sharebymail') diff --git a/apps/sharebymail/appinfo/info.xml b/apps/sharebymail/appinfo/info.xml index 5528f6158d9..ab50ef03694 100644 --- a/apps/sharebymail/appinfo/info.xml +++ b/apps/sharebymail/appinfo/info.xml @@ -5,7 +5,7 @@ Share provider which allows you to share files by mail AGPL Bjoern Schiessle - 1.1.0 + 1.2.0 ShareByMail other @@ -17,6 +17,10 @@ + + OCA\ShareByMail\Settings\Admin + + OCA\ShareByMail\Activity diff --git a/apps/sharebymail/js/settings-admin.js b/apps/sharebymail/js/settings-admin.js new file mode 100644 index 00000000000..7b431233032 --- /dev/null +++ b/apps/sharebymail/js/settings-admin.js @@ -0,0 +1,30 @@ +/** + * @copyright Copyright (c) 2017 Bjoern Schiessle + * + * @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 . + * + */ +$(function() { + + $('#sendPasswordMail').on('change', function() { + var status = 'no'; + if ($(this).is(':checked')) { + status = 'yes'; + } + OC.AppConfig.setValue('sharebymail', 'sendpasswordmail', status); + }); + +}); diff --git a/apps/sharebymail/lib/Settings/Admin.php b/apps/sharebymail/lib/Settings/Admin.php new file mode 100644 index 00000000000..b6e7e5d3b4a --- /dev/null +++ b/apps/sharebymail/lib/Settings/Admin.php @@ -0,0 +1,67 @@ + + * + * @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 . + * + */ + + +namespace OCA\ShareByMail\Settings; + +use OCP\AppFramework\Http\TemplateResponse; +use OCP\Settings\ISettings; + +class Admin implements ISettings { + + /** @var SettingsManager */ + private $settingsManager; + + public function __construct(SettingsManager $settingsManager) { + $this->settingsManager = $settingsManager; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + + $parameters = [ + 'sendPasswordMail' => $this->settingsManager->sendPasswordByMail() + ]; + + return new TemplateResponse('sharebymail', 'settings-admin', $parameters, ''); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'sharing'; + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + * + * E.g.: 70 + */ + public function getPriority() { + return 40; + } + +} diff --git a/apps/sharebymail/lib/Settings/SettingsManager.php b/apps/sharebymail/lib/Settings/SettingsManager.php new file mode 100644 index 00000000000..205b253f337 --- /dev/null +++ b/apps/sharebymail/lib/Settings/SettingsManager.php @@ -0,0 +1,49 @@ + + * + * @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 . + * + */ + + +namespace OCA\ShareByMail\Settings; + + +use OCP\IConfig; + +class SettingsManager { + + /** @var IConfig */ + private $config; + + private $defaultSetting = 'yes'; + + public function __construct(IConfig $config) { + $this->config = $config; + } + + /** + * should the password for a mail share be send to the recipient + * + * @return bool + */ + public function sendPasswordByMail() { + $sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->defaultSetting); + return $sendPasswordByMail === 'yes'; + } + +} diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index 415011d2d6d..332f1c0cf74 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -23,6 +23,7 @@ namespace OCA\ShareByMail; use OC\HintException; use OC\Share20\Exception\InvalidShare; +use OCA\ShareByMail\Settings\SettingsManager; use OCP\Activity\IManager; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\Folder; @@ -76,6 +77,9 @@ class ShareByMailProvider implements IShareProvider { /** @var IManager */ private $activityManager; + /** @var SettingsManager */ + private $settingsManager; + /** * Return the identifier of this provider. * @@ -97,6 +101,7 @@ class ShareByMailProvider implements IShareProvider { * @param IMailer $mailer * @param IURLGenerator $urlGenerator * @param IManager $activityManager + * @param SettingsManager $settingsManager */ public function __construct( IDBConnection $connection, @@ -107,7 +112,8 @@ class ShareByMailProvider implements IShareProvider { ILogger $logger, IMailer $mailer, IURLGenerator $urlGenerator, - IManager $activityManager + IManager $activityManager, + SettingsManager $settingsManager ) { $this->dbConnection = $connection; $this->secureRandom = $secureRandom; @@ -118,6 +124,7 @@ class ShareByMailProvider implements IShareProvider { $this->mailer = $mailer; $this->urlGenerator = $urlGenerator; $this->activityManager = $activityManager; + $this->settingsManager = $settingsManager; } /** @@ -299,6 +306,11 @@ class ShareByMailProvider implements IShareProvider { * @param string $shareWith */ protected function sendPassword($filename, $initiator, $shareWith, $password) { + + if ($this->settingsManager->sendPasswordByMail() === false) { + return; + } + $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]); diff --git a/apps/sharebymail/templates/settings-admin.php b/apps/sharebymail/templates/settings-admin.php new file mode 100644 index 00000000000..c4e41086063 --- /dev/null +++ b/apps/sharebymail/templates/settings-admin.php @@ -0,0 +1,18 @@ + +
    +

    t('Share by mail')); ?>

    + t('Send a personalized link to a file or folder by mail.')); ?> + +

    + /> + +

    + +
    + diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php index 013507fd35f..4ec62dc1a03 100644 --- a/apps/sharebymail/tests/ShareByMailProviderTest.php +++ b/apps/sharebymail/tests/ShareByMailProviderTest.php @@ -24,6 +24,7 @@ namespace OCA\ShareByMail\Tests; use OC\HintException; +use OCA\ShareByMail\Settings\SettingsManager; use OCA\ShareByMail\ShareByMailProvider; use OCP\Files\IRootFolder; use OCP\IDBConnection; @@ -80,6 +81,9 @@ class ShareByMailProviderTest extends TestCase { /** @var \OCP\Activity\IManager | \PHPUnit_Framework_MockObject_MockObject */ private $activityManager; + /** @var SettingsManager | \PHPUnit_Framework_MockObject_MockObject */ + private $settingsManager; + public function setUp() { parent::setUp(); @@ -99,6 +103,7 @@ class ShareByMailProviderTest extends TestCase { $this->urlGenerator = $this->getMockBuilder('\OCP\IUrlGenerator')->getMock(); $this->share = $this->getMockBuilder('\OCP\Share\IShare')->getMock(); $this->activityManager = $this->getMockBuilder('OCP\Activity\IManager')->getMock(); + $this->settingsManager = $this->getMockBuilder(SettingsManager::class)->disableOriginalConstructor()->getMock(); $this->userManager->expects($this->any())->method('userExists')->willReturn(true); } @@ -140,7 +145,8 @@ class ShareByMailProviderTest extends TestCase { $this->logger, $this->mailer, $this->urlGenerator, - $this->activityManager + $this->activityManager, + $this->settingsManager ); } diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index 1a39cfbf337..b411f42b262 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -28,6 +28,7 @@ use OCA\FederatedFileSharing\DiscoveryManager; use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\FederatedFileSharing\Notifications; use OCA\FederatedFileSharing\TokenHandler; +use OCA\ShareByMail\Settings\SettingsManager; use OCA\ShareByMail\ShareByMailProvider; use OCP\Share\IProviderFactory; use OC\Share20\Exception\ProviderException; @@ -149,18 +150,19 @@ class ProviderFactory implements IProviderFactory { return null; } - $l = $this->serverContainer->getL10N('sharebymail'); + $settingsManager = new SettingsManager($this->serverContainer->getConfig()); $this->shareByMailProvider = new ShareByMailProvider( $this->serverContainer->getDatabaseConnection(), $this->serverContainer->getSecureRandom(), $this->serverContainer->getUserManager(), $this->serverContainer->getLazyRootFolder(), - $l, + $this->serverContainer->getL10N('sharebymail'), $this->serverContainer->getLogger(), $this->serverContainer->getMailer(), $this->serverContainer->getURLGenerator(), - $this->serverContainer->getActivityManager() + $this->serverContainer->getActivityManager(), + $settingsManager ); } -- cgit v1.2.3 From 3323d01db1eda016f6e4665ae094c85903a83856 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 30 Mar 2017 17:03:04 +0200 Subject: update unit tests Signed-off-by: Bjoern Schiessle --- .../Controller/RequestHandlerControllerTest.php | 5 +- .../lib/Controller/ShareAPIController.php | 7 ++- apps/files_sharing/tests/ApiTest.php | 30 --------- apps/files_sharing/tests/MigrationTest.php | 4 +- apps/sharebymail/tests/ShareByMailProviderTest.php | 8 +-- core/js/sharedialogshareelistview.js | 7 +-- lib/private/Share20/DefaultShareProvider.php | 2 +- lib/private/Share20/Manager.php | 71 +++++++++------------- lib/public/Share/IShare.php | 2 +- tests/lib/Share20/DefaultShareProviderTest.php | 17 +++--- 10 files changed, 55 insertions(+), 98 deletions(-) (limited to 'apps/sharebymail') diff --git a/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php b/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php index 61f87e9ec67..233395dec9f 100644 --- a/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php +++ b/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php @@ -67,7 +67,7 @@ class RequestHandlerControllerTest extends TestCase { /** @var \OCA\FederatedFileSharing\AddressHandler|\PHPUnit_Framework_MockObject_MockObject */ private $addressHandler; - + /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ private $userManager; @@ -107,7 +107,7 @@ class RequestHandlerControllerTest extends TestCase { $this->userManager = $this->getMockBuilder('OCP\IUserManager')->getMock(); $this->cloudIdManager = new CloudIdManager(); - + $this->registerHttpHelper($httpHelperMock); $this->s2s = new RequestHandlerController( @@ -384,6 +384,7 @@ class RequestHandlerControllerTest extends TestCase { 'parent' => null, 'accepted' => '0', 'expiration' => null, + 'password' => null, 'mail_send' => '0' ]; diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index b810a515082..bc525b6ef82 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -669,13 +669,14 @@ class ShareAPIController extends OCSController { throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); } + if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { + throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given')); + } + /* * expirationdate, password and publicUpload only make sense for link shares */ if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { - if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { - throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given')); - } $newPermissions = null; if ($publicUpload === 'true') { diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index 540905a7dc9..046ede1f83e 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -936,36 +936,6 @@ class ApiTest extends TestCase { $this->shareManager->deleteShare($share2); } - /** - * @medium - * @depends testCreateShareUserFile - */ - public function testUpdateShareInvalidPermissions() { - $node1 = $this->userFolder->get($this->filename); - $share1 = $this->shareManager->newShare(); - $share1->setNode($node1) - ->setSharedBy(self::TEST_FILES_SHARING_API_USER1) - ->setSharedWith(self::TEST_FILES_SHARING_API_USER2) - ->setShareType(\OCP\Share::SHARE_TYPE_USER) - ->setPermissions(19); - $share1 = $this->shareManager->createShare($share1); - - $ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1); - try { - $ocs->updateShare($share1->getId()); - $this->fail(); - } catch (OCSBadRequestException $e) { - - } - $ocs->cleanup(); - - //Permissions should not have changed! - $share1 = $this->shareManager->getShareById('ocinternal:' . $share1->getId()); - $this->assertEquals(19, $share1->getPermissions()); - - $this->shareManager->deleteShare($share1); - } - /** * @medium */ diff --git a/apps/files_sharing/tests/MigrationTest.php b/apps/files_sharing/tests/MigrationTest.php index a357e814f25..708de1c0eca 100644 --- a/apps/files_sharing/tests/MigrationTest.php +++ b/apps/files_sharing/tests/MigrationTest.php @@ -429,11 +429,11 @@ class MigrationTest extends TestCase { foreach ($allShares as $share) { if ((int)$share['share_type'] === Share::SHARE_TYPE_LINK) { - $this->assertSame(null, $share['share_with']); + $this->assertNull( $share['share_with']); $this->assertSame('shareWith', $share['password']); } else { $this->assertSame('shareWith', $share['share_with']); - $this->assertSame(null, $share['password']); + $this->assertNull($share['password']); } } } diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php index 4ec62dc1a03..288ebb4bb45 100644 --- a/apps/sharebymail/tests/ShareByMailProviderTest.php +++ b/apps/sharebymail/tests/ShareByMailProviderTest.php @@ -23,7 +23,6 @@ namespace OCA\ShareByMail\Tests; -use OC\HintException; use OCA\ShareByMail\Settings\SettingsManager; use OCA\ShareByMail\ShareByMailProvider; use OCP\Files\IRootFolder; @@ -33,9 +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; use OCP\Share\IShare; use Test\TestCase; @@ -127,7 +124,8 @@ class ShareByMailProviderTest extends TestCase { $this->logger, $this->mailer, $this->urlGenerator, - $this->activityManager + $this->activityManager, + $this->settingsManager ] ); @@ -318,7 +316,7 @@ class ShareByMailProviderTest extends TestCase { $this->share->expects($this->once())->method('getPermissions')->willReturn($permissions + 1); $this->share->expects($this->once())->method('getShareOwner')->willReturn($uidOwner); $this->share->expects($this->once())->method('getSharedBy')->willReturn($sharedBy); - $this->share->expects($this->once())->method('getId')->willReturn($id); + $this->share->expects($this->atLeastOnce())->method('getId')->willReturn($id); $this->assertSame($this->share, $instance->update($this->share) diff --git a/core/js/sharedialogshareelistview.js b/core/js/sharedialogshareelistview.js index 3c234f54665..573d5949118 100644 --- a/core/js/sharedialogshareelistview.js +++ b/core/js/sharedialogshareelistview.js @@ -510,7 +510,7 @@ passwordField.attr('value', ''); passwordField.attr('placeholder', PASSWORD_PLACEHOLDER_MESSAGE); } else { - var passwordField = '#passwordField-' + this.cid + '-' + shareId; + passwordField = '#passwordField-' + this.cid + '-' + shareId; this.$(passwordField).focus(); } }, @@ -623,10 +623,9 @@ var $li = $element.closest('li[data-share-id]'); var shareId = $li.data('share-id'); + var permissions = OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE | OC.PERMISSION_READ; if ($element.is(':checked')) { - var permissions = OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE; - } else { - var permissions = OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE | OC.PERMISSION_READ; + permissions = OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE; } /** disable checkboxes during save operation to avoid race conditions **/ diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 0d02123e001..bf8bcc9c6d9 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -116,7 +116,7 @@ class DefaultShareProvider implements IShareProvider { //If a password is set store it if ($share->getPassword() !== null) { - $qb->setValue('share_with', $qb->createNamedParameter($share->getPassword())); + $qb->setValue('password', $qb->createNamedParameter($share->getPassword())); } //If an expiration date is set store it diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 0dade2f7126..292b07d28d5 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -266,8 +266,8 @@ class Manager implements IManager { // Check that read permissions are always set // Link shares are allowed to have no read permissions to allow upload to hidden folders - $noReadPermissionRequired = $share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK - || $share->getShareType() !== \OCP\Share::SHARE_TYPE_EMAIL; + $noReadPermissionRequired = $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK + || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL; if (!$noReadPermissionRequired && ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { throw new \InvalidArgumentException('Shares need at least read permissions'); @@ -936,59 +936,49 @@ class Manager implements IManager { * Work around so we don't return expired shares but still follow * proper pagination. */ - if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { - $shares2 = []; - while(true) { - $added = 0; - foreach ($shares as $share) { + $shares2 = []; - $added++; - $shares2[] = $share; + while(true) { + $added = 0; + foreach ($shares as $share) { - if (count($shares2) === $limit) { - break; - } + try { + $this->checkExpireDate($share); + } catch (ShareNotFound $e) { + //Ignore since this basically means the share is deleted + continue; } - if (count($shares2) === $limit) { - break; - } + $added++; + $shares2[] = $share; - // If there was no limit on the select we are done - if ($limit === -1) { + if (count($shares2) === $limit) { break; } + } - $offset += $added; - - // Fetch again $limit shares - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); + if (count($shares2) === $limit) { + break; + } - // No more shares means we are done - if (empty($shares)) { - break; - } + // If there was no limit on the select we are done + if ($limit === -1) { + break; } - $shares = $shares2; - } + $offset += $added; + // Fetch again $limit shares + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $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 - } + // No more shares means we are done + if (empty($shares)) { + break; } } + $shares = $shares2; return $shares; } @@ -1011,11 +1001,6 @@ class Manager implements IManager { $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 - } } } diff --git a/lib/public/Share/IShare.php b/lib/public/Share/IShare.php index 5b552b51c3c..8deec573c1b 100644 --- a/lib/public/Share/IShare.php +++ b/lib/public/Share/IShare.php @@ -189,7 +189,7 @@ interface IShare { /** * Set the expiration date * - * @param \DateTime $expireDate + * @param null|\DateTime $expireDate * @return \OCP\Share\IShare The modified object * @since 9.0.0 */ diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index a1e78313558..fce5668440d 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -338,7 +338,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $qb->insert('share') ->values([ 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK), - 'share_with' => $qb->expr()->literal('sharedWith'), + 'password' => $qb->expr()->literal('password'), 'uid_owner' => $qb->expr()->literal('shareOwner'), 'uid_initiator' => $qb->expr()->literal('sharedBy'), 'item_type' => $qb->expr()->literal('file'), @@ -366,7 +366,8 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals($id, $share->getId()); $this->assertEquals(\OCP\Share::SHARE_TYPE_LINK, $share->getShareType()); - $this->assertEquals('sharedWith', $share->getPassword()); + $this->assertNull($share->getSharedWith()); + $this->assertEquals('password', $share->getPassword()); $this->assertEquals('sharedBy', $share->getSharedBy()); $this->assertEquals('shareOwner', $share->getShareOwner()); $this->assertEquals($ownerPath, $share->getNode()); @@ -752,7 +753,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $qb->insert('share') ->values([ 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK), - 'share_with' => $qb->expr()->literal('password'), + 'password' => $qb->expr()->literal('password'), 'uid_owner' => $qb->expr()->literal('shareOwner'), 'uid_initiator' => $qb->expr()->literal('sharedBy'), 'item_type' => $qb->expr()->literal('file'), @@ -814,7 +815,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ['home::shareOwner', 'files/test.txt', 'files/test2.txt'], // regular file on external storage ['smb::whatever', 'files/test.txt', 'files/test2.txt'], - // regular file on external storage in trashbin-like folder, + // regular file on external storage in trashbin-like folder, ['smb::whatever', 'files_trashbin/files/test.txt', 'files_trashbin/files/test2.txt'], ]; } @@ -2353,9 +2354,11 @@ class DefaultShareProviderTest extends \Test\TestCase { $rootFolder ); - $u1 = $userManager->createUser('testShare1', 'test'); - $u2 = $userManager->createUser('testShare2', 'test'); - $u3 = $userManager->createUser('testShare3', 'test'); + $password = md5(time()); + + $u1 = $userManager->createUser('testShare1', $password); + $u2 = $userManager->createUser('testShare2', $password); + $u3 = $userManager->createUser('testShare3', $password); $g1 = $groupManager->createGroup('group1'); -- cgit v1.2.3 From 11b46389af09a8ad95c38464fbafeca95d2f16fc Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 6 Apr 2017 11:33:48 +0200 Subject: adjust to changes in the theming app Signed-off-by: Bjoern Schiessle --- apps/sharebymail/templates/mailpassword.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apps/sharebymail') diff --git a/apps/sharebymail/templates/mailpassword.php b/apps/sharebymail/templates/mailpassword.php index 49a4853292b..714a61cecd9 100644 --- a/apps/sharebymail/templates/mailpassword.php +++ b/apps/sharebymail/templates/mailpassword.php @@ -19,7 +19,7 @@ * */ -/** @var OC_Theme $theme */ +/** @var OCA\Theming\ThemingDefaults $theme */ /** @var array $_ */ ?> @@ -27,7 +27,7 @@ - -- cgit v1.2.3
    + <?php p($theme->getName()); ?>