From 916a94ffbe1b8230920fee79eb573dae26639197 Mon Sep 17 00:00:00 2001 From: Telmo Santos Date: Fri, 29 Jul 2022 08:51:45 +0200 Subject: [PATCH] microsoft_outlook v11 adjustments --- addons/fetchmail/models/fetchmail.py | 10 +++++++++- addons/microsoft_outlook/controllers/main.py | 3 +-- .../models/microsoft_outlook_mixin.py | 14 ++++++++------ .../models/res_config_settings.py | 11 +++++++++-- .../views/res_config_settings_views.xml | 2 +- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/addons/fetchmail/models/fetchmail.py b/addons/fetchmail/models/fetchmail.py index e03ef88ac44ee..49041451245c5 100644 --- a/addons/fetchmail/models/fetchmail.py +++ b/addons/fetchmail/models/fetchmail.py @@ -112,7 +112,7 @@ def connect(self): connection = IMAP4_SSL(self.server, int(self.port)) else: connection = IMAP4(self.server, int(self.port)) - connection.login(self.user, self.password) + self._imap_login(connection) elif self.type == 'pop': if self.is_ssl: connection = POP3_SSL(self.server, int(self.port)) @@ -126,6 +126,14 @@ def connect(self): connection.sock.settimeout(MAIL_TIMEOUT) return connection + def _imap_login(self, connection): + """Authenticate the IMAP connection. + Can be overridden in other module for different authentication methods. + :param connection: The IMAP connection to authenticate + """ + self.ensure_one() + connection.login(self.user, self.password) + @api.multi def button_confirm_login(self): for server in self: diff --git a/addons/microsoft_outlook/controllers/main.py b/addons/microsoft_outlook/controllers/main.py index 9206275a184ba..bde1b0907702f 100644 --- a/addons/microsoft_outlook/controllers/main.py +++ b/addons/microsoft_outlook/controllers/main.py @@ -72,5 +72,4 @@ def microsoft_outlook_callback(self, code=None, state=None, error_description=No 'microsoft_outlook_access_token': access_token, 'microsoft_outlook_access_token_expiration': expiration, }) - - return werkzeug.utils.redirect(f'/web?#id={rec_id}&model={model_name}&view_type=form', 303) + return werkzeug.utils.redirect('/web?#id=%s&model=%s&view_type=form' % (rec_id, model_name), 303) diff --git a/addons/microsoft_outlook/models/microsoft_outlook_mixin.py b/addons/microsoft_outlook/models/microsoft_outlook_mixin.py index 7453dae1d0811..3facadf0e2632 100644 --- a/addons/microsoft_outlook/models/microsoft_outlook_mixin.py +++ b/addons/microsoft_outlook/models/microsoft_outlook_mixin.py @@ -38,16 +38,17 @@ class MicrosoftOutlookMixin(models.AbstractModel): @api.depends('use_microsoft_outlook_service') def _compute_is_microsoft_outlook_configured(self): - Config = self.env['ir.config_parameter'].sudo() - microsoft_outlook_client_id = Config.get_param('microsoft_outlook_client_id') - microsoft_outlook_client_secret = Config.get_param('microsoft_outlook_client_secret') + company = self.env.user.company_id + microsoft_outlook_client_id = company.microsoft_outlook_client_identifier + microsoft_outlook_client_secret = company.microsoft_outlook_client_secret self.is_microsoft_outlook_configured = microsoft_outlook_client_id and microsoft_outlook_client_secret @api.depends('use_microsoft_outlook_service') def _compute_outlook_uri(self): Config = self.env['ir.config_parameter'].sudo() base_url = Config.get_param('web.base.url') - microsoft_outlook_client_id = Config.get_param('microsoft_outlook_client_id') + company = self.env.user.company_id + microsoft_outlook_client_id = company.microsoft_outlook_client_identifier for record in self: if not record.id or not record.use_microsoft_outlook_service or not record.is_microsoft_outlook_configured: @@ -123,8 +124,9 @@ def _fetch_outlook_token(self, grant_type, **values): """ Config = self.env['ir.config_parameter'].sudo() base_url = Config.get_param('web.base.url') - microsoft_outlook_client_id = Config.get_param('microsoft_outlook_client_id') - microsoft_outlook_client_secret = Config.get_param('microsoft_outlook_client_secret') + company = self.env.user.company_id + microsoft_outlook_client_id = company.microsoft_outlook_client_identifier + microsoft_outlook_client_secret = company.microsoft_outlook_client_secret response = requests.post( url_join(self._OUTLOOK_ENDPOINT, 'token'), diff --git a/addons/microsoft_outlook/models/res_config_settings.py b/addons/microsoft_outlook/models/res_config_settings.py index 620ecace671e7..8038f9001cb69 100644 --- a/addons/microsoft_outlook/models/res_config_settings.py +++ b/addons/microsoft_outlook/models/res_config_settings.py @@ -7,5 +7,12 @@ class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' - microsoft_outlook_client_identifier = fields.Char('Outlook Client Id', config_parameter='microsoft_outlook_client_id') - microsoft_outlook_client_secret = fields.Char('Outlook Client Secret', config_parameter='microsoft_outlook_client_secret') + microsoft_outlook_client_identifier = fields.Char(related='company_id.microsoft_outlook_client_identifier', string='Outlook Client Id') + microsoft_outlook_client_secret = fields.Char(related='company_id.microsoft_outlook_client_secret', string='Outlook Client Secret') + + +class Company(models.Model): + _inherit = "res.company" + + microsoft_outlook_client_identifier = fields.Char() + microsoft_outlook_client_secret = fields.Char() diff --git a/addons/microsoft_outlook/views/res_config_settings_views.xml b/addons/microsoft_outlook/views/res_config_settings_views.xml index 94cdb4b6705c8..ed50ee7d5c38e 100644 --- a/addons/microsoft_outlook/views/res_config_settings_views.xml +++ b/addons/microsoft_outlook/views/res_config_settings_views.xml @@ -8,7 +8,7 @@
+ attrs="{'invisible': [('default_external_email_server', '=', False)]}">
Outlook Credentials