mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Refactor users human readable
This commit is contained in:
parent
693cda4239
commit
8b39ba5549
@ -38,8 +38,8 @@ class UsersController:
|
|||||||
for permission in PermissionsCrafty.get_permissions_list()
|
for permission in PermissionsCrafty.get_permissions_list()
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"quantity": {"type": "number", "minimum": -1},
|
"quantity": {"type": "number", "minimum": -1, "error": "typeInteger"},
|
||||||
"enabled": {"type": "boolean"},
|
"enabled": {"type": "boolean", "error": "typeBool"},
|
||||||
}
|
}
|
||||||
self.user_jsonschema_props: t.Final = {
|
self.user_jsonschema_props: t.Final = {
|
||||||
"username": {
|
"username": {
|
||||||
@ -49,6 +49,8 @@ class UsersController:
|
|||||||
"pattern": "^[a-z0-9_]+$",
|
"pattern": "^[a-z0-9_]+$",
|
||||||
"examples": ["admin"],
|
"examples": ["admin"],
|
||||||
"title": "Username",
|
"title": "Username",
|
||||||
|
"error": "typeString",
|
||||||
|
"fill": True,
|
||||||
},
|
},
|
||||||
"password": {
|
"password": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -62,11 +64,15 @@ class UsersController:
|
|||||||
"format": "email",
|
"format": "email",
|
||||||
"examples": ["default@example.com"],
|
"examples": ["default@example.com"],
|
||||||
"title": "E-Mail",
|
"title": "E-Mail",
|
||||||
|
"error": "typeEmail",
|
||||||
|
"fill": True,
|
||||||
},
|
},
|
||||||
"enabled": {
|
"enabled": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"examples": [True],
|
"examples": [True],
|
||||||
"title": "Enabled",
|
"title": "Enabled",
|
||||||
|
"error": "typeBool",
|
||||||
|
"fill": True,
|
||||||
},
|
},
|
||||||
"lang": {
|
"lang": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -74,16 +80,30 @@ class UsersController:
|
|||||||
"minLength": 2,
|
"minLength": 2,
|
||||||
"examples": ["en"],
|
"examples": ["en"],
|
||||||
"title": "Language",
|
"title": "Language",
|
||||||
|
"error": "typeString",
|
||||||
|
"fill": True,
|
||||||
},
|
},
|
||||||
"superuser": {
|
"superuser": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"examples": [False],
|
"examples": [False],
|
||||||
"title": "Superuser",
|
"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": {
|
"permissions": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
|
"error": "typeList",
|
||||||
|
"fill": True,
|
||||||
"items": {
|
"items": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": _permissions_props,
|
"properties": _permissions_props,
|
||||||
@ -92,13 +112,25 @@ class UsersController:
|
|||||||
},
|
},
|
||||||
"roles": {
|
"roles": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
|
"error": "typeList",
|
||||||
|
"fill": True,
|
||||||
"items": {
|
"items": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"minLength": 1,
|
"minLength": 1,
|
||||||
|
"error": "typeInteger",
|
||||||
|
"fill": True,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"hints": {"type": "boolean"},
|
"hints": {
|
||||||
"server_order": {"type": "string"},
|
"type": "boolean",
|
||||||
|
"error": "typeBool",
|
||||||
|
"fill": True,
|
||||||
|
},
|
||||||
|
"server_order": {
|
||||||
|
"type": "string",
|
||||||
|
"error": "typeString",
|
||||||
|
"fill": True,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
# **********************************************************************************
|
# **********************************************************************************
|
||||||
|
@ -88,12 +88,15 @@ class ApiUsersIndexHandler(BaseApiHandler):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
validate(data, new_user_schema)
|
validate(data, new_user_schema)
|
||||||
except ValidationError as e:
|
except ValidationError as why:
|
||||||
err = self.translator.translate(
|
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",
|
"validators",
|
||||||
e.schema["error"],
|
why.schema.get("error"),
|
||||||
self.controller.users.get_user_lang_by_id(auth_data[4]["user_id"]),
|
self.controller.users.get_user_lang_by_id(auth_data[4]["user_id"]),
|
||||||
)
|
)} {why.schema.get("enum", "")}"""
|
||||||
return self.finish_json(
|
return self.finish_json(
|
||||||
400,
|
400,
|
||||||
{
|
{
|
||||||
|
@ -134,13 +134,21 @@ class ApiUsersUserIndexHandler(BaseApiHandler):
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
validate(data, user_patch_schema)
|
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(
|
return self.finish_json(
|
||||||
400,
|
400,
|
||||||
{
|
{
|
||||||
"status": "error",
|
"status": "error",
|
||||||
"error": "INVALID_JSON_SCHEMA",
|
"error": "INVALID_JSON_SCHEMA",
|
||||||
"error_data": str(e),
|
"error_data": f"{str(err)}",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if user_id == "@me":
|
if user_id == "@me":
|
||||||
|
@ -680,11 +680,12 @@
|
|||||||
"serverExeCommand": "Server execution command must be a string with a minimum length of 1.",
|
"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",
|
"serverLogPath": "Server log path must be a string with a minimum length of 1",
|
||||||
"taskIntervalType": "Task Interval Type must be one of the following: ",
|
"taskIntervalType": "Task Interval Type must be one of the following: ",
|
||||||
"typeBool": "Type error: True or False required",
|
"typeBool": "must be true or false (type boolean)",
|
||||||
"typeInteger": "Type error: Integer required",
|
"typeEmail": "must be of type email.",
|
||||||
"typeIntMinVal0": "must be an integer with a minimum value of 0",
|
"typeInteger": "must be a number.",
|
||||||
"typeList": "Type error: List required ",
|
"typeIntMinVal0": "must be an integer with a minimum value of 0.",
|
||||||
"typeString": "Type error: String required"
|
"typeList": "must be of type list/array ",
|
||||||
|
"typeString": "must be of type string."
|
||||||
},
|
},
|
||||||
"webhooks": {
|
"webhooks": {
|
||||||
"areYouSureDel": "Are you sure you want to delete this webhook?",
|
"areYouSureDel": "Are you sure you want to delete this webhook?",
|
||||||
|
Loading…
Reference in New Issue
Block a user