diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-09-05 16:08:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-05 16:08:57 +0200 |
commit | 15cd21d252b9da706be817df77e4c0643b40327f (patch) | |
tree | a38c9c53c35c3a40fbd8ee2bf2c5d05fac586918 | |
parent | cebbb1633aab6c1dfb20be9b49212b934c3b5e68 (diff) | |
parent | 4e3c39c1d1210b6216462e8e26db93f65a4767e6 (diff) | |
download | nextcloud-server-15cd21d252b9da706be817df77e4c0643b40327f.tar.gz nextcloud-server-15cd21d252b9da706be817df77e4c0643b40327f.zip |
Merge pull request #6358 from nextcloud/fix-mixup-of-id-and-name
Set the meta data before everything
-rw-r--r-- | apps/sharebymail/lib/ShareByMailProvider.php | 9 | ||||
-rw-r--r-- | core/Controller/LostController.php | 3 | ||||
-rw-r--r-- | lib/private/Mail/EMailTemplate.php | 16 | ||||
-rw-r--r-- | lib/private/Mail/Mailer.php | 19 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 3 | ||||
-rw-r--r-- | lib/public/Mail/IEMailTemplate.php | 6 | ||||
-rw-r--r-- | lib/public/Mail/IMailer.php | 6 | ||||
-rw-r--r-- | settings/Controller/MailSettingsController.php | 4 | ||||
-rw-r--r-- | settings/Hooks.php | 6 | ||||
-rw-r--r-- | settings/Mailer/NewUserMailHelper.php | 24 | ||||
-rw-r--r-- | tests/Settings/Mailer/NewUserMailHelperTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Mail/EMailTemplateTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Mail/MailerTest.php | 2 |
13 files changed, 51 insertions, 55 deletions
diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index e5ae64ba120..9a0678f5fe7 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -384,8 +384,7 @@ class ShareByMailProvider implements IShareProvider { $message = $this->mailer->createMessage(); - $emailTemplate = $this->mailer->createEMailTemplate(); - $emailTemplate->setMetaData('sharebymail.RecipientNotification', [ + $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.RecipientNotification', [ 'filename' => $filename, 'link' => $link, 'initiator' => $initiatorDisplayName, @@ -462,8 +461,7 @@ class ShareByMailProvider implements IShareProvider { $message = $this->mailer->createMessage(); - $emailTemplate = $this->mailer->createEMailTemplate(); - $emailTemplate->setMetaData('sharebymail.RecipientPasswordNotification', [ + $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.RecipientPasswordNotification', [ 'filename' => $filename, 'password' => $password, 'initiator' => $initiatorDisplayName, @@ -530,8 +528,7 @@ class ShareByMailProvider implements IShareProvider { $bodyPart = $this->l->t("You just shared »%s« with %s. The share was already send to the recipient. Due to the security policies defined by the administrator of %s each share needs to be protected by password and it is not allowed to send the password directly to the recipient. Therefore you need to forward the password manually to the recipient.", [$filename, $shareWith, $this->defaults->getName()]); $message = $this->mailer->createMessage(); - $emailTemplate = $this->mailer->createEMailTemplate(); - $emailTemplate->setMetaData('sharebymail.OwnerPasswordNotification', [ + $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.OwnerPasswordNotification', [ 'filename' => $filename, 'password' => $password, 'initiator' => $initiatorDisplayName, diff --git a/core/Controller/LostController.php b/core/Controller/LostController.php index 45423b41e8b..4c59b0a1c00 100644 --- a/core/Controller/LostController.php +++ b/core/Controller/LostController.php @@ -305,8 +305,7 @@ class LostController extends Controller { $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user->getUID(), 'token' => $token)); - $emailTemplate = $this->mailer->createEMailTemplate(); - $emailTemplate->setMetaData('core.ResetPassword', [ + $emailTemplate = $this->mailer->createEMailTemplate('core.ResetPassword', [ 'link' => $link, ]); diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index 32cb01f30b3..da3341b6709 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -342,24 +342,18 @@ 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) { + IL10N $l10n, + $emailId, + array $data) { $this->themingDefaults = $themingDefaults; $this->urlGenerator = $urlGenerator; $this->l10n = $l10n; $this->htmlBody .= $this->head; - } - - /** - * Set meta data of an email - * - * @param string $emailId - * @param array $data - * @since 12.0.3 - */ - public function setMetaData($emailId, array $data = []) { $this->emailId = $emailId; $this->data = $data; } diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index d232587df63..45405157d26 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -26,6 +26,7 @@ use OCP\Defaults; use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; +use OCP\Mail\IEMailTemplate; use OCP\Mail\IMailer; use OCP\ILogger; @@ -89,21 +90,33 @@ class Mailer implements IMailer { return new Message(new \Swift_Message()); } - public function createEMailTemplate() { + /** + * Creates a new email template object + * + * @param string $emailId + * @param array $data + * @return IEMailTemplate + * @since 12.0.0 + */ + public function createEMailTemplate($emailId, array $data = []) { $class = $this->config->getSystemValue('mail_template_class', ''); if ($class !== '' && class_exists($class) && is_a($class, EMailTemplate::class, true)) { return new $class( $this->defaults, $this->urlGenerator, - $this->l10n + $this->l10n, + $emailId, + $data ); } return new EMailTemplate( $this->defaults, $this->urlGenerator, - $this->l10n + $this->l10n, + $emailId, + $data ); } diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 46e3bd75c5c..886a319b1e7 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -696,8 +696,7 @@ class Manager implements IManager { $message = $this->mailer->createMessage(); - $emailTemplate = $this->mailer->createEMailTemplate(); - $emailTemplate->setMetaData('files_sharing.RecipientNotification', [ + $emailTemplate = $this->mailer->createEMailTemplate('files_sharing.RecipientNotification', [ 'filename' => $filename, 'link' => $link, 'initiator' => $initiatorDisplayName, diff --git a/lib/public/Mail/IEMailTemplate.php b/lib/public/Mail/IEMailTemplate.php index 2ff4a486f75..6c71c0c0473 100644 --- a/lib/public/Mail/IEMailTemplate.php +++ b/lib/public/Mail/IEMailTemplate.php @@ -51,12 +51,6 @@ namespace OCP\Mail; * @since 12.0.0 */ interface IEMailTemplate { - /** - * Set meta data of an email - * - * @since 12.0.3 - */ - public function setMetaData($emailId, array $data = []); /** * Adds a header to the email diff --git a/lib/public/Mail/IMailer.php b/lib/public/Mail/IMailer.php index af16a8a239a..c283d346745 100644 --- a/lib/public/Mail/IMailer.php +++ b/lib/public/Mail/IMailer.php @@ -57,10 +57,12 @@ interface IMailer { /** * Creates a new email template object * + * @param string $emailId + * @param array $data * @return IEMailTemplate - * @since 12.0.0 + * @since 12.0.0 Parameters added in 12.0.3 */ - public function createEMailTemplate(); + public function createEMailTemplate($emailId, array $data = []); /** * Send the specified message. Also sets the from address to the value defined in config.php diff --git a/settings/Controller/MailSettingsController.php b/settings/Controller/MailSettingsController.php index 44cece1d658..974a95618ad 100644 --- a/settings/Controller/MailSettingsController.php +++ b/settings/Controller/MailSettingsController.php @@ -147,9 +147,7 @@ class MailSettingsController extends Controller { try { $displayName = $this->userSession->getUser()->getDisplayName(); - $template = $this->mailer->createEMailTemplate(); - - $template->setMetaData('settings.TestEmail', [ + $template = $this->mailer->createEMailTemplate('settings.TestEmail', [ 'displayname' => $displayName, ]); diff --git a/settings/Hooks.php b/settings/Hooks.php index f97145da0c0..6f537796517 100644 --- a/settings/Hooks.php +++ b/settings/Hooks.php @@ -117,8 +117,7 @@ class Hooks { $this->activityManager->publish($event); if ($user->getEMailAddress() !== null) { - $template = $this->mailer->createEMailTemplate(); - $template->setMetaData('settings.PasswordChanged', [ + $template = $this->mailer->createEMailTemplate('settings.PasswordChanged', [ 'displayname' => $user->getDisplayName(), 'emailAddress' => $user->getEMailAddress(), 'instanceUrl' => $instanceUrl, @@ -188,8 +187,7 @@ class Hooks { if ($oldMailAddress !== null) { - $template = $this->mailer->createEMailTemplate(); - $template->setMetaData('settings.EmailChanged', [ + $template = $this->mailer->createEMailTemplate('settings.EmailChanged', [ 'displayname' => $user->getDisplayName(), 'newEMailAddress' => $user->getEMailAddress(), 'oldEMailAddress' => $oldMailAddress, diff --git a/settings/Mailer/NewUserMailHelper.php b/settings/Mailer/NewUserMailHelper.php index c4c09653370..9fc6a4a3c70 100644 --- a/settings/Mailer/NewUserMailHelper.php +++ b/settings/Mailer/NewUserMailHelper.php @@ -21,7 +21,6 @@ namespace OC\Settings\Mailer; -use OC\Mail\EMailTemplate; use OCP\Mail\IEMailTemplate; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Defaults; @@ -96,7 +95,7 @@ class NewUserMailHelper { /** * @param IUser $user * @param bool $generatePasswordResetToken - * @return EMailTemplate + * @return IEMailTemplate */ public function generateTemplate(IUser $user, $generatePasswordResetToken = false) { if ($generatePasswordResetToken) { @@ -114,11 +113,18 @@ class NewUserMailHelper { } else { $link = $this->urlGenerator->getAbsoluteURL('/'); } - - $emailTemplate = $this->mailer->createEMailTemplate(); - $emailTemplate->addHeader(); $displayName = $user->getDisplayName(); $userId = $user->getUID(); + + $emailTemplate = $this->mailer->createEMailTemplate('settings.Welcome', [ + 'link' => $link, + 'displayname' => $displayName, + 'userid' => $userId, + 'instancename' => $this->themingDefaults->getName(), + 'resetTokenGenerated' => $generatePasswordResetToken, + ]); + + $emailTemplate->addHeader(); if ($displayName === $userId) { $emailTemplate->addHeading($this->l10n->t('Welcome aboard')); } else { @@ -139,14 +145,6 @@ class NewUserMailHelper { ); $emailTemplate->addFooter(); - $emailTemplate->setMetaData('settings.Welcome', [ - 'link' => $link, - 'displayname' => $displayName, - 'userid' => $userId, - 'instancename' => $this->themingDefaults->getName(), - 'resetTokenGenerated' => $generatePasswordResetToken, - ]); - return $emailTemplate; } diff --git a/tests/Settings/Mailer/NewUserMailHelperTest.php b/tests/Settings/Mailer/NewUserMailHelperTest.php index 40ba9ee1c21..033847e49f6 100644 --- a/tests/Settings/Mailer/NewUserMailHelperTest.php +++ b/tests/Settings/Mailer/NewUserMailHelperTest.php @@ -66,7 +66,9 @@ class NewUserMailHelperTest extends TestCase { $template = new EMailTemplate( $this->defaults, $this->urlGenerator, - $this->l10n + $this->l10n, + 'test.TestTemplate', + [] ); $this->mailer->method('createEMailTemplate') ->will($this->returnValue($template)); diff --git a/tests/lib/Mail/EMailTemplateTest.php b/tests/lib/Mail/EMailTemplateTest.php index 08af56453ab..b2d08f7e81b 100644 --- a/tests/lib/Mail/EMailTemplateTest.php +++ b/tests/lib/Mail/EMailTemplateTest.php @@ -49,7 +49,9 @@ class EMailTemplateTest extends TestCase { $this->emailTemplate = new EMailTemplate( $this->defaults, $this->urlGenerator, - $this->l10n + $this->l10n, + 'test.TestTemplate', + [] ); } diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php index a7226b9ecd6..f647b966f1f 100644 --- a/tests/lib/Mail/MailerTest.php +++ b/tests/lib/Mail/MailerTest.php @@ -133,6 +133,6 @@ class MailerTest extends TestCase { } public function testCreateEMailTemplate() { - $this->assertSame(EMailTemplate::class, get_class($this->mailer->createEMailTemplate())); + $this->assertSame(EMailTemplate::class, get_class($this->mailer->createEMailTemplate('tests.MailerTest'))); } } |