Skip to content

Commit

Permalink
feat(events): preference metadata and system selection (#322)
Browse files Browse the repository at this point in the history
to be returned in results as part of an index query
  • Loading branch information
stakach authored Jun 27, 2024
1 parent 30f022d commit 3e80205
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.7"

services:
db:
#hostname: staff_api_db
Expand Down
12 changes: 6 additions & 6 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ 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
version: 0.4.0

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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
25 changes: 21 additions & 4 deletions src/controllers/events.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
}
Expand Down

0 comments on commit 3e80205

Please sign in to comment.