Refactor users human readable

This commit is contained in:
amcmanu3 2024-08-06 18:24:30 -04:00
parent 693cda4239
commit 8b39ba5549
4 changed files with 61 additions and 17 deletions

View File

@ -38,8 +38,8 @@ class UsersController:
for permission in PermissionsCrafty.get_permissions_list()
],
},
"quantity": {"type": "number", "minimum": -1},
"enabled": {"type": "boolean"},
"quantity": {"type": "number", "minimum": -1, "error": "typeInteger"},
"enabled": {"type": "boolean", "error": "typeBool"},
}
self.user_jsonschema_props: t.Final = {
"username": {
@ -49,6 +49,8 @@ class UsersController:
"pattern": "^[a-z0-9_]+$",
"examples": ["admin"],
"title": "Username",
"error": "typeString",
"fill": True,
},
"password": {
"type": "string",
@ -62,11 +64,15 @@ class UsersController:
"format": "email",
"examples": ["default@example.com"],
"title": "E-Mail",
"error": "typeEmail",
"fill": True,
},
"enabled": {
"type": "boolean",
"examples": [True],
"title": "Enabled",
"error": "typeBool",
"fill": True,
},
"lang": {
"type": "string",
@ -74,16 +80,30 @@ class UsersController:
"minLength": 2,
"examples": ["en"],
"title": "Language",
"error": "typeString",
"fill": True,
},
"superuser": {
"type": "boolean",
"examples": [False],
"title": "Superuser",
"error": "typeBool",
"fill": True,
},
"manager": {
"type": ["integer", "null"],
"error": "typeInteger",
"fill": True,
},
"theme": {
"type": "string",
"error": "typeString",
"fill": True,
},
"manager": {"type": ["integer", "null"]},
"theme": {"type": "string"},
"permissions": {
"type": "array",
"error": "typeList",
"fill": True,
"items": {
"type": "object",
"properties": _permissions_props,
@ -92,13 +112,25 @@ class UsersController:
},
"roles": {
"type": "array",
"error": "typeList",
"fill": True,
"items": {
"type": "integer",
"minLength": 1,
"error": "typeInteger",
"fill": True,
},
},
"hints": {"type": "boolean"},
"server_order": {"type": "string"},
"hints": {
"type": "boolean",
"error": "typeBool",
"fill": True,
},
"server_order": {
"type": "string",
"error": "typeString",
"fill": True,
},
}
# **********************************************************************************

View File

@ -88,12 +88,15 @@ class ApiUsersIndexHandler(BaseApiHandler):
try:
validate(data, new_user_schema)
except ValidationError as e:
err = self.translator.translate(
except ValidationError as why:
offending_key = ""
if why.schema.get("fill", None):
offending_key = why.path[0] if why.path else None
err = f"""{offending_key} {self.translator.translate(
"validators",
e.schema["error"],
why.schema.get("error"),
self.controller.users.get_user_lang_by_id(auth_data[4]["user_id"]),
)
)} {why.schema.get("enum", "")}"""
return self.finish_json(
400,
{

View File

@ -134,13 +134,21 @@ class ApiUsersUserIndexHandler(BaseApiHandler):
)
try:
validate(data, user_patch_schema)
except ValidationError as e:
except ValidationError as why:
offending_key = ""
if why.schema.get("fill", None):
offending_key = why.path[0] if why.path else None
err = f"""{offending_key} {self.translator.translate(
"validators",
why.schema.get("error"),
self.controller.users.get_user_lang_by_id(auth_data[4]["user_id"]),
)} {why.schema.get("enum", "")}"""
return self.finish_json(
400,
{
"status": "error",
"error": "INVALID_JSON_SCHEMA",
"error_data": str(e),
"error_data": f"{str(err)}",
},
)
if user_id == "@me":

View File

@ -680,11 +680,12 @@
"serverExeCommand": "Server execution command must be a string with a minimum length of 1.",
"serverLogPath": "Server log path must be a string with a minimum length of 1",
"taskIntervalType": "Task Interval Type must be one of the following: ",
"typeBool": "Type error: True or False required",
"typeInteger": "Type error: Integer required",
"typeIntMinVal0": "must be an integer with a minimum value of 0",
"typeList": "Type error: List required ",
"typeString": "Type error: String required"
"typeBool": "must be true or false (type boolean)",
"typeEmail": "must be of type email.",
"typeInteger": "must be a number.",
"typeIntMinVal0": "must be an integer with a minimum value of 0.",
"typeList": "must be of type list/array ",
"typeString": "must be of type string."
},
"webhooks": {
"areYouSureDel": "Are you sure you want to delete this webhook?",