updated response models and event validations

This commit is contained in:
2024-12-11 19:54:36 +03:00
parent 3c8ec13dfe
commit 1b15b77036
13 changed files with 453 additions and 102 deletions

View File

@@ -49,61 +49,37 @@ def user_list(request: Request, validation: EndpointValidation):
status_code=status.HTTP_401_UNAUTHORIZED,
detail=f"This endpoint {str(validation.endpoint)} is not active for this user, please contact your responsible company for further information.",
)
if valid_token.user_type == 1:
if not valid_token.selected_company:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Selected company is not found in the token object.",
)
selected_event = Events.filter_one(
Events.endpoint_id == endpoint_active.id,
Events.id.in_(valid_token.selected_company.reachable_event_list_id),
).data
if not selected_event:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="This endpoint requires event validation. Please contact your responsible company to use this event.",
)
active_validation = retrieve_validation_from_class(selected_event, events)
if not active_validation:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="This endpoint requires event validation. Please contact your responsible company to use this event.",
)
headers = getattr(
active_validation, str(valid_token.lang).lower(), active_validation.tr
if valid_token.user_type == 1 and not valid_token.selected_company:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Selected company is not found in the token object.",
)
return EndpointValidationResponse(
language=valid_token.lang,
headers=headers,
validation=active_validation.model_json_schema(),
elif valid_token.user_type == 2 and not valid_token.selected_occupant:
raise HTTPException(
status_code=status.HTTP_418_IM_A_TEAPOT,
detail="Selected occupant is not found in the token object.",
)
elif valid_token.user_type == 2:
if not valid_token.selected_occupant:
raise HTTPException(
status_code=status.HTTP_418_IM_A_TEAPOT,
detail="Selected occupant is not found in the token object.",
)
selected_event = Events.filter_one(
Events.endpoint_id == endpoint_active.id,
Events.id.in_(valid_token.selected_occupant.reachable_event_list_id),
).data
if not selected_event:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=f"This endpoint {str(validation.endpoint)} requires event validation. Please contact your responsible company to use this event.",
)
active_validation = retrieve_validation_from_class(selected_event, events)
if not active_validation:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=f"This endpoint {str(validation.endpoint)} requires event validation. Please contact your responsible company to use this event.",
)
headers = getattr(
active_validation, str(valid_token.lang), active_validation.tr
selected_event = Events.filter_one(
Events.endpoint_id == endpoint_active.id,
Events.id.in_(valid_token.selected_company.reachable_event_list_id),
).data
if not selected_event:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="This endpoint requires event validation. Please contact your responsible company to use this event.",
)
return EndpointValidationResponse(
language=valid_token.lang,
headers=headers,
validation=active_validation.model_json_schema(),
active_validation = retrieve_validation_from_class(selected_event, events)
if not active_validation:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="No validation found for this endpoint.",
)
headers = getattr(
active_validation, str(valid_token.lang).lower(), active_validation.tr
)
print('headers', headers)
return EndpointValidationResponse(
language=valid_token.lang,
headers=headers,
validation=active_validation.model_json_schema(),
)