Files
kbcrm/App_Server/root/auth/model/errors.py
T
gg 505177b5e2 ProjektUser-Modal: Mehrfachauswahl, Filterung und Fehlermeldungs-Verbesserung
- Modal von Einzelauswahl (Select) auf Mehrfachauswahl mit Checkboxen umgestellt
- Nutzerliste sortiert nach username, scrollbar (eine Zeile pro Nutzer)
- SysAdmin und AppAdmin aus der Auswahlliste ausgeblendet (immer Zugriff)
- Bereits zugeordnete Nutzer ausgeblendet
- Fehleranzeige bei fehlender Rolle: closeModal im catch entfernt,
  sodass showServerError nicht sofort überschrieben wird
- AutorisationError: Meldung "Erforderliche Rollen" nur bei nicht-leerer
  allowed_roles-Liste (entfällt bei @authorisation_required([]))

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-09-05 16:14:13 +02:00

46 lines
1.5 KiB
Python

class ApplicationError(Exception):
def __init__(self, *messages, htmlstatus=400):
self.htmlstatus = htmlstatus
Exception.__init__(self, *messages)
@property
def error(self):
error = {
"status": self.htmlstatus,
"messages": list(self.args)
}
return error
class AutorisationError(ApplicationError):
def __init__(self, allowed_roles=[], user_roles=[]):
self.allowed_roles = allowed_roles
self.user_roles = user_roles
if user_roles is None:
userrolestxt = "NoSysAdmin"
else:
userrolestxt = ", ".join([role.name for role in self.user_roles])
# Die Meldung über erforderliche Rollen nur aufnehmen, wenn
# welche spezifiziert sind. Bei leerer allowed_roles-Liste
# (z.B. Endpunkte, die nur AppAdmin/SysAdmin erlauben) entfällt
# dieser Teil der Fehlermeldung komplett.
messages = [
"Sie haben nicht die passende Rolle für diese Funktion",
"Ihre Rollen sind: " + userrolestxt,
]
if self.allowed_roles:
messages.append("Erforderliche Rollen sind: " + ", ".join(self.allowed_roles))
ApplicationError.__init__(self, *messages, htmlstatus=HtmlStatusCode.Unauthorized)
class HtmlStatusCode():
Bad_Request = 400
Unauthorized = 401
Payment_Required = 402
Forbidden = 403
Not_Found = 404
Method_Not_Allowed = 405