Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(events): store expected onsite of all attendees #17

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/controllers/application.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 24 additions & 47 deletions src/controllers/events.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down