Skip to content

Commit

Permalink
merge from main
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Jun 20, 2024
2 parents a6e5ce6 + 567b237 commit 7e0f542
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

<!--next-version-placeholder-->

## 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
Expand Down
5 changes: 2 additions & 3 deletions codeforlife/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

Expand All @@ -39,7 +38,7 @@ def get_urlpatterns(
),
path(
"api/csrf/cookie/",
csrf.CookieView.as_view(),
CsrfCookieView.as_view(),
name="get-csrf-cookie",
),
path(
Expand Down
2 changes: 1 addition & 1 deletion codeforlife/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion codeforlife/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 10 additions & 1 deletion codeforlife/views/csrf.py → codeforlife/views/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand All @@ -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({})

0 comments on commit 7e0f542

Please sign in to comment.