summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-03-14 15:19:55 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-03-15 11:10:24 +0100
commit1db82073a4a36e5fb324630ef5529405ad69713b (patch)
tree2a22694b1789dc50118158cc1ea05d92eda8f2c0
parentf8180579d03fcd10ab8f92f1ecb27899436c7653 (diff)
downloadnextcloud-server-1db82073a4a36e5fb324630ef5529405ad69713b.tar.gz
nextcloud-server-1db82073a4a36e5fb324630ef5529405ad69713b.zip
Generate a valid URL for link notification
fixes #23197 * Updated unit test
-rw-r--r--core/ajax/share.php6
-rw-r--r--lib/private/share/mailnotifications.php13
-rw-r--r--tests/lib/share/MailNotificationsTest.php27
3 files changed, 38 insertions, 8 deletions
diff --git a/core/ajax/share.php b/core/ajax/share.php
index 8ece9945c23..44144b791e2 100644
--- a/core/ajax/share.php
+++ b/core/ajax/share.php
@@ -70,7 +70,8 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
\OC::$server->getL10N('lib'),
\OC::$server->getMailer(),
\OC::$server->getLogger(),
- $defaults
+ $defaults,
+ \OC::$server->getURLGenerator()
);
$result = $mailNotification->sendInternalShareMail($recipientList, $itemSource, $itemType);
@@ -108,7 +109,8 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
\OC::$server->getL10N('lib'),
\OC::$server->getMailer(),
\OC::$server->getLogger(),
- $defaults
+ $defaults,
+ \OC::$server->getURLGenerator()
);
$expiration = null;
diff --git a/lib/private/share/mailnotifications.php b/lib/private/share/mailnotifications.php
index a664d4ebf47..f71651e71fc 100644
--- a/lib/private/share/mailnotifications.php
+++ b/lib/private/share/mailnotifications.php
@@ -30,6 +30,7 @@ namespace OC\Share;
use DateTime;
use OCP\IL10N;
+use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Mail\IMailer;
use OCP\ILogger;
@@ -57,6 +58,8 @@ class MailNotifications {
private $defaults;
/** @var ILogger */
private $logger;
+ /** @var IURLGenerator */
+ private $urlGenerator;
/**
* @param IUser $user
@@ -64,17 +67,20 @@ class MailNotifications {
* @param IMailer $mailer
* @param ILogger $logger
* @param Defaults $defaults
+ * @param IURLGenerator $urlGenerator
*/
public function __construct(IUser $user,
IL10N $l10n,
IMailer $mailer,
ILogger $logger,
- Defaults $defaults) {
+ Defaults $defaults,
+ IURLGenerator $urlGenerator) {
$this->l = $l10n;
$this->user = $user;
$this->mailer = $mailer;
$this->logger = $logger;
$this->defaults = $defaults;
+ $this->urlGenerator = $urlGenerator;
$this->replyTo = $this->user->getEMailAddress();
$this->senderDisplayName = $this->user->getDisplayName();
@@ -131,7 +137,10 @@ class MailNotifications {
);
}
- $link = Util::linkToAbsolute('files', 'index.php', $args);
+ $link = $this->urlGenerator->linkToRouteAbsolute(
+ 'files.view.index',
+ $args
+ );
list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration, 'internal');
diff --git a/tests/lib/share/MailNotificationsTest.php b/tests/lib/share/MailNotificationsTest.php
index 66bec8653fb..8c8ca78f39a 100644
--- a/tests/lib/share/MailNotificationsTest.php
+++ b/tests/lib/share/MailNotificationsTest.php
@@ -25,6 +25,7 @@ use OCP\IUser;
use OCP\Mail\IMailer;
use OCP\ILogger;
use OCP\Defaults;
+use OCP\IURLGenerator;
/**
* Class MailNotificationsTest
@@ -40,6 +41,8 @@ class MailNotificationsTest extends \Test\TestCase {
private $defaults;
/** @var IUser | PHPUnit_Framework_MockObject_MockObject */
private $user;
+ /** @var IURLGenerator | PHPUnit_Framework_MockObject_MockObject */
+ private $urlGenerator;
public function setUp() {
@@ -55,6 +58,7 @@ class MailNotificationsTest extends \Test\TestCase {
->disableOriginalConstructor()->getMock();
$this->user = $this->getMockBuilder('\OCP\IUser')
->disableOriginalConstructor()->getMock();
+ $this->urlGenerator = $this->getMock('\OCP\IURLGenerator');
$this->l10n->expects($this->any())
->method('t')
@@ -116,7 +120,8 @@ class MailNotificationsTest extends \Test\TestCase {
$this->l10n,
$this->mailer,
$this->logger,
- $this->defaults
+ $this->defaults,
+ $this->urlGenerator
);
$this->assertSame([], $mailNotifications->sendLinkShareMail('lukas@owncloud.com', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
@@ -180,7 +185,8 @@ class MailNotificationsTest extends \Test\TestCase {
$this->l10n,
$this->mailer,
$this->logger,
- $this->defaults
+ $this->defaults,
+ $this->urlGenerator
);
$this->assertSame([], $mailNotifications->sendLinkShareMail($to, 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
}
@@ -193,7 +199,8 @@ class MailNotificationsTest extends \Test\TestCase {
$this->l10n,
$this->mailer,
$this->logger,
- $this->defaults
+ $this->defaults,
+ $this->urlGenerator
);
$this->assertSame(['lukas@owncloud.com'], $mailNotifications->sendLinkShareMail('lukas@owncloud.com', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
@@ -208,7 +215,9 @@ class MailNotificationsTest extends \Test\TestCase {
$this->l10n,
$this->mailer,
$this->logger,
- $this->defaults]);
+ $this->defaults,
+ $this->urlGenerator
+ ]);
$mailNotifications->method('getItemSharedWithUser')
->withAnyParameters()
@@ -227,6 +236,16 @@ class MailNotificationsTest extends \Test\TestCase {
->method('getDisplayName')
->willReturn('Recipient');
+ $this->urlGenerator->expects($this->once())
+ ->method('linkToRouteAbsolute')
+ ->with(
+ $this->equalTo('files.view.index'),
+ $this->equalTo([
+ 'dir' => '/',
+ 'scrollto' => 'welcome.txt'
+ ])
+ );
+
$recipientList = [$recipient];
$result = $mailNotifications->sendInternalShareMail($recipientList, '3', 'file');
$this->assertSame([], $result);