From d38fd353f9641a063a7c35f689ed9563c9de91bc Mon Sep 17 00:00:00 2001 From: TSO Date: Mon, 9 Oct 2023 06:20:00 +0200 Subject: [PATCH] [FIX] mail: turn twilio credentials method into a util function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit similar to https://github.com/odoo/odoo/pull/87440 closes odoo/odoo#138064 X-original-commit: cd706e662dabe5fb9dfbaaa2fde111865387b504 Signed-off-by: Alexandre Kühn (aku) Signed-off-by: Nicolas Martinelli (nim) --- addons/mail/models/mail_ice_server.py | 11 ++--------- addons/mail/tools/__init__.py | 1 + addons/mail/tools/credentials.py | 12 ++++++++++++ 3 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 addons/mail/tools/credentials.py diff --git a/addons/mail/models/mail_ice_server.py b/addons/mail/models/mail_ice_server.py index 043b34d63e0..b45c04945b4 100644 --- a/addons/mail/models/mail_ice_server.py +++ b/addons/mail/models/mail_ice_server.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import fields, models +from odoo.addons.mail.tools.credentials import get_twilio_credentials import requests @@ -32,21 +33,13 @@ class MailIceServer(models.Model): formatted_ice_servers.append(formatted_ice_server) return formatted_ice_servers - def _get_twilio_credentials(self): - """ To be overridable if we need to obtain credentials from another source. - :return: tuple - """ - account_sid = self.env['ir.config_parameter'].sudo().get_param('mail.twilio_account_sid') - auth_token = self.env['ir.config_parameter'].sudo().get_param('mail.twilio_account_token') - return account_sid, auth_token - def _get_ice_servers(self): """ :return: List of dict, each of which representing a stun or turn server, formatted as expected by the specifications of RTCConfiguration.iceServers """ if self.env['ir.config_parameter'].sudo().get_param('mail.use_twilio_rtc_servers'): - (account_sid, auth_token) = self._get_twilio_credentials() + (account_sid, auth_token) = get_twilio_credentials(self.env) if account_sid and auth_token: url = f'https://api.twilio.com/2010-04-01/Accounts/{account_sid}/Tokens.json' response = requests.post(url, auth=(account_sid, auth_token), timeout=60) diff --git a/addons/mail/tools/__init__.py b/addons/mail/tools/__init__.py index 6df5ce5e548..9cbdd418684 100644 --- a/addons/mail/tools/__init__.py +++ b/addons/mail/tools/__init__.py @@ -3,3 +3,4 @@ from . import alias_error from . import mail_validation +from . import credentials diff --git a/addons/mail/tools/credentials.py b/addons/mail/tools/credentials.py new file mode 100644 index 00000000000..29c4274ba61 --- /dev/null +++ b/addons/mail/tools/credentials.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +def get_twilio_credentials(env): + """ + To be overridable if we need to obtain credentials from another source. + :return: tuple(account_sid: str, auth_token: str) + """ + params = env["ir.config_parameter"].sudo() + account_sid = params.get_param("mail.twilio_account_sid") + auth_token = params.get_param("mail.twilio_account_token") + return account_sid, auth_token