Use the language of the recipient for the share notification
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
b7768ac11d
commit
2a6855a76d
|
@ -963,7 +963,8 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
$c->getHasher(),
|
||||
$c->getMountManager(),
|
||||
$c->getGroupManager(),
|
||||
$c->getL10N('core'),
|
||||
$c->getL10N('lib'),
|
||||
$c->getL10NFactory(),
|
||||
$factory,
|
||||
$c->getUserManager(),
|
||||
$c->getLazyRootFolder(),
|
||||
|
|
|
@ -43,6 +43,7 @@ use OCP\ILogger;
|
|||
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;
|
||||
|
@ -75,6 +76,8 @@ class Manager implements IManager {
|
|||
private $groupManager;
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
/** @var IFactory */
|
||||
private $l10nFactory;
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var IRootFolder */
|
||||
|
@ -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
|
||||
|
@ -119,6 +123,7 @@ class Manager implements IManager {
|
|||
IMountManager $mountManager,
|
||||
IGroupManager $groupManager,
|
||||
IL10N $l,
|
||||
IFactory $l10nFactory,
|
||||
IProviderFactory $factory,
|
||||
IUserManager $userManager,
|
||||
IRootFolder $rootFolder,
|
||||
|
@ -134,6 +139,7 @@ class Manager implements IManager {
|
|||
$this->mountManager = $mountManager;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->l = $l;
|
||||
$this->l10nFactory = $l10nFactory;
|
||||
$this->factory = $factory;
|
||||
$this->userManager = $userManager;
|
||||
$this->rootFolder = $rootFolder;
|
||||
|
@ -689,7 +695,10 @@ class Manager implements IManager {
|
|||
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(),
|
||||
|
@ -709,6 +718,7 @@ class Manager implements IManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
@ -716,14 +726,15 @@ class Manager implements IManager {
|
|||
* @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();
|
||||
|
||||
|
@ -736,15 +747,15 @@ class Manager implements IManager {
|
|||
]);
|
||||
|
||||
$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
|
||||
);
|
||||
|
||||
|
@ -752,7 +763,7 @@ class Manager implements IManager {
|
|||
|
||||
// The "From" contains the sharers name
|
||||
$instanceName = $this->defaults->getName();
|
||||
$senderName = $this->l->t(
|
||||
$senderName = $l->t(
|
||||
'%s via %s',
|
||||
[
|
||||
$initiatorDisplayName,
|
||||
|
|
|
@ -35,6 +35,7 @@ use OCP\IServerContainer;
|
|||
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;
|
||||
|
@ -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 */
|
||||
|
@ -110,6 +113,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$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 = []) {
|
||||
|
@ -126,6 +130,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$this->factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
|
@ -153,6 +158,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$this->factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
|
@ -2089,6 +2095,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
|
@ -2131,6 +2138,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
|
@ -2782,6 +2790,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
|
@ -2813,6 +2822,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
|
@ -2875,6 +2885,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
|
|
Loading…
Reference in New Issue