Skip to content

Commit

Permalink
microsoft_outlook v11 adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
santostelmo committed Jul 29, 2022
1 parent b745764 commit 916a94f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
10 changes: 9 additions & 1 deletion addons/fetchmail/models/fetchmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions addons/microsoft_outlook/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 8 additions & 6 deletions addons/microsoft_outlook/models/microsoft_outlook_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'),
Expand Down
11 changes: 9 additions & 2 deletions addons/microsoft_outlook/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<field name="arch" type="xml">
<div id="emails" position="inside">
<div class="col-12 col-lg-6 o_setting_box" id="microsoft_outlook_setting"
attrs="{'invisible': [('external_email_server_default', '=', False)]}">
attrs="{'invisible': [('default_external_email_server', '=', False)]}">
<div class="o_setting_right_pane">
<span class="o_form_label">Outlook Credentials</span>
<div class="text-muted">
Expand Down

0 comments on commit 916a94f

Please sign in to comment.