Skip to content

Commit

Permalink
feat(place/attendee_scanner): reduce config required
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Feb 11, 2025
1 parent ab79c3f commit f0677f8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
27 changes: 19 additions & 8 deletions drivers/place/attendee_scanner.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ class Place::AttendeeScanner < PlaceOS::Driver
accessor locations : LocationServices_1

default_settings({
internal_domains: ["comment.out", "use authority / domain email_domains by preference"],
attendee_scan_every_minutes: 5,
_internal_domains: ["comment.out", "use authority / domain email_domains by preference"],
})

getter internal_domains : Array(String) = [] of String

def on_update
# TODO:: use authority email_domains so this setting isn't required
@internal_domains = setting(Array(String), :internal_domains).map!(&.strip.downcase)

@internal_domains = nil
@building_id = nil
@timezone = nil
@systems = nil
@org_id = nil

period = setting?(Int32, :attendee_scan_every_minutes) || 5
schedule.clear
schedule.every(period.minutes) { invite_external_guests }
end

getter building_id : String do
Expand All @@ -47,8 +48,18 @@ class Place::AttendeeScanner < PlaceOS::Driver
building_details = staff_api.zone(building_id).get
@org_id = building_details["parent_id"].as_s?

tz = building_details["timezone"].as_s
Time::Location.load(tz)
tz = building_details["timezone"]?.try(&.as_s?).presence || config.control_system.try(&.timezone)
Time::Location.load(tz.as(String))
end

getter internal_domains : Array(String) do
# use authority email_domains so this setting isn't required
domains = (setting?(Array(String), :internal_domains) || [] of String).map!(&.strip.downcase)
if domains.empty?
staff_api.auth_authority.get["email_domains"].as_a?.try(&.map(&.as_s.strip.downcase)) || domains
else
domains
end
end

alias Event = PlaceCalendar::Event
Expand Down
14 changes: 9 additions & 5 deletions drivers/place/attendee_scanner_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ class Bookings < DriverSpecs::MockDriver
"event_start": 1.hour.ago.to_unix,
"event_end": 1.hour.from_now.to_unix,
"id": "AAkALgAAAAAAHYQDEapmEc2byACqAC-EWg0AVrOjSWJ0R0_lv6HqEl72fQABnPXAjwAA",
"host": "IsaiahL@comment.out",
"host": "IsaiahL@email.com",
"title": "Test Meeting",
"body": "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta name=\"Generator\" content=\"Microsoft Exchange Server\">\r\n<!-- converted from text -->\r\n<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style></head>\r\n<body>\r\n<font size=\"2\"><span style=\"font-size:11pt;\"><div class=\"PlainText\">&nbsp;</div></span></font>\r\n</body>\r\n</html>\r\n",
"attendees": [
{
"name": "Isaiah Langer",
"email": "isaiahl@comment.out",
"email": "isaiahl@email.com",
"response_status": "needsAction",
"resource": false,
},
Expand All @@ -112,7 +112,7 @@ class Bookings < DriverSpecs::MockDriver
},
{
"name": "Test Room 1",
"email": "testroom1@comment.out",
"email": "testroom1@email.com",
"response_status": "accepted",
"resource": true,
},
Expand All @@ -127,17 +127,21 @@ class Bookings < DriverSpecs::MockDriver
"updated": "2024-12-03T08:59:56Z",
"attachments": [] of Nil,
"status": "confirmed",
"creator": "IsaiahL@comment.out",
"creator": "IsaiahL@email.com",
"ical_uid": "040000008200E00074C5B7101A82E00800000000B5C273946145DB01000000000000000010000000651007D546B31E4EB651ED0F73A0CDB6",
"online_meeting_provider": "teamsForBusiness",
"online_meeting_phones": [] of Nil,
"online_meeting_url": "https://teams.microsoft.com/l/meetup-join/19%3ameeting_ZjRkMTM2ZTYtZGIxNi00NDFkLWI5NGYtNDA3Mjg1NDg0YzA2%40thread.v2/0?context=%7b%22Tid%22%3a%22bc9d5ad8-7518-422b-ac8d-b69429ca4cb9%22%2c%22Oid%22%3a%22905b5cbc-ac57-4159-98a7-9b9d8e%22%7d",
"mailbox": "testroom1@comment.out",
"mailbox": "testroom1@email.com",
}]
end
end

DriverSpecs.mock_driver "Place::AttendeeScanner" do
settings({
internal_domains: ["email.com"],
})

system({
StaffAPI: {StaffAPI},
LocationServices: {LocationServices},
Expand Down

0 comments on commit f0677f8

Please sign in to comment.