-
-
Notifications
You must be signed in to change notification settings - Fork 846
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
[13.0][MIG] partner_email_check: Migration to 13.0 #989
[13.0][MIG] partner_email_check: Migration to 13.0 #989
Conversation
* Add new module partner-email-check Validate email input
…en importing validate_email in partner_email_check
- partner_email_check now uses email-validator instead of validate_email - Email addresses are normalized - There is a setting to enforce uniqueness of partner email addresses - There is a setting to check whether emails are deliverable (i.e. whether the domain resolves)
portal's tests set an invalid email address, `c@c`, that's rejected by the current version of partner_email_check. If partner_email_check is installed before portal's tests run then they fail. To solve this, skip email validation if tests are running, unless a key in the context is set to make the checks run anyway. That lets tests in other addons opt in to the checks as well. The previous update to partner_email_check didn't bump the version number, so do that now.
41c0e13
to
4bbf9a7
Compare
117fdd9
to
e40fa9c
Compare
e40fa9c
to
e356c0f
Compare
Not allowed duplicate partner with filled email so maybe need set |
|
||
partner_email_check_filter_duplicates = fields.Boolean( | ||
string="Filter duplicate partner email addresses", | ||
help="Don't allow multiple partners to have the same email address.", |
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.
help="Don't allow multiple partners to have the same email address.", | |
help="Don't allow multiple partners to have the same email address.", | |
config_parameter="partner_email_check_filter_duplicates" |
@qgroulard Could you attend comments? |
Yes I am trying to squeeze this in today's agenda but I'm afraid it will be for another day. |
if self._should_filter_duplicates(): | ||
for copy_vals in res: | ||
if "email" in copy_vals: | ||
copy_vals["email"] = "" |
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.
Why not delete the value from the dictionary, or set it to False, so email will have a NULL value in the database.
3864e32
to
e3dfcc8
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.
👍 LGTM
@simahawk Could you update your review? |
for copy_vals in res: | ||
if "email" in copy_vals: | ||
del copy_vals["email"] |
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 a blocker but you could do:
for copy_vals in res: | |
if "email" in copy_vals: | |
del copy_vals["email"] | |
for copy_vals in res: | |
copy_vals.pop("email", None) |
|
||
@api.model | ||
def email_check(self, emails): | ||
if config["test_enable"] and not self.env.context.get( |
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.
do we really need this? What's the main reason?
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) | ||
# Checks are disabled during tests unless this key is set |
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 don't get why we need this ctx key 🤔
Checks should be disabled by the flags set on the company.
If you want to keep them ON by default you can set them OFF in tests for the rest of the world by adding demo data 😉
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.
This is actually the same comment as #989 (comment) since this key is only used there.
I think I get it now...
There are actually 3 checks performed:
- Check email unique: only if set on company;
- Check deliverability: only if set on company, performed with https://pypi.org/project/email-validator/ thus can't run without checking emails syntax as well;
- Check syntax: currently always performed unless in test mode without this key (test_partner_email_check), performed with https://pypi.org/project/email-validator/
So I guess the idea is not to break other modules' tests since not having this context key set (and being in test mode) is the only way not to check emails syntax.
Maybe the solution would be to add a third flag for the syntax check.
It should be off by default otherwise other modules' test may fail. Thus users must be aware that behavior changes with v13 since beforehand this check used to always be performed.
What do you think ?
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.
nope, the solution is simpler and I reported it above 😉
Just do this:
- add demo data file
- in that file call write function on all companies
- set the flags to false
- in your test class enable the flags
This way for the rest of the test suites (referred as "rest of the world" above) won't be impacted.
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.
of course, the alternative is that you make the flag false by default and you state in the README that it should be enabled
@@ -0,0 +1,24 @@ | |||
# Copyright 2021 ACSONE SA/NV | |||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
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.
Make it https:
[REF] Partner email chack params on company [IMP] email_check [IMP] test partner_email_check use SavepointCase
e3dfcc8
to
1aa74d9
Compare
1aa74d9
to
f42ad2f
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.
thanks for your changes!
/ocabot merge minor |
This PR looks fantastic, let's merge it! |
Congratulations, your PR was merged at 5578b86. Thanks a lot for contributing to OCA. ❤️ |
No description provided.