Skip to content
Snippets Groups Projects
Commit 68b76c2f authored by jorv's avatar jorv
Browse files

[FIX] google_gmail, microsoft_outlook : move UserError to ir_mail_server

The orginal PR and it's forward ports https://github.com/odoo/odoo/pull/121048


intorduced an unexpected AttributeError when using OAuth for incoming
mail servers (fetchmail.server). Since `smtp_user` is not a defined field
in fetchmail.server (it uses the field `user` instead), we had to change
the approach.

To prevent this error, we move the UserError call into the respective
ir_mail_server models, which should check the contrains at that level.
This means that before the form gets saved, trying to connect using an
OAuth account, should prompt the user to first specify an smtp_user before
proceeding.

X-original-commit: fcfd72a5
Original author: niyasraphy <niyasraphyk@gmail.com>
Conflict resolution for saas-15.2, 16.0

closes odoo/odoo#122613

X-original-commit: 3de5e2a1a0238b3edc5537aa5e3842ad5430a186
Signed-off-by: default avatarStéphane Debauche (std) <std@odoo.com>
parent 98cda20c
No related branches found
No related tags found
No related merge requests found
...@@ -167,7 +167,7 @@ msgid "Please configure your Gmail credentials." ...@@ -167,7 +167,7 @@ msgid "Please configure your Gmail credentials."
msgstr "" msgstr ""
#. module: google_gmail #. module: google_gmail
#: code:addons/google_gmail/models/google_gmail_mixin.py:0 #: code:addons/google_gmail/models/ir_mail_server.py:0
#, python-format #, python-format
msgid "" msgid ""
"Please fill the \"Username\" field with your Gmail username (your email " "Please fill the \"Username\" field with your Gmail username (your email "
......
...@@ -71,11 +71,6 @@ class GoogleGmailMixin(models.AbstractModel): ...@@ -71,11 +71,6 @@ class GoogleGmailMixin(models.AbstractModel):
if not self.google_gmail_uri: if not self.google_gmail_uri:
raise UserError(_('Please configure your Gmail credentials.')) raise UserError(_('Please configure your Gmail credentials.'))
if not self.smtp_user:
raise UserError(_(
'Please fill the "Username" field with your Gmail username (your email address). '
'This should be the same account as the one used for the Gmail OAuthentication Token.'))
return { return {
'type': 'ir.actions.act_url', 'type': 'ir.actions.act_url',
'url': self.google_gmail_uri, 'url': self.google_gmail_uri,
......
...@@ -64,6 +64,11 @@ class IrMailServer(models.Model): ...@@ -64,6 +64,11 @@ class IrMailServer(models.Model):
'Incorrect Connection Security for Gmail mail server %r. ' 'Incorrect Connection Security for Gmail mail server %r. '
'Please set it to "TLS (STARTTLS)".', server.name)) 'Please set it to "TLS (STARTTLS)".', server.name))
if not server.smtp_user:
raise UserError(_(
'Please fill the "Username" field with your Gmail username (your email address). '
'This should be the same account as the one used for the Gmail OAuthentication Token.'))
def _smtp_login(self, connection, smtp_user, smtp_password): def _smtp_login(self, connection, smtp_user, smtp_password):
if len(self) == 1 and self.smtp_authentication == 'gmail': if len(self) == 1 and self.smtp_authentication == 'gmail':
auth_string = self._generate_oauth2_string(smtp_user, self.google_gmail_refresh_token) auth_string = self._generate_oauth2_string(smtp_user, self.google_gmail_refresh_token)
......
...@@ -193,7 +193,7 @@ msgstr "" ...@@ -193,7 +193,7 @@ msgstr ""
#. module: microsoft_outlook #. module: microsoft_outlook
#. odoo-python #. odoo-python
#: code:addons/microsoft_outlook/models/microsoft_outlook_mixin.py:0 #: code:addons/microsoft_outlook/models/ir_mail_server.py:0
#, python-format #, python-format
msgid "" msgid ""
"Please fill the \"Username\" field with your Outlook/Office365 username " "Please fill the \"Username\" field with your Outlook/Office365 username "
......
...@@ -52,6 +52,11 @@ class IrMailServer(models.Model): ...@@ -52,6 +52,11 @@ class IrMailServer(models.Model):
'This server %r can only be used for your personal email address. ' 'This server %r can only be used for your personal email address. '
'Please fill the "from_filter" field with %r.', server.name, server.smtp_user)) 'Please fill the "from_filter" field with %r.', server.name, server.smtp_user))
if not server.smtp_user:
raise UserError(_(
'Please fill the "Username" field with your Outlook/Office365 username (your email address). '
'This should be the same account as the one used for the Outlook OAuthentication Token.'))
@api.onchange('smtp_encryption') @api.onchange('smtp_encryption')
def _onchange_encryption(self): def _onchange_encryption(self):
"""Do not change the SMTP configuration if it's a Outlook server """Do not change the SMTP configuration if it's a Outlook server
......
...@@ -79,11 +79,6 @@ class MicrosoftOutlookMixin(models.AbstractModel): ...@@ -79,11 +79,6 @@ class MicrosoftOutlookMixin(models.AbstractModel):
if not self.is_microsoft_outlook_configured: if not self.is_microsoft_outlook_configured:
raise UserError(_('Please configure your Outlook credentials.')) raise UserError(_('Please configure your Outlook credentials.'))
if not self.smtp_user:
raise UserError(_(
'Please fill the "Username" field with your Outlook/Office365 username (your email address). '
'This should be the same account as the one used for the Outlook OAuthentication Token.'))
return { return {
'type': 'ir.actions.act_url', 'type': 'ir.actions.act_url',
'url': self.microsoft_outlook_uri, 'url': self.microsoft_outlook_uri,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment