diff --git a/api/admin.py b/api/admin.py index e1243e5..0a36013 100644 --- a/api/admin.py +++ b/api/admin.py @@ -11,4 +11,4 @@ class ApiKeyAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): if not change: obj.initialFill() - super(ApiKeyAdmin, self).save_model(request, obj, form, change) + super().save_model(request, obj, form, change) diff --git a/api/models.py b/api/models.py index 9db7996..c7b165f 100644 --- a/api/models.py +++ b/api/models.py @@ -37,7 +37,7 @@ class ApiKey(models.Model): @property def keyId(self): - return self.id + return self.pk @property def displayValue(self): diff --git a/app/settings.py b/app/settings.py index 729e7c2..8ba740e 100644 --- a/app/settings.py +++ b/app/settings.py @@ -4,8 +4,6 @@ Django settings for the bocal project from pathlib import Path -from django.contrib.messages import constants as messages -from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ from loadcredential import Credentials diff --git a/bocal_auth/rhosts.py b/bocal_auth/rhosts.py index ae1d80c..a0c25c1 100644 --- a/bocal_auth/rhosts.py +++ b/bocal_auth/rhosts.py @@ -95,12 +95,12 @@ def evalRhostsPrivileges(user): @requireCasUser def logout(user): - stripCasPrivileges() + stripCasPrivileges(user) def forceReevalRhosts(fct): - def wrap(req, *args, **kwargs): - evalRhostsPrivileges(req.user) - return fct(req, *args, **kwargs) + def wrap(request, *args, **kwargs): + evalRhostsPrivileges(request.user) + return fct(request, *args, **kwargs) return wrap diff --git a/bocal_auth/views.py b/bocal_auth/views.py index 995ad23..d8f7b3d 100644 --- a/bocal_auth/views.py +++ b/bocal_auth/views.py @@ -2,26 +2,33 @@ from urllib.parse import quote as urlquote from django.contrib.auth import logout as auth_logout from django.contrib.auth.decorators import login_required +from django.http import HttpRequest +from django.http.response import Http404 from django.shortcuts import redirect, render from django.urls import reverse -def login(req): - if req.user.is_authenticated: +def login(request: HttpRequest): + if request.user.is_authenticated: return redirect("homepage") - if req.method == "GET": - reqDict = req.GET - elif req.method == "POST": - reqDict = req.POST - if "next" in reqDict: - nextUrl = reqDict["next"] + match request.method: + case "GET": + data = request.GET + case "POST": + data = request.POST + case _: + raise Http404 + + next = data.get("next") + + if next is not None: context = { "pass_url": "{}?next={}".format( - reverse("password_login"), urlquote(nextUrl, safe="") + reverse("password_login"), urlquote(next, safe="") ), "cas_url": "{}?next={}".format( - reverse("cas_ng_login"), urlquote(nextUrl, safe="") + reverse("cas_ng_login"), urlquote(next, safe="") ), } else: @@ -30,13 +37,13 @@ def login(req): "cas_url": reverse("cas_ng_login"), } - return render(req, "mainsite/login.html", context=context) + return render(request, "mainsite/login.html", context=context) @login_required -def logout(req): - CAS_BACKEND_NAME = "django_cas_ng.backends.CASBackend" - if req.session["_auth_user_backend"] != CAS_BACKEND_NAME: - auth_logout(req) +def logout(request: HttpRequest): + if request.session["_auth_user_backend"] != "django_cas_ng.backends.CASBackend": + auth_logout(request) return redirect("homepage") + return redirect("cas_ng_logout") diff --git a/mainsite/models.py b/mainsite/models.py index a8bef7f..a956603 100644 --- a/mainsite/models.py +++ b/mainsite/models.py @@ -19,7 +19,7 @@ class SiteConfiguration(SingletonModel): def __str__(self): return "Configuration du site" - class Meta: + class Meta: # pyright: ignore verbose_name = "Configuration du site"