[FIX] microsoft_calendar: Make searching organizer by their email address case-insensitive
Before this commit Odoo was unable to match Outlook address Firstname.Lastname@example.com to Odoo user email address firstname.lastname@example.com. This lead to events being created in Odoo without an organizer. closes odoo/odoo#148715 X-original-commit: c6e174f99d741b82f9e2cb0789e7ad7786879825 Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
This commit is contained in:
@@ -111,6 +111,32 @@ class TestCreateEvents(TestCommon):
|
||||
self.assertEqual(len(new_records), 1)
|
||||
self.assert_odoo_event(new_records, expected_event)
|
||||
|
||||
@patch.object(MicrosoftCalendarService, 'get_events')
|
||||
def test_create_simple_event_from_outlook_attendee_calendar_where_email_addresses_are_capitalized(self, mock_get_events):
|
||||
"""
|
||||
An event has been created in Outlook and synced in the Odoo attendee calendar.
|
||||
The email addresses of the attendee and the organizer are in different case than in Odoo.
|
||||
"""
|
||||
|
||||
# arrange
|
||||
outlook_event = dict(self.simple_event_from_outlook_attendee, organizer={
|
||||
'emailAddress': {'address': "Mike@organizer.com", 'name': "Mike Organizer"},
|
||||
}, attendees=[{'type': 'required', 'status': {'response': 'none', 'time': '0001-01-01T00:00:00Z'},
|
||||
'emailAddress': {'name': 'John Attendee', 'address': 'John@attendee.com'}}])
|
||||
|
||||
mock_get_events.return_value = (MicrosoftEvent([outlook_event]), None)
|
||||
existing_records = self.env["calendar.event"].search([])
|
||||
|
||||
# act
|
||||
self.organizer_user.with_user(self.organizer_user).sudo()._sync_microsoft_calendar()
|
||||
|
||||
# assert
|
||||
records = self.env["calendar.event"].search([])
|
||||
new_records = (records - existing_records)
|
||||
self.assertEqual(len(new_records), 1)
|
||||
self.assert_odoo_event(new_records, self.expected_odoo_event_from_outlook)
|
||||
self.assertEqual(new_records.user_id, self.organizer_user)
|
||||
|
||||
@patch.object(MicrosoftCalendarService, 'insert')
|
||||
def test_create_recurrent_event_without_sync(self, mock_insert):
|
||||
"""
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
from odoo.api import model
|
||||
from typing import Iterator, Mapping
|
||||
from collections import abc
|
||||
from odoo.tools import ReadonlyDict
|
||||
from odoo.tools import ReadonlyDict, email_normalize
|
||||
from odoo.addons.microsoft_calendar.utils.event_id_storage import combine_ids
|
||||
|
||||
|
||||
@@ -166,9 +166,11 @@ class MicrosoftEvent(abc.Set):
|
||||
"""
|
||||
if self.isOrganizer:
|
||||
return env.user.id
|
||||
if self.organizer.get('emailAddress') and self.organizer.get('emailAddress').get('address'):
|
||||
|
||||
organizer_email = self.organizer.get('emailAddress') and email_normalize(self.organizer.get('emailAddress').get('address'))
|
||||
if organizer_email:
|
||||
# Warning: In Microsoft: 1 email = 1 user; but in Odoo several users might have the same email
|
||||
user = env['res.users'].search([('email', '=', self.organizer.get('emailAddress').get('address'))], limit=1)
|
||||
user = env['res.users'].search([('email', '=', organizer_email)], limit=1)
|
||||
return user.id if user else False
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user