New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configurable mailer #1052
Add configurable mailer #1052
Conversation
public function __construct(RouterInterface $router, EngineInterface $templating, \Swift_Mailer $mailer, string $fromEmail, string $emailTemplate) | ||
{ | ||
$this->router = $router; | ||
$this->templating = $templating; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the same order for the const arguments and the member vars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I got it. It should be fixed now?
public function setUp(): void | ||
{ | ||
$this->router = $this->createMock(RouterInterface::class); | ||
$this->templating = $this->createMock(EngineInterface::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the order is correct 🤗👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocked by #1053
Could you please rebase your PR and fix merge conflicts? |
This PR has been updated to reflect changes introduced by #1053. We are now using an alias in the DI to point to the configurable mailer. |
docs/reference/installation.rst
Outdated
Mailer Configuration | ||
~~~~~~~~~~~~~~~~~~~~ | ||
|
||
You can define a custom mailer to send reset password emails. Your mailer will have to implement ``FOS\UserBundle\Mailer\MailerInterface``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please comply with the sf docs standards:
@@ -115,6 +116,7 @@ public function getConfigTreeBuilder() | |||
->scalarNode('default_avatar')->defaultValue('bundles/sonatauser/default_avatar.png')->end() | |||
->end() | |||
->end() | |||
->scalarNode('mailer')->defaultValue(Mailer::class)->end() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a call to info
documenting what this is
src/Mailer/Mailer.php
Outdated
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Symfony\Component\Routing\RouterInterface; | ||
|
||
class Mailer implements MailerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
?
src/Mailer/Mailer.php
Outdated
/** | ||
* @var RouterInterface | ||
*/ | ||
protected $router; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use private
as much as possible
src/Mailer/Mailer.php
Outdated
class Mailer implements MailerInterface | ||
{ | ||
/** | ||
* @var RouterInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refactor this to UrlGeneratorInterface
, since you are not matching any urls.
@@ -226,6 +226,28 @@ public function testConfigureGoogleAuthenticatorEnabled(): void | |||
$this->assertContainerBuilderHasServiceDefinitionWithArgument('sonata.user.google.authenticator.provider', 0, 'bar'); | |||
} | |||
|
|||
/** | |||
* @group legacy | |||
* @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is weird that you need to do this 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it also seems weird to me, but this deprecation is risen everytime the load
method is used :/
tests/Mailer/MailerTest.php
Outdated
/** | ||
* @var RouterInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $router; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private
by default please http://fabien.potencier.org/pragmatism-over-theory-protected-vs-private.html
I don't know how much this is already uses FOS stuff, but would it make sense to use the FOSUserEvents for password reset too? and should that be part of your actions or your new mailer? |
@Hanmac we discussed this in #1053 and agreed to use FOS events :) We decided to postpone the implementation to another PR to be able to close the mailer subject before. I already have some wip on the FOS event implementation but I'm waiting for the completion of the mailer subject before pushing it as a PR. |
@Wharenn oh we already did? then it is okay. i was just wondering where the events should be, in the mailer or in the actions? |
IMO in the actions as they can also be used to hook userland behaviors on every action workflow. This is the way they are implemented in FOSUserBundle. I think the incoming PR will go deeper about the subject. |
Hi @sonata-project/contributors can we move forward on this PR? |
public function configureTranslationDomain($config, ContainerBuilder $container): void | ||
{ | ||
$container->setParameter('sonata.user.admin.user.translation_domain', $config['admin']['user']['translation']); | ||
$container->setParameter('sonata.user.admin.group.translation_domain', $config['admin']['group']['translation']); | ||
} | ||
|
||
/** | ||
* @param array $config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you removed this but didn't add the typehint in the signature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good
4a822bd
*/ | ||
public function fixImpersonating(array $config) | ||
public function fixImpersonating(array $config): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BC break
* @return mixed | ||
*/ | ||
public function configureGoogleAuthenticator($config, ContainerBuilder $container) | ||
public function configureGoogleAuthenticator(array $config, ContainerBuilder $container): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BC break
* @param ContainerBuilder $container | ||
*/ | ||
public function configureClass($config, ContainerBuilder $container): void | ||
public function configureClass(array $config, ContainerBuilder $container): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BC break
* @param ContainerBuilder $container | ||
*/ | ||
public function configureAdminClass($config, ContainerBuilder $container): void | ||
public function configureAdminClass(array $config, ContainerBuilder $container): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BC break
* @param ContainerBuilder $container | ||
*/ | ||
public function configureTranslationDomain($config, ContainerBuilder $container): void | ||
public function configureTranslationDomain(array $config, ContainerBuilder $container): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BC break
* @param ContainerBuilder $container | ||
*/ | ||
public function configureController($config, ContainerBuilder $container): void | ||
public function configureController(array $config, ContainerBuilder $container): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BC break
/** | ||
* @param array $config | ||
*/ | ||
public function configureMailer(array $config, ContainerBuilder $container): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this private
*/ | ||
protected function aliasManagers(ContainerBuilder $container, $managerType): void | ||
protected function aliasManagers(ContainerBuilder $container, string $managerType): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BC break
@core23 fixed BCs |
|
||
private function configureMailer(array $config, ContainerBuilder $container): void | ||
{ | ||
$container->setAlias('sonata.user.mailer', $config['mailer']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bonuspoint: Make an alias for the MailerInterface
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are implementing the FOS MailerInterface, this would lead to expose to autowiring the FOS MailerInterface from this bundle. Is this really what we want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right. Just ignore it 😅
Thanks @Wharenn ! |
I am targeting this branch, because this is a new feature with no breaking change.
Changelog
Subject
By default, SonataUserBundle is using the
mailer
service to send the account password reset email and keep the email building logic in a controller private method. It makes it hard to use a custom implementation like using another mailer than the default one or updating the email creation process.This PR adds a
Mailer
class implementing the FOSMailerInterface
and doing the same things theAdminResettingController
class was. This default class can be replaced by any other user service implementing theMailerInterface
by setting corresponding service id uner themailer
config key: