diff --git a/infokala_tracon/urls.py b/infokala_tracon/urls.py index d4e23b7..c4c1386 100755 --- a/infokala_tracon/urls.py +++ b/infokala_tracon/urls.py @@ -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[a-z0-9-]+)/messages/$', static_app_view), - re_path(r'^events/[a-z0-9-]+/messages$', slash_redirect_view), - re_path(r'^events/(?P[a-z0-9-]+)/messages/config.js$', + path("", default_event_redirect_view), + re_path(r"^events/(?P[a-z0-9-]+)/messages/$", static_app_view), + re_path(r"^events/[a-z0-9-]+/messages$", slash_redirect_view), + re_path( + r"^events/(?P[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[a-z0-9-]+)/messages/?$', + re_path( + r"^api/v1/events/(?P[a-z0-9-]+)/messages/?$", csrf_exempt(MessagesView.as_view()), - name='infokala_messages_view', + name="infokala_messages_view", ), - re_path(r'^api/v1/events/(?P[a-z0-9-]+)/messages/(?P\d+)/?$', + re_path( + r"^api/v1/events/(?P[a-z0-9-]+)/messages/(?P\d+)/?$", csrf_exempt(MessageView.as_view()), - name='infokala_message_view', + name="infokala_message_view", ), - re_path(r'^api/v1/events/(?P[a-z0-9-]+)/messages/(?P\d+)/events/?$', + re_path( + r"^api/v1/events/(?P[a-z0-9-]+)/messages/(?P\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")), ] diff --git a/infokala_tracon/views.py b/infokala_tracon/views.py index db82189..c5674ba 100755 --- a/infokala_tracon/views.py +++ b/infokala_tracon/views.py @@ -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, ) @@ -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 ] @@ -34,10 +39,20 @@ 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 @@ -45,21 +60,28 @@ 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) diff --git a/kubernetes/default.vars.yaml b/kubernetes/default.vars.yaml index 3d58b11..f0ff1ce 100644 --- a/kubernetes/default.vars.yaml +++ b/kubernetes/default.vars.yaml @@ -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: '' @@ -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: diff --git a/kubernetes/production.vars.yaml b/kubernetes/production.vars.yaml index 92ed22a..0c3231e 100644 --- a/kubernetes/production.vars.yaml +++ b/kubernetes/production.vars.yaml @@ -1,5 +1,3 @@ -infokala_default_event: tracon2024 - djangoapp_secret_managed: false djangoapp_admins: - Santtu Pajukanta