summaryrefslogtreecommitdiffstats
path: root/apps/sharebymail
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2018-07-24 09:12:03 +0200
committerGitHub <noreply@github.com>2018-07-24 09:12:03 +0200
commitb41d0d32e2183b8b241d3764f06a3b0f7d6b86c1 (patch)
tree915e14ceafed060f95255e8d2d7d4ad3ab3df7b5 /apps/sharebymail
parent241e5705cb85d24a9c3479c133fcc4d9c069d8c7 (diff)
parentfee62fd20b01b08ffbc7120720ba3bad0a89be73 (diff)
downloadnextcloud-server-b41d0d32e2183b8b241d3764f06a3b0f7d6b86c1.tar.gz
nextcloud-server-b41d0d32e2183b8b241d3764f06a3b0f7d6b86c1.zip
Merge pull request #10218 from nextcloud/share-comments
allow to add a personal note to a share
Diffstat (limited to 'apps/sharebymail')
-rw-r--r--apps/sharebymail/lib/ShareByMailProvider.php61
-rw-r--r--apps/sharebymail/tests/ShareByMailProviderTest.php18
2 files changed, 72 insertions, 7 deletions
diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php
index 1a1855b9c44..73e962e3292 100644
--- a/apps/sharebymail/lib/ShareByMailProvider.php
+++ b/apps/sharebymail/lib/ShareByMailProvider.php
@@ -506,6 +506,61 @@ class ShareByMailProvider implements IShareProvider {
return true;
}
+ protected function sendNote(IShare $share) {
+
+ $recipient = $share->getSharedWith();
+
+
+ $filename = $share->getNode()->getName();
+ $initiator = $share->getSharedBy();
+ $note = $share->getNote();
+
+ $initiatorUser = $this->userManager->get($initiator);
+ $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
+ $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
+
+ $plainHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add:', [$initiatorDisplayName, $filename]);
+ $htmlHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add', [$initiatorDisplayName, $filename]);
+
+ $message = $this->mailer->createMessage();
+
+ $emailTemplate = $this->mailer->createEMailTemplate('shareByMail.sendNote');
+
+ $emailTemplate->setSubject($this->l->t('»%s« added a note to a file shared with you', [$initiatorDisplayName]));
+ $emailTemplate->addHeader();
+ $emailTemplate->addHeading(htmlspecialchars($htmlHeading), $plainHeading);
+ $emailTemplate->addBodyText(htmlspecialchars($note), $note);
+
+ $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare',
+ ['token' => $share->getToken()]);
+ $emailTemplate->addBodyButton(
+ $this->l->t('Open »%s«', [$filename]),
+ $link
+ );
+
+ // The "From" contains the sharers name
+ $instanceName = $this->defaults->getName();
+ $senderName = $this->l->t(
+ '%1$s via %2$s',
+ [
+ $initiatorDisplayName,
+ $instanceName
+ ]
+ );
+ $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
+ if ($initiatorEmailAddress !== null) {
+ $message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]);
+ $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
+ } else {
+ $emailTemplate->addFooter();
+ }
+
+ $message->setTo([$recipient]);
+ $message->useTemplate($emailTemplate);
+ $this->mailer->send($message);
+
+ }
+
/**
* send auto generated password to the owner. This happens if the admin enforces
* a password for mail shares and forbid to send the password by mail to the recipient
@@ -662,8 +717,13 @@ class ShareByMailProvider implements IShareProvider {
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
->set('password', $qb->createNamedParameter($share->getPassword()))
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
+ ->set('note', $qb->createNamedParameter($share->getNote()))
->execute();
+ if ($originalShare->getNote() !== $share->getNote() && $share->getNote() !== '') {
+ $this->sendNote($share);
+ }
+
return $share;
}
@@ -904,6 +964,7 @@ class ShareByMailProvider implements IShareProvider {
->setPermissions((int)$data['permissions'])
->setTarget($data['file_target'])
->setMailSend((bool)$data['mail_send'])
+ ->setNote($data['note'])
->setToken($data['token']);
$shareTime = new \DateTime();
diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php
index 95d746cfb46..f0d99e6026c 100644
--- a/apps/sharebymail/tests/ShareByMailProviderTest.php
+++ b/apps/sharebymail/tests/ShareByMailProviderTest.php
@@ -342,15 +342,17 @@ class ShareByMailProviderTest extends TestCase {
$uidOwner = 'user2';
$permissions = 1;
$token = 'token';
+ $note = 'personal note';
$instance = $this->getInstance();
- $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token);
+ $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $note);
$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->any())->method('getNote')->willReturn($note);
$this->share->expects($this->atLeastOnce())->method('getId')->willReturn($id);
$this->assertSame($this->share,
@@ -372,6 +374,7 @@ class ShareByMailProviderTest extends TestCase {
$this->assertSame($uidOwner, $result[0]['uid_owner']);
$this->assertSame($permissions + 1, (int)$result[0]['permissions']);
$this->assertSame($token, $result[0]['token']);
+ $this->assertSame($note, $result[0]['note']);
}
public function testDelete() {
@@ -478,7 +481,7 @@ class ShareByMailProviderTest extends TestCase {
$instance = $this->getInstance(['createShareObject']);
$idMail = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token);
- $idPublic = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token, \OCP\Share::SHARE_TYPE_LINK);
+ $idPublic = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token, '', \OCP\Share::SHARE_TYPE_LINK);
$this->assertTrue($idMail !== $idPublic);
@@ -490,9 +493,9 @@ class ShareByMailProviderTest extends TestCase {
}
);
- $this->assertInstanceOf('OCP\Share\IShare',
- $instance->getShareByToken('token')
- );
+ $result = $instance->getShareByToken('token');
+
+ $this->assertInstanceOf('OCP\Share\IShare', $result);
}
/**
@@ -511,7 +514,7 @@ class ShareByMailProviderTest extends TestCase {
$instance = $this->getInstance(['createShareObject']);
$idMail = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token);
- $idPublic = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, "token2", \OCP\Share::SHARE_TYPE_LINK);
+ $idPublic = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, "token2", '', \OCP\Share::SHARE_TYPE_LINK);
$this->assertTrue($idMail !== $idPublic);
@@ -631,7 +634,7 @@ class ShareByMailProviderTest extends TestCase {
$this->invokePrivate($instance, 'getRawShare', [$id+1]);
}
- private function createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $shareType = \OCP\Share::SHARE_TYPE_EMAIL) {
+ private function createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $note='', $shareType = \OCP\Share::SHARE_TYPE_EMAIL) {
$qb = $this->connection->getQueryBuilder();
$qb->insert('share')
->setValue('share_type', $qb->createNamedParameter($shareType))
@@ -643,6 +646,7 @@ class ShareByMailProviderTest extends TestCase {
->setValue('uid_initiator', $qb->createNamedParameter($sharedBy))
->setValue('permissions', $qb->createNamedParameter($permissions))
->setValue('token', $qb->createNamedParameter($token))
+ ->setValue('note', $qb->createNamedParameter($note))
->setValue('stime', $qb->createNamedParameter(time()));
/*