Skip to content

Commit

Permalink
feat: default event redirect view
Browse files Browse the repository at this point in the history
  • Loading branch information
japsu committed Oct 27, 2024
1 parent 83bf527 commit f294292
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 45 deletions.
47 changes: 23 additions & 24 deletions infokala_tracon/urls.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
from django.conf import settings
from django.conf.urls import include
from django.contrib import admin
from django.urls import path, re_path
from django.views.decorators.csrf import csrf_exempt
from django.views.generic.base import RedirectView

from .views import (
ConfigView,
logout_view,
MessageEventsView,
MessagesView,
MessageView,
MessageEventsView,
default_event_redirect_view,
logout_view,
slash_redirect_view,
static_app_view,
status_view,
)
from django.urls import path, re_path

urlpatterns = [
# XXX hardcoded
path('', RedirectView.as_view(url='/events/{default_event}/messages'.format(default_event=settings.INFOKALA_DEFAULT_EVENT)),
name='infokala_frontpage_redirect_view',
),
re_path(r'^events/(?P<event_slug>[a-z0-9-]+)/messages/$', static_app_view),
re_path(r'^events/[a-z0-9-]+/messages$', slash_redirect_view),
re_path(r'^events/(?P<event_slug>[a-z0-9-]+)/messages/config.js$',
path("", default_event_redirect_view),
re_path(r"^events/(?P<event_slug>[a-z0-9-]+)/messages/$", static_app_view),
re_path(r"^events/[a-z0-9-]+/messages$", slash_redirect_view),
re_path(
r"^events/(?P<event_slug>[a-z0-9-]+)/messages/config.js$",
csrf_exempt(ConfigView.as_view()),
name='infokala_config_view',
name="infokala_config_view",
),
re_path(r'^api/v1/events/(?P<event_slug>[a-z0-9-]+)/messages/?$',
re_path(
r"^api/v1/events/(?P<event_slug>[a-z0-9-]+)/messages/?$",
csrf_exempt(MessagesView.as_view()),
name='infokala_messages_view',
name="infokala_messages_view",
),
re_path(r'^api/v1/events/(?P<event_slug>[a-z0-9-]+)/messages/(?P<message_id>\d+)/?$',
re_path(
r"^api/v1/events/(?P<event_slug>[a-z0-9-]+)/messages/(?P<message_id>\d+)/?$",
csrf_exempt(MessageView.as_view()),
name='infokala_message_view',
name="infokala_message_view",
),
re_path(r'^api/v1/events/(?P<event_slug>[a-z0-9-]+)/messages/(?P<message_id>\d+)/events/?$',
re_path(
r"^api/v1/events/(?P<event_slug>[a-z0-9-]+)/messages/(?P<message_id>\d+)/events/?$",
csrf_exempt(MessageEventsView.as_view()),
name='infokala_message_events_view',
name="infokala_message_events_view",
),

re_path(r'^api/v1/status/?$', status_view, name='status_view'),


path('admin/', admin.site.urls),
re_path(r'^logout/?$', logout_view),
path('', include('kompassi_oauth2.urls')),
re_path(r"^api/v1/status/?$", status_view, name="status_view"),
path("admin/", admin.site.urls),
re_path(r"^logout/?$", logout_view),
path("", include("kompassi_oauth2.urls")),
]
52 changes: 37 additions & 15 deletions infokala_tracon/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from django.conf import settings
from django.contrib.staticfiles.views import serve
from django.contrib.auth.decorators import login_required
from django.contrib.auth import logout
from django.contrib.auth.decorators import login_required
from django.contrib.staticfiles.views import serve
from django.http import HttpResponseForbidden, JsonResponse
from django.shortcuts import redirect, render

from infokala.views import (
ConfigView as InfokalaConfigView,
)
from infokala.views import (
MessageEventsView as InfokalaMessageEventsView,
)
from infokala.views import (
MessagesView as InfokalaMessagesView,
)
from infokala.views import (
MessageView as InfokalaMessageView,
MessageEventsView as InfokalaMessageEventsView,
ConfigView as InfokalaConfigView,
)


Expand All @@ -21,7 +26,7 @@ def is_user_allowed_to_access(user, event):
tmpl.format(
kompassi_installation_slug=settings.KOMPASSI_INSTALLATION_SLUG,
infokala_installation_slug=settings.INFOKALA_INSTALLATION_SLUG,
event_slug=event.slug
event_slug=event.slug,
)
for tmpl in settings.INFOKALA_ACCESS_GROUP_TEMPLATES
]
Expand All @@ -34,32 +39,49 @@ def authenticate(self, request, event):
return is_user_allowed_to_access(request.user, event)


class MessagesView(AccessControlMixin, InfokalaMessagesView): pass
class MessageView(AccessControlMixin, InfokalaMessageView): pass
class MessageEventsView(AccessControlMixin, InfokalaMessageEventsView): pass
class ConfigView(AccessControlMixin, InfokalaConfigView): pass
class MessagesView(AccessControlMixin, InfokalaMessagesView):
pass


class MessageView(AccessControlMixin, InfokalaMessageView):
pass


class MessageEventsView(AccessControlMixin, InfokalaMessageEventsView):
pass


class ConfigView(AccessControlMixin, InfokalaConfigView):
pass


@login_required
def static_app_view(request, event_slug):
event = settings.INFOKALA_GET_EVENT_OR_404(slug=event_slug)

if not is_user_allowed_to_access(request.user, event):
return render(request, 'infokala_tracon_forbidden.html', status=403)
return render(request, "infokala_tracon_forbidden.html", status=403)

return serve(request, path='infokala/infokala.html', insecure=True)
return serve(request, path="infokala/infokala.html", insecure=True)


def slash_redirect_view(request):
return redirect(request.path + '/')
return redirect(request.path + "/")


def logout_view(request):
logout(request)

next_page = request.GET.get('next', settings.LOGOUT_REDIRECT_URL)
next_page = request.GET.get("next", settings.LOGOUT_REDIRECT_URL)
return redirect(next_page)


def status_view(request):
return JsonResponse({'status': 'OK'})
return JsonResponse({"status": "OK"})


def default_event_redirect_view(request):
from infokala.models import MessageType

message_type = MessageType.objects.latest("id")
return redirect("infokala_messages_view", event_slug=message_type.event_slug)
4 changes: 0 additions & 4 deletions kubernetes/default.vars.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Note: For {dev.,beta.,}conikuvat.fi and larppikuvat.fi, djangoapp_tag is overridden in Jenkinsfile.

# App specific settings
infokala_default_event: example

# Kompassi OAuth2 (NOTE: do not set if djangoapp_secret_managed: false)
kompassi_client_id: ''
kompassi_client_secret: ''
Expand Down Expand Up @@ -94,8 +92,6 @@ gunicorn_environment:
secretKeyRef:
name: !Var djangoapp_name
key: secretKey
- name: INFOKALA_DEFAULT_EVENT
value: !Var infokala_default_event
- name: KOMPASSI_OAUTH2_CLIENT_ID
valueFrom:
secretKeyRef:
Expand Down
2 changes: 0 additions & 2 deletions kubernetes/production.vars.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
infokala_default_event: tracon2024

djangoapp_secret_managed: false
djangoapp_admins:
- Santtu Pajukanta <[email protected]>
Expand Down

0 comments on commit f294292

Please sign in to comment.