Skip to content

Commit

Permalink
Merge branch 'master' into release/office-restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
gannetson committed Oct 5, 2022
2 parents cfbe268 + bcc96d3 commit 4267faf
Show file tree
Hide file tree
Showing 13 changed files with 7,568 additions and 4,792 deletions.
4 changes: 3 additions & 1 deletion bluebottle/initiatives/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def is_staff(self, user):
approved,
name=_('Approve'),
description=_("The initiative will be visible in the frontend and "
"all completed activities will be open for contributions."),
"all completed activities will be open for contributions. "
"Crowdfunding activities have to be reviewed separately."
),
conditions=[is_complete, is_valid],
automatic=False,
permission=is_staff,
Expand Down
3 changes: 2 additions & 1 deletion bluebottle/scim/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.contrib.auth.models import Group
from django.urls import reverse

from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _

from dotted.collection import DottedDict
Expand Down Expand Up @@ -80,7 +81,7 @@ def to_internal_value(self, value):
queryset = self.get_queryset()
location_name = value[0]['locality']
try:
return queryset.get(name=location_name)
return queryset.get(slug=slugify(location_name))
except Location.DoesNotExist:
return queryset.create(name=location_name)
except (TypeError, ValueError):
Expand Down
2 changes: 1 addition & 1 deletion bluebottle/scim/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def test_post_location(self):
"""
Create a user with a location
"""
location = LocationFactory.create()
location = LocationFactory.create(name='test location!', slug='test-location')
data = {
'schemas': ['urn:ietf:params:scim:schemas:core:2.0:User'],
'active': True,
Expand Down
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
Loading

0 comments on commit 4267faf

Please sign in to comment.