diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-04-20 22:32:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-20 22:32:41 +0200 |
commit | bdcaff0f4887148038021de18acdeff36628e6f8 (patch) | |
tree | 980ba1497ea1c37fc76502a97e0ea21459de5a51 | |
parent | 6bb8ad510ee2f9d6213a88e1870f25c8190f6ce6 (diff) | |
parent | 1fa8a8e4843444ff55d1e303450dd8524e66bc4a (diff) | |
download | nextcloud-server-bdcaff0f4887148038021de18acdeff36628e6f8.tar.gz nextcloud-server-bdcaff0f4887148038021de18acdeff36628e6f8.zip |
Merge pull request #20513 from nextcloud/backport/20246/stable17
[stable17] Provide the proper language to the mailer
-rw-r--r-- | apps/theming/lib/ThemingDefaults.php | 4 | ||||
-rw-r--r-- | lib/private/Mail/EMailTemplate.php | 22 | ||||
-rw-r--r-- | lib/private/Mail/Mailer.php | 9 | ||||
-rw-r--r-- | lib/private/Server.php | 4 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 4 | ||||
-rw-r--r-- | lib/private/legacy/defaults.php | 6 | ||||
-rw-r--r-- | lib/public/Defaults.php | 4 | ||||
-rw-r--r-- | lib/public/Mail/IEMailTemplate.php | 3 | ||||
-rw-r--r-- | tests/Settings/Mailer/NewUserMailHelperTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Mail/EMailTemplateTest.php | 9 | ||||
-rw-r--r-- | tests/lib/Mail/MailerTest.php | 4 |
11 files changed, 40 insertions, 31 deletions
diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 6f11f5cfa45..fb10d9ff342 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -139,8 +139,8 @@ class ThemingDefaults extends \OC_Defaults { return $this->config->getAppValue('theming', 'url', $this->url); } - public function getSlogan() { - return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan())); + public function getSlogan(?string $lang = null) { + return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang))); } public function getImprintUrl() { diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index b3654f30382..4f162e9d9ed 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -29,8 +29,8 @@ declare(strict_types=1); namespace OC\Mail; use OCP\Defaults; -use OCP\IL10N; use OCP\IURLGenerator; +use OCP\L10N\IFactory; use OCP\Mail\IEMailTemplate; /** @@ -46,8 +46,8 @@ class EMailTemplate implements IEMailTemplate { protected $themingDefaults; /** @var IURLGenerator */ protected $urlGenerator; - /** @var IL10N */ - protected $l10n; + /** @var IFactory */ + protected $l10nFactory; /** @var string */ protected $emailId; /** @var array */ @@ -344,21 +344,14 @@ EOF; </table> EOF; - /** - * @param Defaults $themingDefaults - * @param IURLGenerator $urlGenerator - * @param IL10N $l10n - * @param string $emailId - * @param array $data - */ public function __construct(Defaults $themingDefaults, IURLGenerator $urlGenerator, - IL10N $l10n, + IFactory $l10nFactory, $emailId, array $data) { $this->themingDefaults = $themingDefaults; $this->urlGenerator = $urlGenerator; - $this->l10n = $l10n; + $this->l10nFactory = $l10nFactory; $this->htmlBody .= $this->head; $this->emailId = $emailId; $this->data = $data; @@ -601,9 +594,10 @@ EOF; * * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used */ - public function addFooter(string $text = '') { + public function addFooter(string $text = '', ?string $lang = null) { if($text === '') { - $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.'); + $l10n = $this->l10nFactory->get('lib', $lang); + $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan($lang) . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.'); } if ($this->footerAdded) { diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index 8f442365585..5125a39b118 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -32,6 +32,7 @@ use OCP\Defaults; use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; +use OCP\L10N\IFactory; use OCP\Mail\IAttachment; use OCP\Mail\IEMailTemplate; use OCP\Mail\IMailer; @@ -69,6 +70,8 @@ class Mailer implements IMailer { private $urlGenerator; /** @var IL10N */ private $l10n; + /** @var IFactory */ + private $l10nFactory; /** * @param IConfig $config @@ -81,12 +84,14 @@ class Mailer implements IMailer { ILogger $logger, Defaults $defaults, IURLGenerator $urlGenerator, - IL10N $l10n) { + IL10N $l10n, + IFactory $l10nFactory) { $this->config = $config; $this->logger = $logger; $this->defaults = $defaults; $this->urlGenerator = $urlGenerator; $this->l10n = $l10n; + $this->l10nFactory = $l10nFactory; } /** @@ -144,7 +149,7 @@ class Mailer implements IMailer { return new EMailTemplate( $this->defaults, $this->urlGenerator, - $this->l10n, + $this->l10nFactory, $emailId, $data ); diff --git a/lib/private/Server.php b/lib/private/Server.php index bce4f0feaef..9ceebf1b433 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -151,6 +151,7 @@ use OCP\IL10N; use OCP\IServerContainer; use OCP\ITempManager; use OCP\IUser; +use OCP\L10N\IFactory; use OCP\Lock\ILockingProvider; use OCP\Log\ILogFactory; use OCP\Remote\Api\IApiFactory; @@ -832,7 +833,8 @@ class Server extends ServerContainer implements IServerContainer { $c->getLogger(), $c->query(Defaults::class), $c->getURLGenerator(), - $c->getL10N('lib') + $c->getL10N('lib'), + $c->query(IFactory::class) ); }); $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 1915ac952f7..f13878d71b4 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -805,9 +805,9 @@ class Manager implements IManager { $initiatorEmail = $initiatorUser->getEMailAddress(); if($initiatorEmail !== null) { $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); - $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')); + $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan($l->getLanguageCode()) !== '' ? ' - ' . $this->defaults->getSlogan($l->getLanguageCode()) : '')); } else { - $emailTemplate->addFooter(); + $emailTemplate->addFooter('', $l->getLanguageCode()); } $message->useTemplate($emailTemplate); diff --git a/lib/private/legacy/defaults.php b/lib/private/legacy/defaults.php index 8633113ba5a..7bd083608d4 100644 --- a/lib/private/legacy/defaults.php +++ b/lib/private/legacy/defaults.php @@ -213,12 +213,12 @@ class OC_Defaults { * Returns slogan * @return string slogan */ - public function getSlogan() { + public function getSlogan(?string $lang = null) { if ($this->themeExist('getSlogan')) { - return $this->theme->getSlogan(); + return $this->theme->getSlogan($lang); } else { if ($this->defaultSlogan === null) { - $l10n = \OC::$server->getL10N('lib'); + $l10n = \OC::$server->getL10N('lib', $lang); $this->defaultSlogan = $l10n->t('a safe home for all your data'); } return $this->defaultSlogan; diff --git a/lib/public/Defaults.php b/lib/public/Defaults.php index bf790bb7239..c93b0f5e455 100644 --- a/lib/public/Defaults.php +++ b/lib/public/Defaults.php @@ -135,8 +135,8 @@ class Defaults { * @return string * @since 6.0.0 */ - public function getSlogan() { - return $this->defaults->getSlogan(); + public function getSlogan(?string $lang = null) { + return $this->defaults->getSlogan($lang); } /** diff --git a/lib/public/Mail/IEMailTemplate.php b/lib/public/Mail/IEMailTemplate.php index 1c0ddbe54d4..18456178ed9 100644 --- a/lib/public/Mail/IEMailTemplate.php +++ b/lib/public/Mail/IEMailTemplate.php @@ -138,10 +138,11 @@ interface IEMailTemplate { * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email * * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used + * @param string $lang Optional language to set the default footer in * * @since 12.0.0 */ - public function addFooter(string $text = ''); + public function addFooter(string $text = '', ?string $lang = null); /** * Returns the rendered email subject as string diff --git a/tests/Settings/Mailer/NewUserMailHelperTest.php b/tests/Settings/Mailer/NewUserMailHelperTest.php index 0e7bc395f2a..8e6f1b41ac7 100644 --- a/tests/Settings/Mailer/NewUserMailHelperTest.php +++ b/tests/Settings/Mailer/NewUserMailHelperTest.php @@ -70,7 +70,7 @@ class NewUserMailHelperTest extends TestCase { $template = new EMailTemplate( $this->defaults, $this->urlGenerator, - $this->l10n, + $this->l10nFactory, 'test.TestTemplate', [] ); diff --git a/tests/lib/Mail/EMailTemplateTest.php b/tests/lib/Mail/EMailTemplateTest.php index d4687c44b06..713f19307fc 100644 --- a/tests/lib/Mail/EMailTemplateTest.php +++ b/tests/lib/Mail/EMailTemplateTest.php @@ -27,6 +27,7 @@ use OC\Mail\EMailTemplate; use OCP\Defaults; use OCP\IL10N; use OCP\IURLGenerator; +use OCP\L10N\IFactory; use Test\TestCase; class EMailTemplateTest extends TestCase { @@ -34,7 +35,7 @@ class EMailTemplateTest extends TestCase { private $defaults; /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ private $urlGenerator; - /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */ private $l10n; /** @var EMailTemplate */ private $emailTemplate; @@ -44,7 +45,11 @@ class EMailTemplateTest extends TestCase { $this->defaults = $this->createMock(Defaults::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); - $this->l10n = $this->createMock(IL10N::class); + $this->l10n = $this->createMock(IFactory::class); + + $this->l10n->method('get') + ->with('lib', '') + ->willReturn($this->createMock(IL10N::class)); $this->emailTemplate = new EMailTemplate( $this->defaults, diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php index 1913cc1176c..b71d6646c56 100644 --- a/tests/lib/Mail/MailerTest.php +++ b/tests/lib/Mail/MailerTest.php @@ -15,6 +15,7 @@ use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; use OCP\IURLGenerator; +use OCP\L10N\IFactory; use Test\TestCase; class MailerTest extends TestCase { @@ -44,7 +45,8 @@ class MailerTest extends TestCase { $this->logger, $this->defaults, $this->urlGenerator, - $this->l10n + $this->l10n, + $this->createMock(IFactory::class) ); } |