-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Notifier] Change notifier recipient handling #35773
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
Conversation
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 great!
I think we should mention the changed things (the added methods + interfaces and the removed AdminRecipient
class) in the UPGRADE guide. Experimental means we are allowed to break stuff, but we the breaks have to be documented afaik.
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.
Did you check the current bridge implementations if there are some changes needed?
Yes I checked the bridges too. All should be good there. |
a768a56
to
76d5a45
Compare
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.
Having hasEmail()
and hasPhone()
methods does not look right to me. I'd prefer dedicated classes that only implement EmailRecipientInterface
and/or SmsRecipientInterface
when the required data is actually present.
21bbb8d
to
72cb155
Compare
According to @xabbuh comment
I gave it a try and introduced I also made sure that the different Recipient objects are always in a valid state to be able to remove the check for a non empty email and phone in the Some tests were added as well: f45f246 I think this solution could be the way to go. WDYT? P.S.: No idea why the AppVeyor build is failing. |
5dfc57b
to
fd0b2d5
Compare
src/Symfony/Component/Notifier/Recipient/EmailValidationTrait.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Recipient/PhoneValidationTrait.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Tests/Recipient/RecipientTest.php
Outdated
Show resolved
Hide resolved
f718a5f
to
d66a235
Compare
This PR was merged into the 5.0 branch. Discussion ---------- [Notifier] Add unit tests | Q | A | ------------- | --- | Branch? | 5.0 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | - <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | - <!-- required for new features --> - [x] `AbstractChannel` - [x] `ChannelPolicy` - [x] `RecipientTest` (done in PR #35773) - [x] `EmailRecipientTest` (done in PR #35773) - [x] `SmsRecipientTest` (done in PR #35773) - [x] `Transports` (see PR #35834) Commits ------- 022c170 [Notifier] Add tests for AbstractChannel and ChannelPolicy
77585c7
to
9368554
Compare
src/Symfony/Component/Notifier/Recipient/EmailRecipientTrait.php
Outdated
Show resolved
Hide resolved
|
||
public function __construct(string $email = '') | ||
public function __construct(string $email = '', string $phone = '') |
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.
When setting the phone to an empty string, it will be passed anyway to SMS transports as it implements the interface. Before, we checked for a non-empty phone, which I think must be kept.
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 keeping the non-empty phone check would mean if I forgot to set a phone number even though I would like to send a SmsMessage
, the SmsChannel
would be skipped and I don't get any information why my notification was not sent as sms.
I would suggest a different approach: We could make the creation of SmsMessage
more strict and throw an InvalidArgumentException
with a proper exception message in case the $phone
argument is empty. We could apply the same to EmailMessage
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.
@fabpot WDYT?
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.
Works for me.
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 you forgot to enforce a non-empty phone on SmsMessage (and the same for the other messages), right?
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 no 🙈 thats true. On it.
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: d11567f
7c45d7b
to
ca644f9
Compare
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.
Sorry for the delay.
@@ -4,11 +4,24 @@ CHANGELOG | |||
5.1.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.
5.2
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.
Moved: 1dab3f5
`RecipientInterface`. | ||
* Changed `EmailChannel` to only support recipients which implement the `EmailRecipientInterface`. | ||
* Changed `SmsChannel` to only support recipients which implement the `SmsRecipientInterface`. | ||
* Added the Mattermost notifier bridge. |
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.
not related
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.
Will revert it.
{ | ||
if (empty(trim($email)) && empty(trim($phone))) { |
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 try to avoid empty in Symfony. Also, I would not trim the value.
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.
Adjusted: 1dab3f5
@@ -35,8 +44,13 @@ public function email(string $email): self | |||
return $this; | |||
} | |||
|
|||
public function getEmail(): string | |||
/** | |||
* @return $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.
I would keep the comment that was part of the interface: Sets the phone number (no spaces, international code like in +3312345678).
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.
Comment added: 1dab3f5
|
||
public function __construct(string $email = '') | ||
public function __construct(string $email = '', string $phone = '') |
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.
Works for me.
a31b649
to
1dab3f5
Compare
Hi @fabpot thanks for your review :-) I made the requested changes and rebased the branch on master. fabbot.io is complaining though, but it looks like a false positive again. |
@@ -17,7 +17,8 @@ | |||
], | |||
"require": { | |||
"php": ">=7.2.5", | |||
"symfony/polyfill-php80": "^1.15" | |||
"symfony/polyfill-php80": "^1.15", | |||
"psr/log": "~1.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.
I recognized this was missing, because the EmailMessageTest
failed locally while using the Notification class that depends on psr/log.
@@ -0,0 +1,24 @@ | |||
<?php | |||
|
|||
declare(strict_types=1); |
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.
Should be removed everywhere, we're using that in Symfony.
Thank you @jschaedl. |
d11567f
to
588607b
Compare
This PR is missing corresponding entries in UPGRADE-5.2.md |
@nicolas-grekas here you go: #38691 |
…og (jschaedl) This PR was merged into the 5.x branch. Discussion ---------- [Notifier] Add missing upgrade entries and fixed changelog | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch 5.x. --> Follow-up of #35773 Commits ------- c6b32cd add missing upgrade entries and fixed changelog
According to @wouterj's reasoning in #35558 I did the following to merge the
AdminRecipient
with theRecipient
class:EmailRecipientInterface
withgetEmail(): string
methodsRecipientInterface
that is extended byEmailRecipientInterface
andSmsRecipientInterface
Recipient
class which now holds an email and a phone number property and implements theEmailRecipientInterface
and theSmsRecipientInterface
NoRecipient
class which now implements theRecipientInterface
AdminRecipient
and fixed all related type-hintsEmailRecipient
andSmsRecipient
$recipient
argument inNotifierInterface::send()
,Notifier::getChannels()
,ChannelInterface::notifiy()
andChannelInterface::supports()
toRecipientInterface
$recipient
argument in theas*Message()
of theEmailNotificationInterface
andSmsNotificationInterface
which now uses the introduced interfaces$recipient
argument in the staticfromNotification()
factory methods inEmailMessage
andSmsMessage
which now uses the introduced interfacesEmailChannel
to only support recipients which implement theEmailRecipientInterface
SmsChannel
only supports recipients which implement theSmsRecipientInterface