chore: Small cleanup

This commit is contained in:
Tom Hubrecht 2024-10-23 13:21:36 +02:00
parent 3681bed05d
commit 129e43252a
Signed by: thubrecht
SSH key fingerprint: SHA256:r+nK/SIcWlJ0zFZJGHtlAoRwq1Rm+WcKAm5ADYMoQPc
6 changed files with 29 additions and 24 deletions

View file

@ -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)

View file

@ -37,7 +37,7 @@ class ApiKey(models.Model):
@property
def keyId(self):
return self.id
return self.pk
@property
def displayValue(self):

View file

@ -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

View file

@ -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

View file

@ -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")

View file

@ -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"