From 086dcefbc89b631f369acdaca72314c84af58c85 Mon Sep 17 00:00:00 2001 From: niyasraphy Date: Fri, 26 May 2023 16:37:06 +0000 Subject: [PATCH] [FIX] google_gmail, microsoft_outlook : move UserError to ir_mail_server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: fcfd72a5e5663fa6b08c80a8a22ec15c8a09456f Original author: niyasraphy Conflict resolution for saas-15.2, 16.0, saas-16.2, saas-16.3 closes odoo/odoo#123660 X-original-commit: b0749e430847d2f49e07b119915e8dee0c4e7f00 Signed-off-by: Stéphane Debauche (std) --- addons/google_gmail/i18n/google_gmail.pot | 2 +- addons/google_gmail/models/google_gmail_mixin.py | 5 ----- addons/google_gmail/models/ir_mail_server.py | 5 +++++ addons/microsoft_outlook/i18n/microsoft_outlook.pot | 2 +- addons/microsoft_outlook/models/ir_mail_server.py | 5 +++++ addons/microsoft_outlook/models/microsoft_outlook_mixin.py | 5 ----- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/addons/google_gmail/i18n/google_gmail.pot b/addons/google_gmail/i18n/google_gmail.pot index 499839f7a51..e56ed4cc2bc 100644 --- a/addons/google_gmail/i18n/google_gmail.pot +++ b/addons/google_gmail/i18n/google_gmail.pot @@ -175,7 +175,7 @@ msgstr "" #. module: google_gmail #. odoo-python -#: code:addons/google_gmail/models/google_gmail_mixin.py:0 +#: code:addons/google_gmail/models/ir_mail_server.py:0 #, python-format msgid "" "Please fill the \"Username\" field with your Gmail username (your email " diff --git a/addons/google_gmail/models/google_gmail_mixin.py b/addons/google_gmail/models/google_gmail_mixin.py index e97f6055a8d..1a41e915bf4 100644 --- a/addons/google_gmail/models/google_gmail_mixin.py +++ b/addons/google_gmail/models/google_gmail_mixin.py @@ -71,11 +71,6 @@ class GoogleGmailMixin(models.AbstractModel): if not self.google_gmail_uri: 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 { 'type': 'ir.actions.act_url', 'url': self.google_gmail_uri, diff --git a/addons/google_gmail/models/ir_mail_server.py b/addons/google_gmail/models/ir_mail_server.py index eca7f4ff492..b82f9666352 100644 --- a/addons/google_gmail/models/ir_mail_server.py +++ b/addons/google_gmail/models/ir_mail_server.py @@ -64,6 +64,11 @@ class IrMailServer(models.Model): 'Incorrect Connection Security for Gmail mail server %r. ' '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): if len(self) == 1 and self.smtp_authentication == 'gmail': auth_string = self._generate_oauth2_string(smtp_user, self.google_gmail_refresh_token) diff --git a/addons/microsoft_outlook/i18n/microsoft_outlook.pot b/addons/microsoft_outlook/i18n/microsoft_outlook.pot index e31f3afc457..9a4e5fa643b 100644 --- a/addons/microsoft_outlook/i18n/microsoft_outlook.pot +++ b/addons/microsoft_outlook/i18n/microsoft_outlook.pot @@ -193,7 +193,7 @@ msgstr "" #. module: microsoft_outlook #. odoo-python -#: code:addons/microsoft_outlook/models/microsoft_outlook_mixin.py:0 +#: code:addons/microsoft_outlook/models/ir_mail_server.py:0 #, python-format msgid "" "Please fill the \"Username\" field with your Outlook/Office365 username " diff --git a/addons/microsoft_outlook/models/ir_mail_server.py b/addons/microsoft_outlook/models/ir_mail_server.py index f28f7fbd08a..14515b8abc6 100644 --- a/addons/microsoft_outlook/models/ir_mail_server.py +++ b/addons/microsoft_outlook/models/ir_mail_server.py @@ -52,6 +52,11 @@ class IrMailServer(models.Model): '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)) + 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') def _onchange_encryption(self): """Do not change the SMTP configuration if it's a Outlook server diff --git a/addons/microsoft_outlook/models/microsoft_outlook_mixin.py b/addons/microsoft_outlook/models/microsoft_outlook_mixin.py index 2fd3220ab9c..7fe4d9c2d66 100644 --- a/addons/microsoft_outlook/models/microsoft_outlook_mixin.py +++ b/addons/microsoft_outlook/models/microsoft_outlook_mixin.py @@ -79,11 +79,6 @@ class MicrosoftOutlookMixin(models.AbstractModel): if not self.is_microsoft_outlook_configured: 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 { 'type': 'ir.actions.act_url', 'url': self.microsoft_outlook_uri,