Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,8 @@ public function __construct($webRoot, \OC\Config $config) {
$c->getHasher(),
$c->getMountManager(),
$c->getGroupManager(),
$c->getL10N('core'),
$c->getL10N('lib'),
$c->getL10NFactory(),
$factory,
$c->getUserManager(),
$c->getLazyRootFolder(),
Expand Down
25 changes: 18 additions & 7 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Mail\IMailer;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
Expand Down Expand Up @@ -75,6 +76,8 @@ class Manager implements IManager {
private $groupManager;
/** @var IL10N */
private $l;
/** @var IFactory */
private $l10nFactory;
/** @var IUserManager */
private $userManager;
/** @var IRootFolder */
Expand Down Expand Up @@ -103,6 +106,7 @@ class Manager implements IManager {
* @param IMountManager $mountManager
* @param IGroupManager $groupManager
* @param IL10N $l
* @param IFactory $l10nFactory
* @param IProviderFactory $factory
* @param IUserManager $userManager
* @param IRootFolder $rootFolder
Expand All @@ -119,6 +123,7 @@ public function __construct(
IMountManager $mountManager,
IGroupManager $groupManager,
IL10N $l,
IFactory $l10nFactory,
IProviderFactory $factory,
IUserManager $userManager,
IRootFolder $rootFolder,
Expand All @@ -134,6 +139,7 @@ public function __construct(
$this->mountManager = $mountManager;
$this->groupManager = $groupManager;
$this->l = $l;
$this->l10nFactory = $l10nFactory;
$this->factory = $factory;
$this->userManager = $userManager;
$this->rootFolder = $rootFolder;
Expand Down Expand Up @@ -689,7 +695,10 @@ public function createShare(\OCP\Share\IShare $share) {
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(),
Expand All @@ -709,21 +718,23 @@ public function createShare(\OCP\Share\IShare $share) {
}

/**
* @param IL10N $l Language of the recipient
* @param string $filename file/folder name
* @param string $link link to the file/folder
* @param string $initiator user ID of share sender
* @param string $shareWith email address of share receiver
* @param \DateTime|null $expiration
* @throws \Exception If mail couldn't be sent
*/
protected function sendMailNotification($filename,
protected function sendMailNotification(IL10N $l,
$filename,
$link,
$initiator,
$shareWith,
\DateTime $expiration = null) {
$initiatorUser = $this->userManager->get($initiator);
$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
$subject = (string)$this->l->t('%s shared »%s« with you', array($initiatorDisplayName, $filename));
$subject = $l->t('%s shared »%s« with you', array($initiatorDisplayName, $filename));

$message = $this->mailer->createMessage();

Expand All @@ -736,23 +747,23 @@ protected function sendMailNotification($filename,
]);

$emailTemplate->addHeader();
$emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$initiatorDisplayName, $filename]), false);
$text = $this->l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]);
$emailTemplate->addHeading($l->t('%s shared »%s« with you', [$initiatorDisplayName, $filename]), false);
$text = $l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]);

$emailTemplate->addBodyText(
$text . ' ' . $this->l->t('Click the button below to open it.'),
$text . ' ' . $l->t('Click the button below to open it.'),
$text
);
$emailTemplate->addBodyButton(
$this->l->t('Open »%s«', [$filename]),
$l->t('Open »%s«', [$filename]),
$link
);

$message->setTo([$shareWith]);

// The "From" contains the sharers name
$instanceName = $this->defaults->getName();
$senderName = $this->l->t(
$senderName = $l->t(
'%s via %s',
[
$initiatorDisplayName,
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Mail\IMailer;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IProviderFactory;
Expand Down Expand Up @@ -80,6 +81,8 @@ class ManagerTest extends \Test\TestCase {
protected $groupManager;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
protected $l;
/** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
protected $l10nFactory;
/** @var DummyFactory */
protected $factory;
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
Expand Down Expand Up @@ -110,6 +113,7 @@ public function setUp() {
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->defaults = $this->createMock(\OC_Defaults::class);

$this->l10nFactory = $this->createMock(IFactory::class);
$this->l = $this->createMock(IL10N::class);
$this->l->method('t')
->will($this->returnCallback(function($text, $parameters = []) {
Expand All @@ -126,6 +130,7 @@ public function setUp() {
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$this->factory,
$this->userManager,
$this->rootFolder,
Expand Down Expand Up @@ -153,6 +158,7 @@ private function createManagerMock() {
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$this->factory,
$this->userManager,
$this->rootFolder,
Expand Down Expand Up @@ -2089,6 +2095,7 @@ public function testGetShareByToken() {
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$factory,
$this->userManager,
$this->rootFolder,
Expand Down Expand Up @@ -2131,6 +2138,7 @@ public function testGetShareByTokenWithException() {
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$factory,
$this->userManager,
$this->rootFolder,
Expand Down Expand Up @@ -2782,6 +2790,7 @@ public function testShareProviderExists($shareType, $expected) {
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$factory,
$this->userManager,
$this->rootFolder,
Expand Down Expand Up @@ -2813,6 +2822,7 @@ public function testGetSharesInFolder() {
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$factory,
$this->userManager,
$this->rootFolder,
Expand Down Expand Up @@ -2875,6 +2885,7 @@ public function testGetAccessList() {
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$factory,
$this->userManager,
$this->rootFolder,
Expand Down