Dev (#2758)
* fix(chalice): fixed Math-operators validation refactor(chalice): search for sessions that have events for heatmaps * refactor(chalice): search for sessions that have at least 1 location event for heatmaps * fix(chalice): fixed Math-operators validation refactor(chalice): search for sessions that have events for heatmaps * refactor(chalice): search for sessions that have at least 1 location event for heatmaps * feat(chalice): autocomplete return top 10 with stats * fix(chalice): fixed autocomplete top 10 meta-filters * fix(chalice): support special characters for name feat(chalice): return parsable error for alphanumeric exceptions resolve #2713
This commit is contained in:
parent
94b9a492f0
commit
db38f914a8
3 changed files with 25 additions and 8 deletions
|
|
@ -36,6 +36,10 @@ class ORRoute(APIRoute):
|
|||
# 422 validation exception
|
||||
logger.warning(f"!!! 422 exception when calling: {request.method} {request.url}")
|
||||
logger.warning(exc.errors())
|
||||
for e in exc.errors():
|
||||
if e.get("msg", "").endswith("must be alphanumeric"):
|
||||
return JSONResponse(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
content={"errors": [e["msg"][18:]], "detail": str(exc)})
|
||||
raise exc
|
||||
except HTTPException as e:
|
||||
if e.status_code // 100 == 4:
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from pydantic.functional_validators import BeforeValidator
|
|||
from chalicelib.utils.TimeUTC import TimeUTC
|
||||
from .overrides import BaseModel, Enum, ORUnion
|
||||
from .transformers_validators import transform_email, remove_whitespace, remove_duplicate_values, single_to_list, \
|
||||
force_is_event, NAME_PATTERN, int_to_string
|
||||
force_is_event, NAME_PATTERN, int_to_string, check_alphanumeric
|
||||
|
||||
|
||||
def transform_old_filter_type(cls, values):
|
||||
|
|
@ -76,20 +76,23 @@ class UserLoginSchema(_GRecaptcha):
|
|||
|
||||
|
||||
class UserSignupSchema(UserLoginSchema):
|
||||
fullname: str = Field(..., min_length=1, pattern=NAME_PATTERN)
|
||||
organizationName: str = Field(..., min_length=1, pattern=NAME_PATTERN)
|
||||
fullname: str = Field(..., min_length=1)
|
||||
organizationName: str = Field(..., min_length=1)
|
||||
|
||||
_transform_fullname = field_validator('fullname', mode='before')(remove_whitespace)
|
||||
_transform_organizationName = field_validator('organizationName', mode='before')(remove_whitespace)
|
||||
|
||||
_check_alphanumeric = field_validator('fullname', 'organizationName')(check_alphanumeric)
|
||||
|
||||
|
||||
class EditAccountSchema(BaseModel):
|
||||
name: Optional[str] = Field(default=None, pattern=NAME_PATTERN)
|
||||
tenantName: Optional[str] = Field(default=None, pattern=NAME_PATTERN)
|
||||
name: Optional[str] = Field(default=None)
|
||||
tenantName: Optional[str] = Field(default=None)
|
||||
opt_out: Optional[bool] = Field(default=None)
|
||||
|
||||
_transform_name = field_validator('name', mode='before')(remove_whitespace)
|
||||
_transform_tenantName = field_validator('tenantName', mode='before')(remove_whitespace)
|
||||
_check_alphanumeric = field_validator('name', 'tenantName')(check_alphanumeric)
|
||||
|
||||
|
||||
class ForgetPasswordPayloadSchema(_GRecaptcha):
|
||||
|
|
@ -226,12 +229,13 @@ class CreateMemberSchema(BaseModel):
|
|||
|
||||
|
||||
class EditMemberSchema(BaseModel):
|
||||
name: str = Field(..., pattern=NAME_PATTERN)
|
||||
name: str = Field(...)
|
||||
email: EmailStr = Field(...)
|
||||
admin: bool = Field(default=False)
|
||||
|
||||
_transform_email = field_validator('email', mode='before')(transform_email)
|
||||
_transform_name = field_validator('name', mode='before')(remove_whitespace)
|
||||
_check_alphanumeric = field_validator('name')(check_alphanumeric)
|
||||
|
||||
|
||||
class EditPasswordByInvitationSchema(BaseModel):
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
from .overrides import Enum
|
||||
|
||||
from typing import Union, Any, Type
|
||||
|
||||
from pydantic import ValidationInfo
|
||||
|
||||
from .overrides import Enum
|
||||
|
||||
NAME_PATTERN = r"^[a-z,A-Z,0-9,\-,é,è,à,ç, ,|,&,\/,\\,_,.,#]*$"
|
||||
|
||||
|
||||
|
|
@ -45,3 +47,10 @@ def force_is_event(events_enum: list[Type[Enum]]):
|
|||
return value
|
||||
|
||||
return fn
|
||||
|
||||
|
||||
def check_alphanumeric(v: str, info: ValidationInfo) -> str:
|
||||
if isinstance(v, str):
|
||||
is_alphanumeric = v.replace(' ', '').isalnum()
|
||||
assert is_alphanumeric, f'{info.field_name} must be alphanumeric'
|
||||
return v
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue