You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.7 KiB

[REF] auth_signup_verify_email: Skip mail send in tests and use email_validator (#1247) This addon introduced an integration conflict when tested in a database that had `mail_tracking_mass_mailing` installed, producing this failure: Traceback (most recent call last): File "/opt/odoo/auto/addons/auth_signup_verify_email/controllers/main.py", line 44, in passwordless_signup sudo_users.reset_password(values.get("login")) File "/usr/lib/python2.7/contextlib.py", line 24, in __exit__ self.gen.next() File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 419, in savepoint self.execute('RELEASE SAVEPOINT "%s"' % name) File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 154, in wrapper return f(self, *args, **kwargs) File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 231, in execute res = self._obj.execute(query, params) InternalError: no such savepoint Which in turn produced the following in the next test: InternalError: current transaction is aborted, commands ignored until end of transaction block The problem comes from the fact that one cannot rollback to a nested savepoint if the parent savepoint was released. It became a problem because that's the strategy that both this addon and upstream's `TestCursor` follow. To avoid that, tests now mock the `send_mail` method. This results also in having a predictable outcome from the test `test_good_email`, so it is more meaningful now. Besides, previously we were using the `validate_email` package, which is currently a dead project that can silently fail under certain environments, as seen in https://github.com/syrusakbary/validate_email/pull/80. There's the `email_validator` package, freely available, supported, and it provides a human-readable error message whenever some format from the email fails. As such, here I'm switching the dependency, while still adding a backwards compatibility layer for preexisting installations.
7 years ago
[REF] auth_signup_verify_email: Skip mail send in tests and use email_validator (#1247) This addon introduced an integration conflict when tested in a database that had `mail_tracking_mass_mailing` installed, producing this failure: Traceback (most recent call last): File "/opt/odoo/auto/addons/auth_signup_verify_email/controllers/main.py", line 44, in passwordless_signup sudo_users.reset_password(values.get("login")) File "/usr/lib/python2.7/contextlib.py", line 24, in __exit__ self.gen.next() File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 419, in savepoint self.execute('RELEASE SAVEPOINT "%s"' % name) File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 154, in wrapper return f(self, *args, **kwargs) File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 231, in execute res = self._obj.execute(query, params) InternalError: no such savepoint Which in turn produced the following in the next test: InternalError: current transaction is aborted, commands ignored until end of transaction block The problem comes from the fact that one cannot rollback to a nested savepoint if the parent savepoint was released. It became a problem because that's the strategy that both this addon and upstream's `TestCursor` follow. To avoid that, tests now mock the `send_mail` method. This results also in having a predictable outcome from the test `test_good_email`, so it is more meaningful now. Besides, previously we were using the `validate_email` package, which is currently a dead project that can silently fail under certain environments, as seen in https://github.com/syrusakbary/validate_email/pull/80. There's the `email_validator` package, freely available, supported, and it provides a human-readable error message whenever some format from the email fails. As such, here I'm switching the dependency, while still adding a backwards compatibility layer for preexisting installations.
7 years ago
[REF] auth_signup_verify_email: Skip mail send in tests and use email_validator (#1247) This addon introduced an integration conflict when tested in a database that had `mail_tracking_mass_mailing` installed, producing this failure: Traceback (most recent call last): File "/opt/odoo/auto/addons/auth_signup_verify_email/controllers/main.py", line 44, in passwordless_signup sudo_users.reset_password(values.get("login")) File "/usr/lib/python2.7/contextlib.py", line 24, in __exit__ self.gen.next() File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 419, in savepoint self.execute('RELEASE SAVEPOINT "%s"' % name) File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 154, in wrapper return f(self, *args, **kwargs) File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 231, in execute res = self._obj.execute(query, params) InternalError: no such savepoint Which in turn produced the following in the next test: InternalError: current transaction is aborted, commands ignored until end of transaction block The problem comes from the fact that one cannot rollback to a nested savepoint if the parent savepoint was released. It became a problem because that's the strategy that both this addon and upstream's `TestCursor` follow. To avoid that, tests now mock the `send_mail` method. This results also in having a predictable outcome from the test `test_good_email`, so it is more meaningful now. Besides, previously we were using the `validate_email` package, which is currently a dead project that can silently fail under certain environments, as seen in https://github.com/syrusakbary/validate_email/pull/80. There's the `email_validator` package, freely available, supported, and it provides a human-readable error message whenever some format from the email fails. As such, here I'm switching the dependency, while still adding a backwards compatibility layer for preexisting installations.
7 years ago
[REF] auth_signup_verify_email: Skip mail send in tests and use email_validator (#1247) This addon introduced an integration conflict when tested in a database that had `mail_tracking_mass_mailing` installed, producing this failure: Traceback (most recent call last): File "/opt/odoo/auto/addons/auth_signup_verify_email/controllers/main.py", line 44, in passwordless_signup sudo_users.reset_password(values.get("login")) File "/usr/lib/python2.7/contextlib.py", line 24, in __exit__ self.gen.next() File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 419, in savepoint self.execute('RELEASE SAVEPOINT "%s"' % name) File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 154, in wrapper return f(self, *args, **kwargs) File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 231, in execute res = self._obj.execute(query, params) InternalError: no such savepoint Which in turn produced the following in the next test: InternalError: current transaction is aborted, commands ignored until end of transaction block The problem comes from the fact that one cannot rollback to a nested savepoint if the parent savepoint was released. It became a problem because that's the strategy that both this addon and upstream's `TestCursor` follow. To avoid that, tests now mock the `send_mail` method. This results also in having a predictable outcome from the test `test_good_email`, so it is more meaningful now. Besides, previously we were using the `validate_email` package, which is currently a dead project that can silently fail under certain environments, as seen in https://github.com/syrusakbary/validate_email/pull/80. There's the `email_validator` package, freely available, supported, and it provides a human-readable error message whenever some format from the email fails. As such, here I'm switching the dependency, while still adding a backwards compatibility layer for preexisting installations.
7 years ago
  1. # -*- coding: utf-8 -*-
  2. # © 2015 Antiun Ingeniería, S.L.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import logging
  5. from odoo import _, http
  6. from odoo.addons.auth_signup.controllers.main import AuthSignupHome
  7. _logger = logging.getLogger(__name__)
  8. try:
  9. from email_validator import validate_email, EmailSyntaxError
  10. except ImportError:
  11. # TODO Remove in v12, dropping backwards compatibility with validate_email
  12. # pragma: no-cover
  13. try:
  14. from validate_email import validate_email as _validate
  15. class EmailSyntaxError(Exception):
  16. message = False
  17. def validate_email(*args, **kwargs):
  18. if not _validate(*args, **kwargs):
  19. raise EmailSyntaxError
  20. except ImportError:
  21. _logger.debug("Cannot import `email_validator`.")
  22. else:
  23. _logger.warning("Install `email_validator` to get full support.")
  24. class SignupVerifyEmail(AuthSignupHome):
  25. @http.route()
  26. def web_auth_signup(self, *args, **kw):
  27. if (http.request.params.get("login") and
  28. not http.request.params.get("password")):
  29. return self.passwordless_signup(http.request.params)
  30. else:
  31. return super(SignupVerifyEmail, self).web_auth_signup(*args, **kw)
  32. def passwordless_signup(self, values):
  33. qcontext = self.get_auth_signup_qcontext()
  34. # Check good format of e-mail
  35. try:
  36. validate_email(values.get("login", ""))
  37. except EmailSyntaxError as error:
  38. qcontext["error"] = getattr(
  39. error,
  40. "message",
  41. _("That does not seem to be an email address."),
  42. )
  43. return http.request.render("auth_signup.signup", qcontext)
  44. if not values.get("email"):
  45. values["email"] = values.get("login")
  46. # Remove password
  47. values["password"] = ""
  48. sudo_users = (http.request.env["res.users"]
  49. .with_context(create_user=True).sudo())
  50. try:
  51. with http.request.cr.savepoint():
  52. sudo_users.signup(values, qcontext.get("token"))
  53. sudo_users.reset_password(values.get("login"))
  54. except Exception as error:
  55. # Duplicate key or wrong SMTP settings, probably
  56. _logger.exception(error)
  57. # Agnostic message for security
  58. qcontext["error"] = _(
  59. "Something went wrong, please try again later or contact us.")
  60. return http.request.render("auth_signup.signup", qcontext)
  61. qcontext["message"] = _("Check your email to activate your account!")
  62. return http.request.render("auth_signup.reset_password", qcontext)