root: early spring clean for linting (#8498)
* remove pyright Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove pylint Signed-off-by: Jens Langhammer <jens@goauthentik.io> * replace pylint with ruff Signed-off-by: Jens Langhammer <jens@goauthentik.io> * ruff fix Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * fix UP038 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix DJ012 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix default arg Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix UP031 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * rename stage type to view Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix DJ008 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix remaining upgrade Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix PLR2004 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix B904 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix PLW2901 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix remaining issues Signed-off-by: Jens Langhammer <jens@goauthentik.io> * prevent ruff from breaking the code Signed-off-by: Jens Langhammer <jens@goauthentik.io> * stages/prompt: refactor field building Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * fix tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix lint Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fully remove isort Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io> Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> Co-authored-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
@ -7,7 +7,6 @@ from difflib import get_close_matches
|
||||
from functools import lru_cache
|
||||
from inspect import currentframe
|
||||
from smtplib import SMTPException
|
||||
from typing import Optional
|
||||
from uuid import uuid4
|
||||
|
||||
from django.apps import apps
|
||||
@ -52,6 +51,8 @@ from authentik.stages.email.utils import TemplateEmailMessage
|
||||
from authentik.tenants.models import Tenant
|
||||
|
||||
LOGGER = get_logger()
|
||||
DISCORD_FIELD_LIMIT = 25
|
||||
NOTIFICATION_SUMMARY_LENGTH = 75
|
||||
|
||||
|
||||
def default_event_duration():
|
||||
@ -65,7 +66,7 @@ def default_brand():
|
||||
return sanitize_dict(model_to_dict(DEFAULT_BRAND))
|
||||
|
||||
|
||||
@lru_cache()
|
||||
@lru_cache
|
||||
def django_app_names() -> list[str]:
|
||||
"""Get a cached list of all django apps' names (not labels)"""
|
||||
return [x.name for x in apps.app_configs.values()]
|
||||
@ -198,7 +199,7 @@ class Event(SerializerModel, ExpiringModel):
|
||||
@staticmethod
|
||||
def new(
|
||||
action: str | EventAction,
|
||||
app: Optional[str] = None,
|
||||
app: str | None = None,
|
||||
**kwargs,
|
||||
) -> "Event":
|
||||
"""Create new Event instance from arguments. Instance is NOT saved."""
|
||||
@ -224,7 +225,7 @@ class Event(SerializerModel, ExpiringModel):
|
||||
self.user = get_user(user)
|
||||
return self
|
||||
|
||||
def from_http(self, request: HttpRequest, user: Optional[User] = None) -> "Event":
|
||||
def from_http(self, request: HttpRequest, user: User | None = None) -> "Event":
|
||||
"""Add data from a Django-HttpRequest, allowing the creation of
|
||||
Events independently from requests.
|
||||
`user` arguments optionally overrides user from requests."""
|
||||
@ -418,7 +419,7 @@ class NotificationTransport(SerializerModel):
|
||||
if not isinstance(value, str):
|
||||
continue
|
||||
# https://birdie0.github.io/discord-webhooks-guide/other/field_limits.html
|
||||
if len(fields) >= 25:
|
||||
if len(fields) >= DISCORD_FIELD_LIMIT:
|
||||
continue
|
||||
fields.append({"title": key[:256], "value": value[:1024]})
|
||||
body = {
|
||||
@ -472,7 +473,7 @@ class NotificationTransport(SerializerModel):
|
||||
continue
|
||||
context["key_value"][key] = value
|
||||
else:
|
||||
context["title"] += notification.body[:75]
|
||||
context["title"] += notification.body[:NOTIFICATION_SUMMARY_LENGTH]
|
||||
# TODO: improve permission check
|
||||
if notification.user.is_superuser:
|
||||
context["source"] = {
|
||||
@ -489,7 +490,7 @@ class NotificationTransport(SerializerModel):
|
||||
try:
|
||||
from authentik.stages.email.tasks import send_mail
|
||||
|
||||
return send_mail(mail.__dict__) # pylint: disable=no-value-for-parameter
|
||||
return send_mail(mail.__dict__)
|
||||
except (SMTPException, ConnectionError, OSError) as exc:
|
||||
raise NotificationTransportError(exc) from exc
|
||||
|
||||
@ -533,7 +534,11 @@ class Notification(SerializerModel):
|
||||
return NotificationSerializer
|
||||
|
||||
def __str__(self) -> str:
|
||||
body_trunc = (self.body[:75] + "..") if len(self.body) > 75 else self.body
|
||||
body_trunc = (
|
||||
(self.body[:NOTIFICATION_SUMMARY_LENGTH] + "..")
|
||||
if len(self.body) > NOTIFICATION_SUMMARY_LENGTH
|
||||
else self.body
|
||||
)
|
||||
return f"Notification for user {self.user}: {body_trunc}"
|
||||
|
||||
class Meta:
|
||||
|
||||
Reference in New Issue
Block a user