|
|
|
|
@@ -5,7 +5,10 @@ Validation function handlers
|
|
|
|
|
from typing import Dict, Any
|
|
|
|
|
from fastapi import Request
|
|
|
|
|
|
|
|
|
|
from ApiLayers.AllConfigs.Redis.configs import RedisValidationKeysAction, RedisCategoryKeys
|
|
|
|
|
from ApiLayers.AllConfigs.Redis.configs import (
|
|
|
|
|
RedisValidationKeysAction,
|
|
|
|
|
RedisCategoryKeys,
|
|
|
|
|
)
|
|
|
|
|
from Services.Redis.Actions.actions import RedisActions
|
|
|
|
|
from Events.base_request_model import BaseRouteModel
|
|
|
|
|
|
|
|
|
|
@@ -22,7 +25,7 @@ class ValidateBase:
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def function_codes(self):
|
|
|
|
|
redis_function_codes= RedisActions.get_json(
|
|
|
|
|
redis_function_codes = RedisActions.get_json(
|
|
|
|
|
list_keys=[f"{self.redis_key}{self.url}"]
|
|
|
|
|
)
|
|
|
|
|
if redis_function_codes.status:
|
|
|
|
|
@@ -31,9 +34,13 @@ class ValidateBase:
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def intersection(self):
|
|
|
|
|
intersection = list(set(self.function_codes).intersection(set(self.reachable_codes)))
|
|
|
|
|
intersection = list(
|
|
|
|
|
set(self.function_codes).intersection(set(self.reachable_codes))
|
|
|
|
|
)
|
|
|
|
|
if not len(intersection) == 1:
|
|
|
|
|
raise ValueError("Users reachable function codes does not match or match more than one.")
|
|
|
|
|
raise ValueError(
|
|
|
|
|
"Users reachable function codes does not match or match more than one."
|
|
|
|
|
)
|
|
|
|
|
return intersection[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -44,9 +51,11 @@ class RedisHeaderRetrieve(ValidateBase):
|
|
|
|
|
@property
|
|
|
|
|
def header(self):
|
|
|
|
|
"""
|
|
|
|
|
Headers: Headers which is merged with response model && language models of event
|
|
|
|
|
Headers: Headers which is merged with response model && language models of event
|
|
|
|
|
"""
|
|
|
|
|
redis_header= RedisActions.get_json(list_keys=[f"{self.redis_key}:{self.intersection}"])
|
|
|
|
|
redis_header = RedisActions.get_json(
|
|
|
|
|
list_keys=[f"{self.redis_key}:{self.intersection}"]
|
|
|
|
|
)
|
|
|
|
|
if redis_header.status:
|
|
|
|
|
return redis_header.first
|
|
|
|
|
raise ValueError("Header not found")
|
|
|
|
|
@@ -59,9 +68,11 @@ class RedisValidationRetrieve(ValidateBase):
|
|
|
|
|
@property
|
|
|
|
|
def validation(self):
|
|
|
|
|
"""
|
|
|
|
|
Validation: Validation of event which is merged with response model && language models of event
|
|
|
|
|
Validation: Validation of event which is merged with response model && language models of event
|
|
|
|
|
"""
|
|
|
|
|
redis_validation = RedisActions.get_json(list_keys=[f"{self.redis_key}:{self.intersection}"])
|
|
|
|
|
redis_validation = RedisActions.get_json(
|
|
|
|
|
list_keys=[f"{self.redis_key}:{self.intersection}"]
|
|
|
|
|
)
|
|
|
|
|
if redis_validation.status:
|
|
|
|
|
return redis_validation.first
|
|
|
|
|
raise ValueError("Header not found")
|
|
|
|
|
@@ -72,8 +83,8 @@ class ValidationsBoth(RedisHeaderRetrieve, RedisValidationRetrieve):
|
|
|
|
|
@property
|
|
|
|
|
def both(self) -> Dict[str, Any]:
|
|
|
|
|
"""
|
|
|
|
|
Headers: Headers which is merged with response model && language models of event
|
|
|
|
|
Validation: Validation of event which is merged with response model && language models of event
|
|
|
|
|
Headers: Headers which is merged with response model && language models of event
|
|
|
|
|
Validation: Validation of event which is merged with response model && language models of event
|
|
|
|
|
"""
|
|
|
|
|
return {"headers": self.header, "validation": self.validation}
|
|
|
|
|
|
|
|
|
|
@@ -85,14 +96,23 @@ class RetrieveValidation(BaseRouteModel):
|
|
|
|
|
"""
|
|
|
|
|
Retrieve validation by event function code
|
|
|
|
|
"""
|
|
|
|
|
if getattr(data, 'asked_field', "") not in ValidationsConfig.SUPPORTED_VALIDATIONS:
|
|
|
|
|
raise ValueError(f"Invalid asked field please retry with valid fields {ValidationsConfig.SUPPORTED_VALIDATIONS}")
|
|
|
|
|
if (
|
|
|
|
|
getattr(data, "asked_field", "")
|
|
|
|
|
not in ValidationsConfig.SUPPORTED_VALIDATIONS
|
|
|
|
|
):
|
|
|
|
|
raise ValueError(
|
|
|
|
|
f"Invalid asked field please retry with valid fields {ValidationsConfig.SUPPORTED_VALIDATIONS}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
reachable_codes = []
|
|
|
|
|
if cls.context_retriever.token.is_employee:
|
|
|
|
|
reachable_codes = cls.context_retriever.token.selected_company.reachable_event_codes
|
|
|
|
|
reachable_codes = (
|
|
|
|
|
cls.context_retriever.token.selected_company.reachable_event_codes
|
|
|
|
|
)
|
|
|
|
|
elif cls.context_retriever.token.is_occupant:
|
|
|
|
|
reachable_codes = cls.context_retriever.token.selected_occupant.reachable_event_codes
|
|
|
|
|
reachable_codes = (
|
|
|
|
|
cls.context_retriever.token.selected_occupant.reachable_event_codes
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
validate_dict = dict(url=data.url, reachable_code=reachable_codes)
|
|
|
|
|
if data.asked_field == "all":
|
|
|
|
|
|