Merge pull request #4304 from nextcloud/add-email-template-to-ocp
Add IEMailTemplate to public OCP API
This commit is contained in:
commit
6bd1c50dc3
|
@ -32,7 +32,7 @@ namespace OCA\Provisioning_API\Tests\Controller;
|
||||||
use Exception;
|
use Exception;
|
||||||
use OC\Accounts\AccountManager;
|
use OC\Accounts\AccountManager;
|
||||||
use OC\Group\Manager;
|
use OC\Group\Manager;
|
||||||
use OC\Mail\IEMailTemplate;
|
use OCP\Mail\IEMailTemplate;
|
||||||
use OC\Settings\Mailer\NewUserMailHelper;
|
use OC\Settings\Mailer\NewUserMailHelper;
|
||||||
use OC\SubAdmin;
|
use OC\SubAdmin;
|
||||||
use OCA\Provisioning_API\Controller\UsersController;
|
use OCA\Provisioning_API\Controller\UsersController;
|
||||||
|
|
|
@ -211,6 +211,7 @@ return array(
|
||||||
'OCP\\Lock\\ILockingProvider' => $baseDir . '/lib/public/Lock/ILockingProvider.php',
|
'OCP\\Lock\\ILockingProvider' => $baseDir . '/lib/public/Lock/ILockingProvider.php',
|
||||||
'OCP\\Lock\\LockedException' => $baseDir . '/lib/public/Lock/LockedException.php',
|
'OCP\\Lock\\LockedException' => $baseDir . '/lib/public/Lock/LockedException.php',
|
||||||
'OCP\\Lockdown\\ILockdownManager' => $baseDir . '/lib/public/Lockdown/ILockdownManager.php',
|
'OCP\\Lockdown\\ILockdownManager' => $baseDir . '/lib/public/Lockdown/ILockdownManager.php',
|
||||||
|
'OCP\\Mail\\IEMailTemplate' => $baseDir . '/lib/public/Mail/IEMailTemplate.php',
|
||||||
'OCP\\Mail\\IMailer' => $baseDir . '/lib/public/Mail/IMailer.php',
|
'OCP\\Mail\\IMailer' => $baseDir . '/lib/public/Mail/IMailer.php',
|
||||||
'OCP\\Migration\\IOutput' => $baseDir . '/lib/public/Migration/IOutput.php',
|
'OCP\\Migration\\IOutput' => $baseDir . '/lib/public/Migration/IOutput.php',
|
||||||
'OCP\\Migration\\IRepairStep' => $baseDir . '/lib/public/Migration/IRepairStep.php',
|
'OCP\\Migration\\IRepairStep' => $baseDir . '/lib/public/Migration/IRepairStep.php',
|
||||||
|
@ -638,7 +639,6 @@ return array(
|
||||||
'OC\\Log\\Rotate' => $baseDir . '/lib/private/Log/Rotate.php',
|
'OC\\Log\\Rotate' => $baseDir . '/lib/private/Log/Rotate.php',
|
||||||
'OC\\Log\\Syslog' => $baseDir . '/lib/private/Log/Syslog.php',
|
'OC\\Log\\Syslog' => $baseDir . '/lib/private/Log/Syslog.php',
|
||||||
'OC\\Mail\\EMailTemplate' => $baseDir . '/lib/private/Mail/EMailTemplate.php',
|
'OC\\Mail\\EMailTemplate' => $baseDir . '/lib/private/Mail/EMailTemplate.php',
|
||||||
'OC\\Mail\\IEMailTemplate' => $baseDir . '/lib/private/Mail/IEMailTemplate.php',
|
|
||||||
'OC\\Mail\\Mailer' => $baseDir . '/lib/private/Mail/Mailer.php',
|
'OC\\Mail\\Mailer' => $baseDir . '/lib/private/Mail/Mailer.php',
|
||||||
'OC\\Mail\\Message' => $baseDir . '/lib/private/Mail/Message.php',
|
'OC\\Mail\\Message' => $baseDir . '/lib/private/Mail/Message.php',
|
||||||
'OC\\Memcache\\APCu' => $baseDir . '/lib/private/Memcache/APCu.php',
|
'OC\\Memcache\\APCu' => $baseDir . '/lib/private/Memcache/APCu.php',
|
||||||
|
|
|
@ -241,6 +241,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
||||||
'OCP\\Lock\\ILockingProvider' => __DIR__ . '/../../..' . '/lib/public/Lock/ILockingProvider.php',
|
'OCP\\Lock\\ILockingProvider' => __DIR__ . '/../../..' . '/lib/public/Lock/ILockingProvider.php',
|
||||||
'OCP\\Lock\\LockedException' => __DIR__ . '/../../..' . '/lib/public/Lock/LockedException.php',
|
'OCP\\Lock\\LockedException' => __DIR__ . '/../../..' . '/lib/public/Lock/LockedException.php',
|
||||||
'OCP\\Lockdown\\ILockdownManager' => __DIR__ . '/../../..' . '/lib/public/Lockdown/ILockdownManager.php',
|
'OCP\\Lockdown\\ILockdownManager' => __DIR__ . '/../../..' . '/lib/public/Lockdown/ILockdownManager.php',
|
||||||
|
'OCP\\Mail\\IEMailTemplate' => __DIR__ . '/../../..' . '/lib/public/Mail/IEMailTemplate.php',
|
||||||
'OCP\\Mail\\IMailer' => __DIR__ . '/../../..' . '/lib/public/Mail/IMailer.php',
|
'OCP\\Mail\\IMailer' => __DIR__ . '/../../..' . '/lib/public/Mail/IMailer.php',
|
||||||
'OCP\\Migration\\IOutput' => __DIR__ . '/../../..' . '/lib/public/Migration/IOutput.php',
|
'OCP\\Migration\\IOutput' => __DIR__ . '/../../..' . '/lib/public/Migration/IOutput.php',
|
||||||
'OCP\\Migration\\IRepairStep' => __DIR__ . '/../../..' . '/lib/public/Migration/IRepairStep.php',
|
'OCP\\Migration\\IRepairStep' => __DIR__ . '/../../..' . '/lib/public/Migration/IRepairStep.php',
|
||||||
|
@ -668,7 +669,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
||||||
'OC\\Log\\Rotate' => __DIR__ . '/../../..' . '/lib/private/Log/Rotate.php',
|
'OC\\Log\\Rotate' => __DIR__ . '/../../..' . '/lib/private/Log/Rotate.php',
|
||||||
'OC\\Log\\Syslog' => __DIR__ . '/../../..' . '/lib/private/Log/Syslog.php',
|
'OC\\Log\\Syslog' => __DIR__ . '/../../..' . '/lib/private/Log/Syslog.php',
|
||||||
'OC\\Mail\\EMailTemplate' => __DIR__ . '/../../..' . '/lib/private/Mail/EMailTemplate.php',
|
'OC\\Mail\\EMailTemplate' => __DIR__ . '/../../..' . '/lib/private/Mail/EMailTemplate.php',
|
||||||
'OC\\Mail\\IEMailTemplate' => __DIR__ . '/../../..' . '/lib/private/Mail/IEMailTemplate.php',
|
|
||||||
'OC\\Mail\\Mailer' => __DIR__ . '/../../..' . '/lib/private/Mail/Mailer.php',
|
'OC\\Mail\\Mailer' => __DIR__ . '/../../..' . '/lib/private/Mail/Mailer.php',
|
||||||
'OC\\Mail\\Message' => __DIR__ . '/../../..' . '/lib/private/Mail/Message.php',
|
'OC\\Mail\\Message' => __DIR__ . '/../../..' . '/lib/private/Mail/Message.php',
|
||||||
'OC\\Memcache\\APCu' => __DIR__ . '/../../..' . '/lib/private/Memcache/APCu.php',
|
'OC\\Memcache\\APCu' => __DIR__ . '/../../..' . '/lib/private/Memcache/APCu.php',
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace OC\Mail;
|
||||||
use OCP\Defaults;
|
use OCP\Defaults;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
|
use OCP\Mail\IEMailTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class EMailTemplate
|
* Class EMailTemplate
|
||||||
|
|
|
@ -24,6 +24,8 @@ namespace OC\Mail;
|
||||||
|
|
||||||
use OCP\Defaults;
|
use OCP\Defaults;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
use OCP\IL10N;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
use OCP\Mail\IMailer;
|
use OCP\Mail\IMailer;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
|
|
||||||
|
@ -54,18 +56,28 @@ class Mailer implements IMailer {
|
||||||
private $logger;
|
private $logger;
|
||||||
/** @var Defaults */
|
/** @var Defaults */
|
||||||
private $defaults;
|
private $defaults;
|
||||||
|
/** @var IURLGenerator */
|
||||||
|
private $urlGenerator;
|
||||||
|
/** @var IL10N */
|
||||||
|
private $l10n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param IConfig $config
|
* @param IConfig $config
|
||||||
* @param ILogger $logger
|
* @param ILogger $logger
|
||||||
* @param Defaults $defaults
|
* @param Defaults $defaults
|
||||||
|
* @param IURLGenerator $urlGenerator
|
||||||
|
* @param IL10N $l10n
|
||||||
*/
|
*/
|
||||||
function __construct(IConfig $config,
|
public function __construct(IConfig $config,
|
||||||
ILogger $logger,
|
ILogger $logger,
|
||||||
Defaults $defaults) {
|
Defaults $defaults,
|
||||||
|
IURLGenerator $urlGenerator,
|
||||||
|
IL10N $l10n) {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->defaults = $defaults;
|
$this->defaults = $defaults;
|
||||||
|
$this->urlGenerator = $urlGenerator;
|
||||||
|
$this->l10n = $l10n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,6 +89,14 @@ class Mailer implements IMailer {
|
||||||
return new Message(new \Swift_Message());
|
return new Message(new \Swift_Message());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createEMailTemplate() {
|
||||||
|
return new EMailTemplate(
|
||||||
|
$this->defaults,
|
||||||
|
$this->urlGenerator,
|
||||||
|
$this->l10n
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the specified message. Also sets the from address to the value defined in config.php
|
* Send the specified message. Also sets the from address to the value defined in config.php
|
||||||
* if no-one has been passed.
|
* if no-one has been passed.
|
||||||
|
|
|
@ -727,7 +727,9 @@ class Server extends ServerContainer implements IServerContainer {
|
||||||
return new Mailer(
|
return new Mailer(
|
||||||
$c->getConfig(),
|
$c->getConfig(),
|
||||||
$c->getLogger(),
|
$c->getLogger(),
|
||||||
$c->query(Defaults::class)
|
$c->query(Defaults::class),
|
||||||
|
$c->getURLGenerator(),
|
||||||
|
$c->getL10N('lib')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
|
$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
|
||||||
|
|
|
@ -21,9 +21,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace OC\Mail;
|
namespace OCP\Mail;
|
||||||
|
|
||||||
use OCP\Defaults;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface IEMailTemplate
|
* Interface IEMailTemplate
|
||||||
|
@ -49,19 +47,14 @@ use OCP\Defaults;
|
||||||
*
|
*
|
||||||
* $htmlContent = $emailTemplate->renderHTML();
|
* $htmlContent = $emailTemplate->renderHTML();
|
||||||
* $plainContent = $emailTemplate->renderText();
|
* $plainContent = $emailTemplate->renderText();
|
||||||
|
*
|
||||||
|
* @since 12.0.0
|
||||||
*/
|
*/
|
||||||
interface IEMailTemplate {
|
interface IEMailTemplate {
|
||||||
/**
|
|
||||||
* @param Defaults $themingDefaults
|
|
||||||
* @param \OCP\IURLGenerator $urlGenerator
|
|
||||||
* @param \OCP\IL10N $l10n
|
|
||||||
*/
|
|
||||||
public function __construct(Defaults $themingDefaults,
|
|
||||||
\OCP\IURLGenerator $urlGenerator,
|
|
||||||
\OCP\IL10N $l10n);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a header to the email
|
* Adds a header to the email
|
||||||
|
*
|
||||||
|
* @since 12.0.0
|
||||||
*/
|
*/
|
||||||
public function addHeader();
|
public function addHeader();
|
||||||
|
|
||||||
|
@ -69,6 +62,8 @@ interface IEMailTemplate {
|
||||||
* Adds a heading to the email
|
* Adds a heading to the email
|
||||||
*
|
*
|
||||||
* @param string $title
|
* @param string $title
|
||||||
|
*
|
||||||
|
* @since 12.0.0
|
||||||
*/
|
*/
|
||||||
public function addHeading($title);
|
public function addHeading($title);
|
||||||
|
|
||||||
|
@ -76,6 +71,8 @@ interface IEMailTemplate {
|
||||||
* Adds a paragraph to the body of the email
|
* Adds a paragraph to the body of the email
|
||||||
*
|
*
|
||||||
* @param string $text
|
* @param string $text
|
||||||
|
*
|
||||||
|
* @since 12.0.0
|
||||||
*/
|
*/
|
||||||
public function addBodyText($text);
|
public function addBodyText($text);
|
||||||
|
|
||||||
|
@ -86,6 +83,8 @@ interface IEMailTemplate {
|
||||||
* @param string $urlLeft URL of left button
|
* @param string $urlLeft URL of left button
|
||||||
* @param string $textRight Text of right button
|
* @param string $textRight Text of right button
|
||||||
* @param string $urlRight URL of right button
|
* @param string $urlRight URL of right button
|
||||||
|
*
|
||||||
|
* @since 12.0.0
|
||||||
*/
|
*/
|
||||||
public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight);
|
public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight);
|
||||||
|
|
||||||
|
@ -93,6 +92,8 @@ 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
|
* 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
|
* @param string $text
|
||||||
|
*
|
||||||
|
* @since 12.0.0
|
||||||
*/
|
*/
|
||||||
public function addFooter($text = '');
|
public function addFooter($text = '');
|
||||||
|
|
||||||
|
@ -100,6 +101,8 @@ interface IEMailTemplate {
|
||||||
* Returns the rendered HTML email as string
|
* Returns the rendered HTML email as string
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 12.0.0
|
||||||
*/
|
*/
|
||||||
public function renderHTML();
|
public function renderHTML();
|
||||||
|
|
||||||
|
@ -107,6 +110,8 @@ interface IEMailTemplate {
|
||||||
* Returns the rendered plain text email as string
|
* Returns the rendered plain text email as string
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 12.0.0
|
||||||
*/
|
*/
|
||||||
public function renderText();
|
public function renderText();
|
||||||
}
|
}
|
|
@ -54,6 +54,14 @@ interface IMailer {
|
||||||
*/
|
*/
|
||||||
public function createMessage();
|
public function createMessage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new email template object
|
||||||
|
*
|
||||||
|
* @return IEMailTemplate
|
||||||
|
* @since 12.0.0
|
||||||
|
*/
|
||||||
|
public function createEMailTemplate();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the specified message. Also sets the from address to the value defined in config.php
|
* Send the specified message. Also sets the from address to the value defined in config.php
|
||||||
* if no-one has been passed.
|
* if no-one has been passed.
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
namespace OC\Settings\Mailer;
|
namespace OC\Settings\Mailer;
|
||||||
|
|
||||||
use OC\Mail\EMailTemplate;
|
use OC\Mail\EMailTemplate;
|
||||||
use OC\Mail\IEMailTemplate;
|
use OCP\Mail\IEMailTemplate;
|
||||||
use OCP\AppFramework\Utility\ITimeFactory;
|
use OCP\AppFramework\Utility\ITimeFactory;
|
||||||
use OCP\Defaults;
|
use OCP\Defaults;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
namespace Tests\Settings\Mailer;
|
namespace Tests\Settings\Mailer;
|
||||||
|
|
||||||
use OC\Mail\IEMailTemplate;
|
use OCP\Mail\IEMailTemplate;
|
||||||
use OC\Mail\Message;
|
use OC\Mail\Message;
|
||||||
use OC\Settings\Mailer\NewUserMailHelper;
|
use OC\Settings\Mailer\NewUserMailHelper;
|
||||||
use OCP\AppFramework\Utility\ITimeFactory;
|
use OCP\AppFramework\Utility\ITimeFactory;
|
||||||
|
|
|
@ -8,32 +8,44 @@
|
||||||
|
|
||||||
namespace Test\Mail;
|
namespace Test\Mail;
|
||||||
|
|
||||||
|
use OC\Mail\EMailTemplate;
|
||||||
use OC\Mail\Mailer;
|
use OC\Mail\Mailer;
|
||||||
use OCP\Defaults;
|
use OCP\Defaults;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
use OCP\IL10N;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class MailerTest extends TestCase {
|
class MailerTest extends TestCase {
|
||||||
/** @var IConfig */
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $config;
|
private $config;
|
||||||
/** @var Defaults */
|
/** @var Defaults|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $defaults;
|
private $defaults;
|
||||||
/** @var ILogger */
|
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $logger;
|
private $logger;
|
||||||
|
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $urlGenerator;
|
||||||
|
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $l10n;
|
||||||
/** @var Mailer */
|
/** @var Mailer */
|
||||||
private $mailer;
|
private $mailer;
|
||||||
|
|
||||||
function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->config = $this->getMockBuilder('\OCP\IConfig')
|
$this->config = $this->createMock(IConfig::class);
|
||||||
->disableOriginalConstructor()->getMock();
|
$this->defaults = $this->createMock(Defaults::class);
|
||||||
$this->defaults = $this->getMockBuilder('\OCP\Defaults')
|
$this->logger = $this->createMock(ILogger::class);
|
||||||
->disableOriginalConstructor()->getMock();
|
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||||
$this->logger = $this->getMockBuilder('\OCP\ILogger')
|
$this->l10n = $this->createMock(IL10N::class);
|
||||||
->disableOriginalConstructor()->getMock();
|
$this->mailer = new Mailer(
|
||||||
$this->mailer = new Mailer($this->config, $this->logger, $this->defaults);
|
$this->config,
|
||||||
|
$this->logger,
|
||||||
|
$this->defaults,
|
||||||
|
$this->urlGenerator,
|
||||||
|
$this->l10n
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetMailInstance() {
|
public function testGetMailInstance() {
|
||||||
|
@ -120,4 +132,7 @@ class MailerTest extends TestCase {
|
||||||
$this->assertSame($expected, $this->mailer->validateMailAddress($email));
|
$this->assertSame($expected, $this->mailer->validateMailAddress($email));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCreateEMailTemplate() {
|
||||||
|
$this->assertSame(EMailTemplate::class, get_class($this->mailer->createEMailTemplate()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue