Skip to content
Snippets Groups Projects
Commit b45abc3d authored by pedrambiria's avatar pedrambiria
Browse files

[FIX] google_calendar: use the event user token to send the request


Before this commit: it was possible to create an event for another user as
its organizer. But even if that user has a synchronized Google calendar, it
will be sent by the current user token, and it causes several issues.

The solution is to use the event's organizer token if it exists.

opw-3076595

closes odoo/odoo#120352

X-original-commit: 96694316
Signed-off-by: default avatarArnaud Joset (arj) <arj@odoo.com>
Signed-off-by: default avatarPedram Bi Ria (pebr) <pebr@odoo.com>
parent b6ea1dd3
Branches
Tags
No related merge requests found
......@@ -222,9 +222,6 @@ class Meeting(models.Model):
} for alarm in self.alarm_ids]
attendees = self.attendee_ids
if self.user_id and self.user_id != self.env.user and bool(self.user_id.sudo().google_calendar_token):
# We avoid updating the other attendee status if we are not the organizer
attendees = self.attendee_ids.filtered(lambda att: att.partner_id == self.env.user.partner_id)
attendee_values = [{
'email': attendee.partner_id.email_normalized,
'responseStatus': attendee.state or 'needsAction',
......@@ -283,3 +280,9 @@ class Meeting(models.Model):
super(Meeting, my_cancelled_records)._cancel()
attendees = (self - my_cancelled_records).attendee_ids.filtered(lambda a: a.partner_id == user.partner_id)
attendees.state = 'declined'
def _get_event_user(self):
self.ensure_one()
if self.user_id and self.user_id.sudo().google_calendar_token:
return self.user_id
return self.env.user
......@@ -40,7 +40,7 @@ class RecurrenceRule(models.Model):
'active': False,
'need_sync': True,
}]
event._google_delete(google_service, event.google_id)
event.with_user(event._get_event_user())._google_delete(google_service, event.google_id)
event.google_id = False
self.env['calendar.event'].create(vals)
......@@ -230,3 +230,10 @@ class RecurrenceRule(models.Model):
},
}
return values
def _get_event_user(self):
self.ensure_one()
event = self._get_first_event()
if event:
return event._get_event_user()
return self.env.user
......@@ -71,7 +71,7 @@ class GoogleSync(models.AbstractModel):
result = super().write(vals)
for record in self.filtered('need_sync'):
if record.google_id:
record._google_patch(google_service, record.google_id, record._google_values(), timeout=3)
record.with_user(record._get_event_user())._google_patch(google_service, record.google_id, record._google_values(), timeout=3)
return result
......@@ -87,7 +87,7 @@ class GoogleSync(models.AbstractModel):
google_service = GoogleCalendarService(self.env['google.service'])
records_to_sync = records.filtered(lambda r: r.need_sync and r.active)
for record in records_to_sync:
record._google_insert(google_service, record._google_values(), timeout=3)
record.with_user(record._get_event_user())._google_insert(google_service, record._google_values(), timeout=3)
return records
def unlink(self):
......@@ -129,11 +129,11 @@ class GoogleSync(models.AbstractModel):
updated_records = records_to_sync.filtered('google_id')
new_records = records_to_sync - updated_records
for record in cancelled_records.filtered(lambda e: e.google_id and e.need_sync):
record._google_delete(google_service, record.google_id)
record.with_user(record._get_event_user())._google_delete(google_service, record.google_id)
for record in new_records:
record._google_insert(google_service, record._google_values())
record.with_user(record._get_event_user())._google_insert(google_service, record._google_values())
for record in updated_records:
record._google_patch(google_service, record.google_id, record._google_values())
record.with_user(record._get_event_user())._google_patch(google_service, record.google_id, record._google_values())
def _cancel(self):
self.google_id = False
......@@ -349,3 +349,11 @@ class GoogleSync(models.AbstractModel):
a given user.
"""
raise NotImplementedError()
def _get_event_user(self):
""" Return the correct user to send the request to Google.
It's possible that a user creates an event and sets another user as the organizer. Using self.env.user will
cause some issues, and It might not be possible to use this user for sending the request, so this method gets
the appropriate user accordingly.
"""
raise NotImplementedError()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment