updated account info gathering

This commit is contained in:
2025-02-13 16:41:15 +03:00
parent 533fe1f84e
commit 3bcec2abff
8 changed files with 339 additions and 185 deletions

View File

@@ -2,7 +2,7 @@
Validation function handlers
"""
from typing import Dict, Any
from typing import Dict, Any, Optional
from fastapi import Request
from ApiLayers.AllConfigs.Redis.configs import (
@@ -75,7 +75,7 @@ class RedisValidationRetrieve(ValidateBase):
)
if redis_validation.status:
return redis_validation.first
raise ValueError("Header not found")
raise ValueError("Validation not found")
class ValidationsBoth(RedisHeaderRetrieve, RedisValidationRetrieve):
@@ -155,14 +155,27 @@ class RetrievePage(BaseRouteModel):
raise NotImplementedError("Cluster not found")
@classmethod
def retrieve_page(cls, data: Any):
def retrieve_page(cls, data: Any) -> Optional[Dict[str, Any]]:
"""
Retrieve page by event function code
Check reachable codes for user to render which page and components on Frontend
Uses:
Context Token Retriever to get user information from ACCESS_TOKEN
CategoryCluster Retrieve Cluster Retrieve cluster by name
Check available instructions of page and info user with it
Returns:
NAME=cluster_name.name,
PREFIX=cluster_name.PREFIX,
URL=dict(page_info).get("URL", None),
ICON=dict(page_info).get("ICON", None),
INFO=dict(page_info).get("INFO", None),
SUB_COMPONENTS=sub_components,
"""
from Events.Engine import CategoryCluster
from Events.JustEvents.events_file import retrieve_cluster_by_name
reachable_codes = []
page_name = getattr(data, "page", None)
if cls.context_retriever.token.is_employee:
reachable_codes = (
cls.context_retriever.token.selected_company.reachable_event_codes
@@ -171,46 +184,36 @@ class RetrievePage(BaseRouteModel):
reachable_codes = (
cls.context_retriever.token.selected_occupant.reachable_event_codes
)
cluster_from_all_events = cls.get_site_cluster(page_name=data.page)
cluster_from_all_events = cls.get_site_cluster(page_name=page_name)
if not cluster_from_all_events:
raise ValueError(f"Cluster not found : {data.page}")
raise ValueError(f"Cluster not found : {page_name}")
cluster_name: CategoryCluster = retrieve_cluster_by_name(cluster_from_all_events)
if not cluster_name:
raise ValueError("Cluster not found")
page_info = cluster_name.retrieve_page_info().get(data.page, None)
page_info = cluster_name.retrieve_page_info().get(page_name, None)
if not page_info:
raise ValueError("Page not found")
endpoints: dict = dict(page_info).get("endpoints", {})
if not endpoints:
raise ValueError("Endpoints not found")
sub_components: dict = dict(page_info).get("SUB_COMPONENTS", {})
if not sub_components:
raise ValueError("Sub components not found")
new_page_info_dict = dict(
name=cluster_name.name,
prefix=cluster_name.PREFIX,
url=dict(page_info).get("url", None),
icon=dict(page_info).get("icon", None),
mapping=cluster_name.MAPPING,
page_info=dict(page_info).get("page_info", None),
endpoints={},
language_models={},
instructions={},
NAME=cluster_name.name,
PREFIX=cluster_name.PREFIX,
URL=dict(page_info).get("URL", None),
ICON=dict(page_info).get("ICON", None),
INFO=dict(page_info).get("INFO", None),
SUB_COMPONENTS=sub_components,
# MAPPING=cluster_name.MAPPING,
)
for key, event_codes in dict(endpoints).items():
for key, events in dict(sub_components).items():
# Meaning client can reach this endpoint [] & [] intersection
if set(event_codes) & set(reachable_codes):
language_models = dict(page_info).get("language_models", {})
instructions = dict(page_info).get("instructions", {})
new_page_info_dict["endpoints"][key] = True
if language_models.get(key, None):
if key in language_models[key].keys(): # key has sub key blocks inside lang model
for key_model, val_model in dict(language_models[key]).items():
if key_model in new_page_info_dict["endpoints"].keys():
new_page_info_dict["language_models"][key_model] = language_models[key][key_model]
else:
new_page_info_dict["language_models"][key] = language_models[key]
if instructions.get(key, None):
new_page_info_dict["instructions"][key] = instructions.get(key, None)
return new_page_info_dict
endpoint_event_codes = dict(events).get("ENDPOINTS", [])
new_page_info_dict["SUB_COMPONENTS"][key].pop("ENDPOINTS")
if not set(endpoint_event_codes) & set(reachable_codes):
new_page_info_dict["SUB_COMPONENTS"].pop(key)
return new_page_info_dict

View File

@@ -1,13 +1,13 @@
"""
Validation records request and response models.
"""
from typing import Optional
from pydantic import BaseModel
class ValidationsPydantic(BaseModel):
event_code: str
type: Optional[str] = "REQUEST"
asked_field: Optional[str] = "all"