Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.

Commit 1e8819f

Browse files
authored
Prepare for Matrix stream widgets (#1443)
* Add new page templates to prepare for Matrix stream widgets. Since the Matrix iframes do not send the session cookie from an already logged in browser tab, we have to resort to using a token for getting access to the page. Disable CMS caching of pages, since otherwise the token access check would be cached for all users. * Remove cookie samesite setting, since this is only supported in Django 3.1. * Make the token code work without having access to a request object. * Fix title filter to work without request object * Add whitespace on the side to make the video better fit Matrix widgets.
1 parent acc1d93 commit 1e8819f

File tree

6 files changed

+188
-6
lines changed

6 files changed

+188
-6
lines changed

conference/templatetags/conference.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@ def tickets(user):
145145
"""
146146
return get_tickets_for_current_conference(user)
147147

148-
@register.simple_tag
149-
def visible_streams(user):
148+
@register.simple_tag(takes_context=True)
149+
def visible_streams(context, user):
150150
""" Return the list of currently active streams as dictionaries:
151151
- title
152152
- url
153153
"""
154-
return get_streams_for_current_conference(user)
154+
request = context['request']
155+
return get_streams_for_current_conference(user, request=request)

conference/user_panel.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,14 +582,64 @@ def get_tickets_for_current_conference(user):
582582
)
583583

584584

585-
def get_streams_for_current_conference(user):
585+
def matrix_token_access(request):
586+
587+
""" Check whether a Matrix embedding token was passed in
588+
589+
"""
590+
#print ('Configured token: %r' % settings.MATRIX_STREAM_EMBEDDING_TOKEN)
591+
592+
if request is None:
593+
return False
594+
595+
# Token check
596+
if settings.MATRIX_STREAM_EMBEDDING_TOKEN is None:
597+
return False
598+
token = request.GET.get('token')
599+
#print ('Found token: %r' % token)
600+
if token is None:
601+
return False
602+
if token != settings.MATRIX_STREAM_EMBEDDING_TOKEN:
603+
return False
604+
605+
# Referer check
606+
if settings.MATRIX_STREAM_EMBEDDING_REFERER is not None:
607+
referrer = request.META.get('HTTP_REFERER')
608+
#print ('Referrer: %r' % referrer)
609+
if referrer is None:
610+
return False
611+
elif referrer.startswith(settings.MATRIX_STREAM_EMBEDDING_REFERER):
612+
# check passes
613+
pass
614+
else:
615+
return False
616+
617+
return True
618+
619+
def get_streams_for_current_conference(user, request=None):
586620

587621
""" Return the list of currently active streams as dictionaries:
588622
- title
589623
- url
590624
"""
591-
fare_codes = set(
592-
get_tickets_for_current_conference(user).values_list("fare__code", flat=True))
625+
if user.is_authenticated:
626+
# Authenticated user: use tickets
627+
fare_codes = set(
628+
get_tickets_for_current_conference(user).values_list("fare__code", flat=True))
629+
elif matrix_token_access(request):
630+
# Use token fares
631+
#print ('Allow Matrix embedding')
632+
fare_codes = settings.MATRIX_STREAM_EMBEDDING_FARES
633+
else:
634+
# No fares available
635+
fare_codes = set()
636+
637+
# Allow filtering by title
638+
if request is not None:
639+
title_filter = request.GET.get('title')
640+
else:
641+
title_filter = None
642+
593643
#print ('User has these fares: %r' % fare_codes)
594644
conference = Conference.objects.current()
595645
now = timezone.now()
@@ -612,6 +662,9 @@ def get_streams_for_current_conference(user):
612662
stream_fare_codes = set(stream.get('fare_codes', ()))
613663
#print ('Stream requires these fare codes: %r' % stream_fare_codes)
614664
if stream_fare_codes & fare_codes:
665+
if title_filter:
666+
if stream['title'] != title_filter:
667+
continue
615668
streams.append({
616669
'title': stream['title'],
617670
'url': stream['url'],

pycon/settings.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def _(x):
3535
HTTPS = True
3636
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
3737

38+
else:
39+
# In dev mode, allow configuring the HTTPS support via the env
40+
HTTPS = (os.environ.get('HTTPS', 'off') == 'on')
41+
if HTTPS:
42+
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
3843

3944
ADMINS = (("web-wg", "[email protected]"),)
4045
MANAGERS = ADMINS
@@ -373,6 +378,22 @@ def _(x):
373378

374379
PAGE_USE_STRICT_URL = True
375380

381+
### Django CMS
382+
383+
# Disable CMS content caching
384+
#
385+
# See https://docs.divio.com/en/latest/background/caching/#caching-with-aldryn-django-legacy
386+
# for details.
387+
#
388+
# Not doing so, puts the system at risk, since it could potentially deliver
389+
# content which was rendered for a user with different permissions.
390+
#
391+
CMS_CACHE_DURATIONS = {
392+
'menus': 60,
393+
'content': 0,
394+
'permissions': 60,
395+
}
396+
376397
CMS_LANGUAGES = {
377398
1: [
378399
{
@@ -394,6 +415,10 @@ def _(x):
394415
'Generic Content Page (with sidebar)'),
395416
('conference/homepage/home_template.html',
396417
'Homepage'),
418+
('conference/content/wide_content_page.html',
419+
'Wide Content Page'),
420+
('conference/content/content_only_page.html',
421+
'Content Only Page'),
397422
)
398423
PAGE_TEMPLATES = (
399424
('conference/content/generic_content_page_with_sidebar.html',
@@ -452,6 +477,9 @@ def _(x):
452477
#
453478
SESSION_COOKIE_NAME = 'sid'
454479
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
480+
if HTTPS:
481+
# Use secure cookie settings when using HTTPS
482+
SESSION_COOKIE_SECURE = True
455483

456484
CONFERENCE_CONFERENCE = 'ep2021'
457485
CONFERENCE_NAME = "EuroPython 2021"
@@ -739,3 +767,28 @@ def CONFERENCE_SCHEDULE_ATTENDEES(schedule, forecast):
739767
default='',
740768
cast=lambda v: [s.strip() for s in v.split(',') if s.strip()]
741769
)
770+
771+
### Matrix stream embedding
772+
773+
# Token to accept
774+
#
775+
# Normally, users have to be logged in to allow seeing streams based on
776+
# their tickets. With the token, this can be overridden to e.g. permit
777+
# Matrix widgets to show streams without having the user log in first.
778+
#
779+
MATRIX_STREAM_EMBEDDING_TOKEN = config(
780+
'MATRIX_STREAM_EMBEDDING_TOKEN',
781+
default=None
782+
)
783+
784+
# Referer to accept
785+
#
786+
# This is optional and only checked if given.
787+
#
788+
MATRIX_STREAM_EMBEDDING_REFERER = config(
789+
'MATRIX_STREAM_EMBEDDING_REFERER',
790+
default=None
791+
)
792+
793+
# Fare code set to assume when using stream embedding
794+
MATRIX_STREAM_EMBEDDING_FARES = set(['TRCC'])

templates/conference/base.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@
4949
<script src="{% static 'js/bootstrap.min.js' %}"></script>
5050
{% block morejs %}{% endblock %}
5151

52+
{% block cookieconsent %}
5253
{% include "conference/_cookie_consent.html" %}
54+
{% endblock %}
55+
5356
{% render_block "js" %} {# FOR DJANGO CMS #}
5457
</body>
5558
</html>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{% extends "conference/base.html" %}
2+
3+
{% load menu_tags cms_tags static %}
4+
5+
{% block body %}
6+
{% include "conference/content/_messages.html" %}
7+
<div id="content_page">
8+
<div class="container-fluid">
9+
<div class="row">
10+
<div class="col-lg-1 col-1"></div>
11+
<div class="col-lg-10 col-10">
12+
<div id="content" class="epcms_content">
13+
{% placeholder "text" %}
14+
</div>
15+
</div>
16+
<div class="col-lg-1 col-1"></div>
17+
</div><!-- .row -->
18+
</div>
19+
</div>
20+
{% endblock %}
21+
22+
{% block morejs %}
23+
<!-- No TOC generation script loaded -->
24+
{% endblock morejs %}
25+
26+
{% block cookieconsent %}
27+
<!-- No cookie consent banner shown -->
28+
{% endblock %}
29+
30+
{% block morecss %}
31+
<style>
32+
img.filer_image {
33+
max-width: 100%;
34+
height: auto;
35+
}
36+
</style>
37+
{% endblock morecss %}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{% extends "conference/base.html" %}
2+
3+
{% load menu_tags cms_tags static %}
4+
5+
{% block content %}
6+
<div id="content_page">
7+
<div class="container">
8+
<div class="row">
9+
<div class="col-md-12">
10+
<h1>{% page_attribute "title" %}</h1>
11+
</div>
12+
</div>
13+
<div class="row">
14+
<div class="col-lg-12 col-12">
15+
<div id="content" class="epcms_content">
16+
{% placeholder "text" %}
17+
</div>
18+
</div>
19+
</div><!-- .row -->
20+
</div>
21+
</div>
22+
{% endblock %}
23+
24+
{% block morejs %}
25+
<script src="{% static "/js/generate_toc_for_cms.js" %}"></script>
26+
{% endblock morejs %}
27+
28+
{% block morecss %}
29+
<style>
30+
img.filer_image {
31+
max-width: 100%;
32+
height: auto;
33+
}
34+
</style>
35+
{% endblock morecss %}

0 commit comments

Comments
 (0)