Browse Source

Generate a valid URL for link notification

fixes #23197

* Updated unit test
tags/v9.1.0beta1
Roeland Jago Douma 8 years ago
parent
commit
1db82073a4

+ 4
- 2
core/ajax/share.php View File

\OC::$server->getL10N('lib'), \OC::$server->getL10N('lib'),
\OC::$server->getMailer(), \OC::$server->getMailer(),
\OC::$server->getLogger(), \OC::$server->getLogger(),
$defaults
$defaults,
\OC::$server->getURLGenerator()
); );
$result = $mailNotification->sendInternalShareMail($recipientList, $itemSource, $itemType); $result = $mailNotification->sendInternalShareMail($recipientList, $itemSource, $itemType);


\OC::$server->getL10N('lib'), \OC::$server->getL10N('lib'),
\OC::$server->getMailer(), \OC::$server->getMailer(),
\OC::$server->getLogger(), \OC::$server->getLogger(),
$defaults
$defaults,
\OC::$server->getURLGenerator()
); );


$expiration = null; $expiration = null;

+ 11
- 2
lib/private/share/mailnotifications.php View File



use DateTime; use DateTime;
use OCP\IL10N; use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
use OCP\Mail\IMailer; use OCP\Mail\IMailer;
use OCP\ILogger; use OCP\ILogger;
private $defaults; private $defaults;
/** @var ILogger */ /** @var ILogger */
private $logger; private $logger;
/** @var IURLGenerator */
private $urlGenerator;


/** /**
* @param IUser $user * @param IUser $user
* @param IMailer $mailer * @param IMailer $mailer
* @param ILogger $logger * @param ILogger $logger
* @param Defaults $defaults * @param Defaults $defaults
* @param IURLGenerator $urlGenerator
*/ */
public function __construct(IUser $user, public function __construct(IUser $user,
IL10N $l10n, IL10N $l10n,
IMailer $mailer, IMailer $mailer,
ILogger $logger, ILogger $logger,
Defaults $defaults) {
Defaults $defaults,
IURLGenerator $urlGenerator) {
$this->l = $l10n; $this->l = $l10n;
$this->user = $user; $this->user = $user;
$this->mailer = $mailer; $this->mailer = $mailer;
$this->logger = $logger; $this->logger = $logger;
$this->defaults = $defaults; $this->defaults = $defaults;
$this->urlGenerator = $urlGenerator;


$this->replyTo = $this->user->getEMailAddress(); $this->replyTo = $this->user->getEMailAddress();
$this->senderDisplayName = $this->user->getDisplayName(); $this->senderDisplayName = $this->user->getDisplayName();
); );
} }


$link = Util::linkToAbsolute('files', 'index.php', $args);
$link = $this->urlGenerator->linkToRouteAbsolute(
'files.view.index',
$args
);


list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration, 'internal'); list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration, 'internal');



+ 23
- 4
tests/lib/share/MailNotificationsTest.php View File

use OCP\Mail\IMailer; use OCP\Mail\IMailer;
use OCP\ILogger; use OCP\ILogger;
use OCP\Defaults; use OCP\Defaults;
use OCP\IURLGenerator;


/** /**
* Class MailNotificationsTest * Class MailNotificationsTest
private $defaults; private $defaults;
/** @var IUser | PHPUnit_Framework_MockObject_MockObject */ /** @var IUser | PHPUnit_Framework_MockObject_MockObject */
private $user; private $user;
/** @var IURLGenerator | PHPUnit_Framework_MockObject_MockObject */
private $urlGenerator;




public function setUp() { public function setUp() {
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$this->user = $this->getMockBuilder('\OCP\IUser') $this->user = $this->getMockBuilder('\OCP\IUser')
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$this->urlGenerator = $this->getMock('\OCP\IURLGenerator');


$this->l10n->expects($this->any()) $this->l10n->expects($this->any())
->method('t') ->method('t')
$this->l10n, $this->l10n,
$this->mailer, $this->mailer,
$this->logger, $this->logger,
$this->defaults
$this->defaults,
$this->urlGenerator
); );


$this->assertSame([], $mailNotifications->sendLinkShareMail('lukas@owncloud.com', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600)); $this->assertSame([], $mailNotifications->sendLinkShareMail('lukas@owncloud.com', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
$this->l10n, $this->l10n,
$this->mailer, $this->mailer,
$this->logger, $this->logger,
$this->defaults
$this->defaults,
$this->urlGenerator
); );
$this->assertSame([], $mailNotifications->sendLinkShareMail($to, 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600)); $this->assertSame([], $mailNotifications->sendLinkShareMail($to, 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
} }
$this->l10n, $this->l10n,
$this->mailer, $this->mailer,
$this->logger, $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)); $this->assertSame(['lukas@owncloud.com'], $mailNotifications->sendLinkShareMail('lukas@owncloud.com', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
$this->l10n, $this->l10n,
$this->mailer, $this->mailer,
$this->logger, $this->logger,
$this->defaults]);
$this->defaults,
$this->urlGenerator
]);


$mailNotifications->method('getItemSharedWithUser') $mailNotifications->method('getItemSharedWithUser')
->withAnyParameters() ->withAnyParameters()
->method('getDisplayName') ->method('getDisplayName')
->willReturn('Recipient'); ->willReturn('Recipient');


$this->urlGenerator->expects($this->once())
->method('linkToRouteAbsolute')
->with(
$this->equalTo('files.view.index'),
$this->equalTo([
'dir' => '/',
'scrollto' => 'welcome.txt'
])
);

$recipientList = [$recipient]; $recipientList = [$recipient];
$result = $mailNotifications->sendInternalShareMail($recipientList, '3', 'file'); $result = $mailNotifications->sendInternalShareMail($recipientList, '3', 'file');
$this->assertSame([], $result); $this->assertSame([], $result);

Loading…
Cancel
Save