Skip to content

Commit

Permalink
Merge pull request #5265 from onepercentclub/hotfix/BB-20613-add-loca…
Browse files Browse the repository at this point in the history
…tion-hint-to-calendar-invites

Add location hint to calendar invites
  • Loading branch information
gannetson committed Oct 5, 2022
2 parents e46eef4 + c7c4f86 commit bcc96d3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 7 deletions.
2 changes: 2 additions & 0 deletions bluebottle/time_based/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ def format_date(date):

if self.location:
params['location'] = self.location.formatted_address
if self.location_hint:
params['location'] = f'{params["location"]} ({self.location_hint})'

return u'{}?{}'.format(url, urlencode(params))

Expand Down
76 changes: 69 additions & 7 deletions bluebottle/time_based/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,7 @@ def test_get_other(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_get_calendar_links(self):
self.slot.location = None
self.slot.is_online = True
self.slot.online_meeting_url = 'http://example.com'
self.slot.save()
Expand All @@ -1694,19 +1695,48 @@ def test_get_calendar_links(self):

links = response.json()['data']['attributes']['links']

self.assertTrue(
urllib.parse.quote_plus(self.slot.online_meeting_url) in links['google']
)
self.assertTrue(
'https://calendar.google.com/calendar/render?action=TEMPLATE' in links['google']
)

self.assertTrue(
links['ical'].startswith(
reverse('slot-ical', args=(self.slot.pk,))
)
)

params = urllib.parse.parse_qs(urllib.parse.urlparse(links['google']).query)
self.assertEqual(params['action'], ['TEMPLATE'])
self.assertEqual(params['text'][0], self.activity.title)
self.assertEqual(
params['details'][0],
f'{self.activity.description}\n{self.activity.get_absolute_url()}\nJoin: {self.slot.online_meeting_url}'
)

def test_get_calendar_links_location(self):
self.slot.is_online = False
self.slot.save()

response = self.client.get(self.url, user=self.activity.owner)

links = response.json()['data']['attributes']['links']

params = urllib.parse.parse_qs(urllib.parse.urlparse(links['google']).query)
self.assertEqual(
params['location'][0], self.slot.location.formatted_address
)

def test_get_calendar_links_location_hint(self):
self.slot.is_online = False
self.slot.location_hint = 'On the second floor'
self.slot.save()

response = self.client.get(self.url, user=self.activity.owner)

links = response.json()['data']['attributes']['links']

params = urllib.parse.parse_qs(urllib.parse.urlparse(links['google']).query)
self.assertEqual(
params['location'][0],
f'{self.slot.location.formatted_address} ({self.slot.location_hint})'
)

def test_closed_site(self):
MemberPlatformSettings.objects.update(closed=True)
group = Group.objects.get(name='Anonymous')
Expand Down Expand Up @@ -3066,6 +3096,7 @@ def setUp(self):
self.slot = self.activity.slots.first()
self.slot.is_online = True
self.slot.online_meeting_url = 'http://example.com'
self.slot.location = None
self.slot.save()

self.slot_url = reverse('date-slot-detail', args=(self.slot.pk,))
Expand Down Expand Up @@ -3112,6 +3143,37 @@ def test_get(self):
)
self.assertEqual(ical_event['url'], self.activity.get_absolute_url())
self.assertEqual(ical_event['organizer'], 'MAILTO:{}'.format(self.activity.owner.email))
self.assertTrue('location' not in ical_event)

def test_get_location(self):
self.slot.location = GeolocationFactory.create()
self.slot.save()

response = self.client.get(self.signed_url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
calendar = icalendar.Calendar.from_ical(response.content)

for ical_event in calendar.walk('vevent'):
self.assertEqual(ical_event['organizer'], 'MAILTO:{}'.format(self.activity.owner.email))
self.assertEqual(
ical_event['location'], self.slot.location.formatted_address
)

def test_get_location_hint(self):
self.slot.location = GeolocationFactory.create()
self.slot.location_hint = 'On the first floor'
self.slot.save()

response = self.client.get(self.signed_url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
calendar = icalendar.Calendar.from_ical(response.content)

for ical_event in calendar.walk('vevent'):
self.assertEqual(ical_event['organizer'], 'MAILTO:{}'.format(self.activity.owner.email))
self.assertEqual(
ical_event['location'],
f'{self.slot.location.formatted_address} ({self.slot.location_hint})'
)

def test_get_no_signature(self):
response = self.client.get(self.unsigned_url)
Expand Down
5 changes: 5 additions & 0 deletions bluebottle/time_based/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ def get(self, *args, **kwargs):
if slot.location:
event['location'] = icalendar.vText(slot.location.formatted_address)

if slot.location_hint:
event['location'] = f'{event["location"]} ({slot.location_hint})'

calendar.add_component(event)

response = HttpResponse(calendar.to_ical(), content_type='text/calendar')
Expand Down Expand Up @@ -535,6 +538,8 @@ def get(self, *args, **kwargs):
if instance.location:
slot['location'] = icalendar.vText(instance.location.formatted_address)

if instance.location_hint:
slot['location'] = f'{slot["location"]} ({instance.location_hint})'
calendar.add_component(slot)

response = HttpResponse(calendar.to_ical(), content_type='text/calendar')
Expand Down

0 comments on commit bcc96d3

Please sign in to comment.