Use the language of the recipient for the share notification

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2017-09-08 10:34:19 +02:00
parent 194f880073
commit 7e625a8d22
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
3 changed files with 31 additions and 12 deletions

View File

@ -55,8 +55,6 @@ use OC\Authentication\LoginCredentials\Store;
use OC\Command\CronBus; use OC\Command\CronBus;
use OC\Contacts\ContactsMenu\ActionFactory; use OC\Contacts\ContactsMenu\ActionFactory;
use OC\Diagnostics\EventLogger; use OC\Diagnostics\EventLogger;
use OC\Diagnostics\NullEventLogger;
use OC\Diagnostics\NullQueryLogger;
use OC\Diagnostics\QueryLogger; use OC\Diagnostics\QueryLogger;
use OC\Federation\CloudIdManager; use OC\Federation\CloudIdManager;
use OC\Files\Config\UserMountCache; use OC\Files\Config\UserMountCache;
@ -114,7 +112,6 @@ use OCP\IL10N;
use OCP\IServerContainer; use OCP\IServerContainer;
use OCP\ITempManager; use OCP\ITempManager;
use OCP\Contacts\ContactsMenu\IActionFactory; use OCP\Contacts\ContactsMenu\IActionFactory;
use OCP\IURLGenerator;
use OCP\Lock\ILockingProvider; use OCP\Lock\ILockingProvider;
use OCP\RichObjectStrings\IValidator; use OCP\RichObjectStrings\IValidator;
use OCP\Security\IContentSecurityPolicyManager; use OCP\Security\IContentSecurityPolicyManager;
@ -980,7 +977,8 @@ class Server extends ServerContainer implements IServerContainer {
$c->getHasher(), $c->getHasher(),
$c->getMountManager(), $c->getMountManager(),
$c->getGroupManager(), $c->getGroupManager(),
$c->getL10N('core'), $c->getL10N('lib'),
$c->getL10NFactory(),
$factory, $factory,
$c->getUserManager(), $c->getUserManager(),
$c->getLazyRootFolder(), $c->getLazyRootFolder(),

View File

@ -31,7 +31,6 @@ use OC\Cache\CappedMemoryCache;
use OC\Files\Mount\MoveableMount; use OC\Files\Mount\MoveableMount;
use OC\HintException; use OC\HintException;
use OC\Share20\Exception\ProviderException; use OC\Share20\Exception\ProviderException;
use OCP\Defaults;
use OCP\Files\File; use OCP\Files\File;
use OCP\Files\Folder; use OCP\Files\Folder;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
@ -44,6 +43,7 @@ use OCP\ILogger;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Mail\IMailer; use OCP\Mail\IMailer;
use OCP\Security\IHasher; use OCP\Security\IHasher;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
@ -76,6 +76,8 @@ class Manager implements IManager {
private $groupManager; private $groupManager;
/** @var IL10N */ /** @var IL10N */
private $l; private $l;
/** @var IFactory */
private $l10nFactory;
/** @var IUserManager */ /** @var IUserManager */
private $userManager; private $userManager;
/** @var IRootFolder */ /** @var IRootFolder */
@ -104,6 +106,7 @@ class Manager implements IManager {
* @param IMountManager $mountManager * @param IMountManager $mountManager
* @param IGroupManager $groupManager * @param IGroupManager $groupManager
* @param IL10N $l * @param IL10N $l
* @param IFactory $l10nFactory
* @param IProviderFactory $factory * @param IProviderFactory $factory
* @param IUserManager $userManager * @param IUserManager $userManager
* @param IRootFolder $rootFolder * @param IRootFolder $rootFolder
@ -120,6 +123,7 @@ class Manager implements IManager {
IMountManager $mountManager, IMountManager $mountManager,
IGroupManager $groupManager, IGroupManager $groupManager,
IL10N $l, IL10N $l,
IFactory $l10nFactory,
IProviderFactory $factory, IProviderFactory $factory,
IUserManager $userManager, IUserManager $userManager,
IRootFolder $rootFolder, IRootFolder $rootFolder,
@ -135,6 +139,7 @@ class Manager implements IManager {
$this->mountManager = $mountManager; $this->mountManager = $mountManager;
$this->groupManager = $groupManager; $this->groupManager = $groupManager;
$this->l = $l; $this->l = $l;
$this->l10nFactory = $l10nFactory;
$this->factory = $factory; $this->factory = $factory;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
@ -658,7 +663,10 @@ class Manager implements IManager {
if ($user !== null) { if ($user !== null) {
$emailAddress = $user->getEMailAddress(); $emailAddress = $user->getEMailAddress();
if ($emailAddress !== null && $emailAddress !== '') { if ($emailAddress !== null && $emailAddress !== '') {
$userLang = $this->config->getUserValue($share->getSharedWith(), 'core', 'lang', null);
$l = $this->l10nFactory->get('lib', $userLang);
$this->sendMailNotification( $this->sendMailNotification(
$l,
$share->getNode()->getName(), $share->getNode()->getName(),
$this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', [ 'fileid' => $share->getNode()->getId() ]), $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', [ 'fileid' => $share->getNode()->getId() ]),
$share->getSharedBy(), $share->getSharedBy(),
@ -678,6 +686,7 @@ class Manager implements IManager {
} }
/** /**
* @param IL10N $l Language of the recipient
* @param string $filename file/folder name * @param string $filename file/folder name
* @param string $link link to the file/folder * @param string $link link to the file/folder
* @param string $initiator user ID of share sender * @param string $initiator user ID of share sender
@ -685,14 +694,15 @@ class Manager implements IManager {
* @param \DateTime|null $expiration * @param \DateTime|null $expiration
* @throws \Exception If mail couldn't be sent * @throws \Exception If mail couldn't be sent
*/ */
protected function sendMailNotification($filename, protected function sendMailNotification(IL10N $l,
$filename,
$link, $link,
$initiator, $initiator,
$shareWith, $shareWith,
\DateTime $expiration = null) { \DateTime $expiration = null) {
$initiatorUser = $this->userManager->get($initiator); $initiatorUser = $this->userManager->get($initiator);
$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $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(); $message = $this->mailer->createMessage();
@ -705,15 +715,15 @@ class Manager implements IManager {
]); ]);
$emailTemplate->addHeader(); $emailTemplate->addHeader();
$emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$initiatorDisplayName, $filename]), false); $emailTemplate->addHeading($l->t('%s shared »%s« with you', [$initiatorDisplayName, $filename]), false);
$text = $this->l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]); $text = $l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]);
$emailTemplate->addBodyText( $emailTemplate->addBodyText(
$text . ' ' . $this->l->t('Click the button below to open it.'), $text . ' ' . $l->t('Click the button below to open it.'),
$text $text
); );
$emailTemplate->addBodyButton( $emailTemplate->addBodyButton(
$this->l->t('Open »%s«', [$filename]), $l->t('Open »%s«', [$filename]),
$link $link
); );
@ -721,7 +731,7 @@ class Manager implements IManager {
// The "From" contains the sharers name // The "From" contains the sharers name
$instanceName = $this->defaults->getName(); $instanceName = $this->defaults->getName();
$senderName = $this->l->t( $senderName = $l->t(
'%s via %s', '%s via %s',
[ [
$initiatorDisplayName, $initiatorDisplayName,

View File

@ -35,6 +35,7 @@ use OCP\IServerContainer;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Mail\IMailer; use OCP\Mail\IMailer;
use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IProviderFactory; use OCP\Share\IProviderFactory;
@ -80,6 +81,8 @@ class ManagerTest extends \Test\TestCase {
protected $groupManager; protected $groupManager;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */ /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
protected $l; protected $l;
/** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
protected $l10nFactory;
/** @var DummyFactory */ /** @var DummyFactory */
protected $factory; protected $factory;
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
@ -110,6 +113,7 @@ class ManagerTest extends \Test\TestCase {
$this->urlGenerator = $this->createMock(IURLGenerator::class); $this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->defaults = $this->createMock(\OC_Defaults::class); $this->defaults = $this->createMock(\OC_Defaults::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->l = $this->createMock(IL10N::class); $this->l = $this->createMock(IL10N::class);
$this->l->method('t') $this->l->method('t')
->will($this->returnCallback(function($text, $parameters = []) { ->will($this->returnCallback(function($text, $parameters = []) {
@ -126,6 +130,7 @@ class ManagerTest extends \Test\TestCase {
$this->mountManager, $this->mountManager,
$this->groupManager, $this->groupManager,
$this->l, $this->l,
$this->l10nFactory,
$this->factory, $this->factory,
$this->userManager, $this->userManager,
$this->rootFolder, $this->rootFolder,
@ -153,6 +158,7 @@ class ManagerTest extends \Test\TestCase {
$this->mountManager, $this->mountManager,
$this->groupManager, $this->groupManager,
$this->l, $this->l,
$this->l10nFactory,
$this->factory, $this->factory,
$this->userManager, $this->userManager,
$this->rootFolder, $this->rootFolder,
@ -2124,6 +2130,7 @@ class ManagerTest extends \Test\TestCase {
$this->mountManager, $this->mountManager,
$this->groupManager, $this->groupManager,
$this->l, $this->l,
$this->l10nFactory,
$factory, $factory,
$this->userManager, $this->userManager,
$this->rootFolder, $this->rootFolder,
@ -2166,6 +2173,7 @@ class ManagerTest extends \Test\TestCase {
$this->mountManager, $this->mountManager,
$this->groupManager, $this->groupManager,
$this->l, $this->l,
$this->l10nFactory,
$factory, $factory,
$this->userManager, $this->userManager,
$this->rootFolder, $this->rootFolder,
@ -2817,6 +2825,7 @@ class ManagerTest extends \Test\TestCase {
$this->mountManager, $this->mountManager,
$this->groupManager, $this->groupManager,
$this->l, $this->l,
$this->l10nFactory,
$factory, $factory,
$this->userManager, $this->userManager,
$this->rootFolder, $this->rootFolder,
@ -2848,6 +2857,7 @@ class ManagerTest extends \Test\TestCase {
$this->mountManager, $this->mountManager,
$this->groupManager, $this->groupManager,
$this->l, $this->l,
$this->l10nFactory,
$factory, $factory,
$this->userManager, $this->userManager,
$this->rootFolder, $this->rootFolder,
@ -2910,6 +2920,7 @@ class ManagerTest extends \Test\TestCase {
$this->mountManager, $this->mountManager,
$this->groupManager, $this->groupManager,
$this->l, $this->l,
$this->l10nFactory,
$factory, $factory,
$this->userManager, $this->userManager,
$this->rootFolder, $this->rootFolder,