39 lines
1.2 KiB
Python
39 lines
1.2 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])
|
|
|
|
ApplicationError.__init__(self,
|
|
"Sie haben nicht die passende Rolle für diese Funktion",
|
|
"Ihre Rollen sind: " + userrolestxt,
|
|
"Erforderliche Rollen sind: " + ", ".join(self.allowed_roles), htmlstatus=HtmlStatusCode.Unauthorized)
|
|
|
|
class HtmlStatusCode():
|
|
Bad_Request = 400
|
|
Unauthorized = 401
|
|
Payment_Required = 402
|
|
Forbidden = 403
|
|
Not_Found = 404
|
|
Method_Not_Allowed = 405
|
|
|
|
|