diff --git a/app/classes/controllers/users_controller.py b/app/classes/controllers/users_controller.py index d45797bd..7abae8e0 100644 --- a/app/classes/controllers/users_controller.py +++ b/app/classes/controllers/users_controller.py @@ -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, + }, } # ********************************************************************************** diff --git a/app/classes/web/routes/api/users/index.py b/app/classes/web/routes/api/users/index.py index 32ebd283..0b021735 100644 --- a/app/classes/web/routes/api/users/index.py +++ b/app/classes/web/routes/api/users/index.py @@ -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, { diff --git a/app/classes/web/routes/api/users/user/index.py b/app/classes/web/routes/api/users/user/index.py index b05e4ac3..391fc5f5 100644 --- a/app/classes/web/routes/api/users/user/index.py +++ b/app/classes/web/routes/api/users/user/index.py @@ -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": diff --git a/app/translations/en_EN.json b/app/translations/en_EN.json index 26c2f5af..fc2c4422 100644 --- a/app/translations/en_EN.json +++ b/app/translations/en_EN.json @@ -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?",