From 56a25125817f4f0172c2310dca719bdcb5cbef8e Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 11 Sep 2017 00:28:24 +0200 Subject: [PATCH 1/3] Add support for `\OCP\Share\IShare::getMailSend` back This adds back the support for `\OCP\Share\IShare::getMailSend`, one example is creating bulk shares via API which where previously blocking due to the share notification emails. Signed-off-by: Lukas Reschke --- lib/private/Share20/DefaultShareProvider.php | 2 +- lib/private/Share20/Manager.php | 39 +++++++++++--------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index a440c36406..ca0a6349db 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -837,7 +837,7 @@ class DefaultShareProvider implements IShareProvider { ->setShareType((int)$data['share_type']) ->setPermissions((int)$data['permissions']) ->setTarget($data['file_target']) - ->setMailSend((bool)$data['mail_send']); + ->setMailSend(true); $shareTime = new \DateTime(); $shareTime->setTimestamp((int)$data['stime']); diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 83fe4ec0d1..b22bfbc387 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -669,26 +669,31 @@ class Manager implements IManager { $this->eventDispatcher->dispatch('OCP\Share::postShare', $event); if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { - $user = $this->userManager->get($share->getSharedWith()); - if ($user !== null) { - $emailAddress = $user->getEMailAddress(); - if ($emailAddress !== null && $emailAddress !== '') { - $userLang = $this->config->getUserValue($share->getSharedWith(), 'core', 'lang', null); - $l = $this->l10nFactory->get('lib', $userLang); - $this->sendMailNotification( - $l, - $share->getNode()->getName(), - $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', [ 'fileid' => $share->getNode()->getId() ]), - $share->getSharedBy(), - $emailAddress, - $share->getExpirationDate() - ); - $this->logger->debug('Send share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); + $mailSend = $share->getMailSend(); + if($mailSend === true) { + $user = $this->userManager->get($share->getSharedWith()); + if ($user !== null) { + $emailAddress = $user->getEMailAddress(); + if ($emailAddress !== null && $emailAddress !== '') { + $userLang = $this->config->getUserValue($share->getSharedWith(), 'core', 'lang', null); + $l = $this->l10nFactory->get('lib', $userLang); + $this->sendMailNotification( + $l, + $share->getNode()->getName(), + $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]), + $share->getSharedBy(), + $emailAddress, + $share->getExpirationDate() + ); + $this->logger->debug('Send share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); + } else { + $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); + } } else { - $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); + $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); } } else { - $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); + $this->logger->debug('Share notification not send because mailsend is false.', ['app' => 'share']); } } From 1c25919cf18d3b4b690d22aa749735997227eca4 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 11 Sep 2017 00:56:20 +0200 Subject: [PATCH 2/3] Proper handle null cases and default to true Signed-off-by: Lukas Reschke --- lib/private/Share20/DefaultShareProvider.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index ca0a6349db..844b36b299 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -183,6 +183,9 @@ class DefaultShareProvider implements IShareProvider { throw new ShareNotFound(); } + $mailSendValue = $share->getMailSend(); + $data['mail_send'] = ($mailSendValue === null) ? true : $mailSendValue; + $share = $this->createShare($data); return $share; } @@ -837,7 +840,7 @@ class DefaultShareProvider implements IShareProvider { ->setShareType((int)$data['share_type']) ->setPermissions((int)$data['permissions']) ->setTarget($data['file_target']) - ->setMailSend(true); + ->setMailSend((bool)$data['mail_send']); $shareTime = new \DateTime(); $shareTime->setTimestamp((int)$data['stime']); From a51a8fbcafe0005f32d526df2facc01c216b79b6 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 27 Nov 2017 10:54:40 +0100 Subject: [PATCH 3/3] Federation actually sends an email via Share 2.0 Signed-off-by: Morris Jobke --- build/integration/federation_features/federated.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/integration/federation_features/federated.feature b/build/integration/federation_features/federated.feature index 8bf8e921b0..c7b20cf86a 100644 --- a/build/integration/federation_features/federated.feature +++ b/build/integration/federation_features/federated.feature @@ -113,7 +113,7 @@ Feature: federated | permissions | 19 | | stime | A_NUMBER | | storage | A_NUMBER | - | mail_send | 0 | + | mail_send | 1 | | uid_owner | user1 | | file_parent | A_NUMBER | | displayname_owner | user1 |