diff --git a/src/controllers/application.cr b/src/controllers/application.cr index 2630aa5..9c5e493 100644 --- a/src/controllers/application.cr +++ b/src/controllers/application.cr @@ -100,13 +100,13 @@ abstract class Application < ActionController::Base email = attendee.email.downcase if visitor = visitors[email]? { - name: attendee.display_name || visitor.guest.preferred_name || visitor.guest.name || email, - email: email, - response_status: attendee.response_status, - checked_in: is_parent_metadata ? false : visitor.checked_in, - visit_expected: visitor.visit_expected, - resource: attendee.resource, - required: !attendee.optional, + name: attendee.display_name || visitor.guest.preferred_name || visitor.guest.name || email, + email: email, + response_status: attendee.response_status, + checked_in: is_parent_metadata ? false : visitor.checked_in, + visit_expected: visitor.visit_expected, + resource: attendee.resource, + required: !attendee.optional, # assistance_required: visitor.guest.assistance_required, } else diff --git a/src/controllers/events.cr b/src/controllers/events.cr index 276b2d3..7ea402f 100644 --- a/src/controllers/events.cr +++ b/src/controllers/events.cr @@ -144,9 +144,9 @@ class Events < Application system = placeos_client.systems.fetch(system_id) sys_email = system.email.presence.not_nil! # Exclude the placeos system.name so that Google will automatically use the room mailbox name. - room_mailbox = GuestDetails.new(sys_email, nil) + room_mailbox = GuestDetails.new(sys_email, nil) room_mailbox.resource = true - attendees[sys_email] = room_mailbox + attendees[sys_email] = room_mailbox end # Ensure the host is configured to be attending the meeting and has accepted the meeting @@ -227,37 +227,9 @@ class Events < Application }) end - # Save external guests into the database - all_attendees = event.attendees - internal_domain = host.split("@")[1] || "unknown_domain" - if all_attendees && !all_attendees.empty? - all_attendees.each do |attendee| - next if !attendee.visit_expected - next if attendee.email.ends_with?(internal_domain) - - email = attendee.email.strip.downcase - guest = Guest.find(email) || Guest.new - guest.email = email - guest.name ||= attendee.name - guest.preferred_name ||= attendee.preferred_name - guest.phone ||= attendee.phone - guest.organisation ||= attendee.organisation - guest.photo ||= attendee.photo - # guest.assistance_required ||= !!attendee.assistance_required - - if ext_data = attendee.extension_data - guest_data = guest.extension_data - ext_data.each { |key, value| guest_data[key] = value } - end - - guest.save! - end - end - # Save custom data ext_data = event.extension_data - external_onsite_visitors = attending.select { |a| !a.email.ends_with?(internal_domain) } - if ext_data || (external_onsite_visitors && !external_onsite_visitors.empty?) + if ext_data || (attending && !attending.empty?) meta = EventMetadata.new meta.system_id = sys.id.not_nil! meta.event_id = gevent.id @@ -270,10 +242,24 @@ class Events < Application Log.info { "saving extension data for event #{gevent.id} in #{sys.id}" } - if external_onsite_visitors - # Create attendees - external_onsite_visitors.each do |attendee| + # Save all attendees into the database + if attending + # Create guests + attending.each do |attendee| email = attendee.email.strip.downcase + guest = Guest.find(email) || Guest.new + guest.email = email + guest.name ||= attendee.name + guest.preferred_name ||= attendee.preferred_name + guest.phone ||= attendee.phone + guest.organisation ||= attendee.organisation + guest.photo ||= attendee.photo + + if attendee_ext_data = attendee.extension_data + guest.extension_data = attendee_ext_data + end + guest.save! + attend = Attendee.new attend.event_id = meta.id.not_nil! attend.guest_id = email @@ -590,13 +576,11 @@ class Events < Application end end - # Save external guests into the database + # Save all guests into the database all_attendees = changes.attendees if all_attendees && !all_attendees.empty? - internal_domain = host.split("@")[1] || "unknown_domain" all_attendees.each do |attendee| - next if !attendee.visit_expected || attendee.email.ends_with?(internal_domain) - + next if !attendee.visit_expected email = attendee.email.strip.downcase guest = Guest.find(email) || Guest.new guest.email = email @@ -605,13 +589,9 @@ class Events < Application guest.phone ||= attendee.phone guest.organisation ||= attendee.organisation guest.photo ||= attendee.photo - # guest.assistance_required ||= !!attendee.assistance_required - - if ext_data = attendee.extension_data - guest_data = guest.extension_data - ext_data.each { |key, value| guest_data[key] = value } + if attendee_ext_data = attendee.extension_data + guest.extension_data = attendee_ext_data end - guest.save! end end @@ -622,8 +602,6 @@ class Events < Application attending.each do |attendee| email = attendee.email.strip.downcase next unless attendee.visit_expected - next if email.ends_with?(internal_domain.not_nil!) - was_attending = existing_lookup[email]? previously_visiting = was_attending.try &.visit_expected @@ -656,7 +634,6 @@ class Events < Application elsif changing_room existing.each do |attend| next unless attend.visit_expected - next if attend.email.ends_with?(internal_domain.not_nil!) spawn do sys = system.not_nil! guest = attend.guest