diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bfb53a0..b74f6f31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ +## v0.16.12 (2024-06-19) + +### Fix + +* Override logout view ([`1e4855c`](https://github.com/ocadotechnology/codeforlife-package-python/commit/1e4855c5b1c7c7d4a2dfac9b29901efe50e654f5)) + +## v0.16.11 (2024-06-19) + +### Fix + +* Auth flow ([#120](https://github.com/ocadotechnology/codeforlife-package-python/issues/120)) ([`c0ce515`](https://github.com/ocadotechnology/codeforlife-package-python/commit/c0ce515a4e5557c757e19dc8aa15ebb0437bc887)) + ## v0.16.10 (2024-06-07) ### Fix diff --git a/codeforlife/urls.py b/codeforlife/urls.py index 07394c28..886b08a0 100644 --- a/codeforlife/urls.py +++ b/codeforlife/urls.py @@ -6,13 +6,12 @@ import typing as t from django.contrib import admin -from django.contrib.auth.views import LogoutView from django.http import HttpResponse from django.urls import URLPattern, URLResolver, include, path, re_path from rest_framework import status from .settings import SERVICE_IS_ROOT, SERVICE_NAME -from .views import csrf +from .views import CsrfCookieView, LogoutView UrlPatterns = t.List[t.Union[URLResolver, URLPattern]] @@ -39,7 +38,7 @@ def get_urlpatterns( ), path( "api/csrf/cookie/", - csrf.CookieView.as_view(), + CsrfCookieView.as_view(), name="get-csrf-cookie", ), path( diff --git a/codeforlife/version.py b/codeforlife/version.py index 377c1c27..b96ed5ea 100644 --- a/codeforlife/version.py +++ b/codeforlife/version.py @@ -5,4 +5,4 @@ # Do NOT set manually! # This is auto-updated by python-semantic-release in the pipeline. -__version__ = "0.16.10" +__version__ = "0.16.12" diff --git a/codeforlife/views/__init__.py b/codeforlife/views/__init__.py index 149f5b39..1822c7e9 100644 --- a/codeforlife/views/__init__.py +++ b/codeforlife/views/__init__.py @@ -4,6 +4,6 @@ """ from .api import APIView -from .csrf import CookieView +from .common import CsrfCookieView, LogoutView from .decorators import action, cron_job from .model import ModelViewSet diff --git a/codeforlife/views/csrf.py b/codeforlife/views/common.py similarity index 66% rename from codeforlife/views/csrf.py rename to codeforlife/views/common.py index 8a149cf5..ac84de68 100644 --- a/codeforlife/views/csrf.py +++ b/codeforlife/views/common.py @@ -3,6 +3,8 @@ Created on 12/04/2024 at 16:51:36(+01:00). """ +from django.contrib.auth.views import LogoutView as _LogoutView +from django.http import JsonResponse from django.utils.decorators import method_decorator from django.views.decorators.csrf import ensure_csrf_cookie from rest_framework.request import Request @@ -12,7 +14,7 @@ from ..permissions import AllowAny -class CookieView(APIView): +class CsrfCookieView(APIView): """A view to get a CSRF cookie.""" http_method_names = ["get"] @@ -24,3 +26,10 @@ def get(self, request: Request): Return a response which Django will auto-insert a CSRF cookie into. """ return Response() + + +class LogoutView(_LogoutView): + """Override Django's logout view to always return a JSON response.""" + + def render_to_response(self, context, **response_kwargs): + return JsonResponse({})