diff --git a/docker-compose.yml b/docker-compose.yml index 970c5fc..47cbbb7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3.7" - services: db: #hostname: staff_api_db diff --git a/shard.lock b/shard.lock index d833829..00ebb43 100644 --- a/shard.lock +++ b/shard.lock @@ -31,7 +31,7 @@ shards: connect-proxy: git: https://github.com/spider-gazelle/connect-proxy.git - version: 2.0.0 + version: 2.0.1 cron_parser: git: https://github.com/kostya/cron_parser.git @@ -39,7 +39,7 @@ shards: csuuid: git: https://github.com/wyhaines/csuuid.cr.git - version: 1.0.0+git.commit.a4cf9615c6518cf27c68a1755a8c2ac4ae4fe987 + version: 1.0.1+git.commit.b71cf5c899dd5cde6aff8e922bdabd5e2dfab585 db: git: https://github.com/crystal-lang/crystal-db.git @@ -55,7 +55,7 @@ shards: email: git: https://github.com/arcage/crystal-email.git - version: 0.7.0 + version: 0.7.1 eventbus: git: https://github.com/spider-gazelle/eventbus.git @@ -115,7 +115,7 @@ shards: office365: git: https://github.com/placeos/office365.git - version: 1.24.0 + version: 1.25.3 open_api: git: https://github.com/elbywan/open_api.cr.git @@ -163,7 +163,7 @@ shards: place_calendar: git: https://github.com/placeos/calendar.git - version: 4.20.1 + version: 4.22.1 placeos: git: https://github.com/placeos/crystal-client.git @@ -175,7 +175,7 @@ shards: placeos-models: git: https://github.com/placeos/models.git - version: 9.46.0 + version: 9.48.0 pool: git: https://github.com/ysbaddaden/pool.git diff --git a/src/controllers/events.cr b/src/controllers/events.cr index 94934f5..505c7b6 100644 --- a/src/controllers/events.cr +++ b/src/controllers/events.cr @@ -130,7 +130,7 @@ class Events < Application # find any missing system ids (event_id => calendar_id) event_resources = {} of String => String - results.each do |(_calendar_id, system, event)| + results.each do |(calendar_id, system, event)| # NOTE:: we should be able to swtch to using the ical uids only in the future # 01/06/2022 MS does not return unique ical uids for recurring bookings: https://devblogs.microsoft.com/microsoft365dev/microsoft-graph-calendar-events-icaluid-update/ # However they have a new `uid` field on the beta API which we can use when it's moved to production @@ -144,13 +144,21 @@ class Events < Application # TODO: Handle recurring O365 events with differing `ical_uid` # Determine how to deal with recurring events in Office365 where the `ical_uid` is different for each recurrance - if (recurring_event_id = event.recurring_event_id) && recurring_event_id != event.id + if (recurring_event_id = event.recurring_event_id) && recurring_event_id != event_id event_master_ids << recurring_event_id end # check if there is possible system information available - if system.nil? && (attendee = event.attendees.find(&.resource)) - event_resources[event.id.as(String)] = attendee.email.downcase + if system.nil? + resource_emails = event.attendees.compact_map do |attendee| + attendee.email.downcase if attendee.resource + end + + if resource_emails.includes? calendar_id + event_resources[event_id] = calendar_id + elsif attend_email = resource_emails.first? + event_resources[event_id] = attend_email + end end end @@ -160,18 +168,27 @@ class Events < Application # Metadata is stored against a resource calendar which in office365 can only # be matched by the `ical_uid` EventMetadata.by_tenant(tenant.id).by_events_or_master_ids(ical_uids, event_master_ids).each { |meta| + # where there might be multiple resource calendars on the event we want to pick + # metadatas that most closely match the request + next if (existing = metadatas[meta.ical_uid]?) && calendars[existing.resource_calendar]? + metadatas[meta.ical_uid] = meta if recurring_master_id = meta.recurring_master_id + next if (existing = metadatas[recurring_master_id]?) && calendars[existing.resource_calendar]? metadatas[recurring_master_id] = meta if resource_master_id = meta.resource_master_id + next if (existing = metadatas[resource_master_id]?) && calendars[existing.resource_calendar]? metadatas[resource_master_id] = meta end end } else EventMetadata.by_tenant(tenant.id).by_events_or_master_ids(event_ids, event_master_ids).each { |meta| + next if (existing = metadatas[meta.event_id]?) && calendars[existing.resource_calendar]? + metadatas[meta.event_id] = meta if recurring_master_id = meta.recurring_master_id + next if (existing = metadatas[recurring_master_id]?) && calendars[existing.resource_calendar]? metadatas[recurring_master_id] = meta end }