Include speaker user name in schedule JSON

When a user has permission to see contact details, expose the speaker's
username in the author object, for integration between systems.
This commit is contained in:
Joel Addison 2022-01-05 19:48:42 +10:00
parent 731858c191
commit 97391d0210

View file

@ -217,22 +217,26 @@ def has_contact_perm(user):
return user.has_perm('symposion_speakers.can_view_contact_details') or user.is_staff
def make_speaker_dict(user, speaker):
def make_speaker_dict(speaker, can_view_contact_details):
return {
'name': speaker.name,
'twitter': speaker.twitter_username,
'contact': speaker.email if has_contact_perm(user) else 'redacted',
'contact': speaker.email if can_view_contact_details else 'redacted',
'picture_url': speaker_photo(None, speaker, 120),
'code': speaker.code,
'biography': speaker.biography,
'username': speaker.user_id if can_view_contact_details else '',
}
def schedule_json(request):
slots = Slot.objects.filter(
day__schedule__published=True,
day__schedule__hidden=False
).order_by("start")
can_view_contact_details = has_contact_perm(request.user)
protocol = request.META.get('HTTP_X_FORWARDED_PROTO', 'http')
data = []
for slot in slots:
@ -269,7 +273,7 @@ def schedule_json(request):
slot_data.update({
"name": slot.content.title,
"authors": [make_speaker_dict(request.user, s) for s in slot.content.speakers()],
"authors": [make_speaker_dict(s, can_view_contact_details) for s in slot.content.speakers()],
"abstract": slot.content.abstract,
"conf_url": "%s://%s%s" % (
protocol,