updated reachables

This commit is contained in:
2025-06-15 22:22:29 +03:00
parent 658a26a123
commit 8573c8021b
7 changed files with 42 additions and 33 deletions

View File

@@ -109,6 +109,8 @@ class LoginHandler:
).outerjoin(Addresses, Addresses.id == Companies.official_address_id
).filter(Employees.people_id == found_user.person_id)
list_employees, list_employees_query_all = [], list_employee_query.all()
list_of_available_sites, list_of_event_codes = {}, {}
if not list_employees_query_all:
ValueError("No Employee found for this user")
@@ -117,6 +119,14 @@ class LoginHandler:
for ix, returns in enumerate(list_of_returns):
single_employee[str(returns)] = employee[ix]
list_employees.append(single_employee)
employee_id, employee_uu_id = int(single_employee["Employees.id"]), str(single_employee["Employees.uu_id"])
application_employee_codes = Application2Employee.get_application_codes(employee_id=employee_id, db=db_session)
event_employee_codes = Event2Employee.get_event_codes(employee_id=employee_id, db=db_session)
print("application_employee_codes", application_employee_codes)
print("event_employee_codes", event_employee_codes)
list_of_available_sites.update({employee_uu_id: application_employee_codes})
list_of_event_codes.update({employee_uu_id: event_employee_codes})
companies_uu_id_list, companies_id_list, companies_list, duty_uu_id_list, duty_id_list = [], [], [], [], []
for list_employee in list_employees:
companies_id_list.append(int(list_employee["Companies.id"]))
@@ -131,11 +141,14 @@ class LoginHandler:
"duty": list_employee["Duty.duty_name"],
"company_uuid": str(list_employee["Companies.uu_id"])
})
model_value = EmployeeTokenObject(
user_type=UserType.employee.value, user_uu_id=str(found_user.uu_id), user_id=found_user.id, person_id=found_user.person_id,
person_uu_id=str(list_employees[0]["People.uu_id"]), request=dict(headers.request.headers), domain_list=other_domains_list,
companies_uu_id_list=companies_uu_id_list, companies_id_list=companies_id_list, duty_uu_id_list=duty_uu_id_list, duty_id_list=duty_id_list,
reachable_app_codes=list_of_available_sites, reachable_event_codes=list_of_event_codes,
).model_dump()
print("model_value", model_value)
set_to_redis_dict = dict(
user=found_user, token=model_value,
header_info=dict(language=headers.language, domain=headers.domain, timezone=headers.timezone),
@@ -175,6 +188,7 @@ class LoginHandler:
found_user = user_handler.check_user_exists(access_key=data.access_key, db_session=db_session)
other_domains_list, main_domain = [], ""
redis_handler = RedisHandlers()
list_of_available_sites, list_of_event_codes = {}, {}
with mongo_handler.collection(f"{str(found_user.related_company)}*Domain") as collection:
result = collection.find_one({"user_uu_id": str(found_user.uu_id)})
@@ -221,7 +235,19 @@ class LoginHandler:
user_type=UserType.occupant.value, user_uu_id=str(found_user.uu_id), user_id=found_user.id, person_id=person.id,
person_uu_id=str(person.uu_id), domain_list=other_domains_list, request=dict(headers.request.headers), available_occupants=occupants_selection_dict,
).model_dump()
build_living_space_uu_id = str(living_space.uu_id)
build_living_space_id = int(living_space.id)
application_occupant_codes = Application2Occupant.get_application_codes(build_living_space_id=build_living_space_id, db=db_session)
event_occupant_codes = Event2Occupant.get_event_codes(build_living_space_id=build_living_space_id, db=db_session)
print("application_occupant_codes", application_occupant_codes)
print("event_occupant_codes", event_occupant_codes)
list_of_available_sites.update({build_living_space_uu_id: application_occupant_codes})
list_of_event_codes.update({build_living_space_uu_id: event_occupant_codes})
model_value.update({"reachable_app_codes": list_of_available_sites, "reachable_event_codes": list_of_event_codes})
print("model_value", model_value)
set_redis_dict = dict(user=found_user, token=model_value, header_info=dict(language=language, domain=domain, timezone=timezone))
if access_token := redis_handler.set_object_to_redis(**set_redis_dict):
return {
@@ -319,10 +345,6 @@ class LoginHandler:
filter_endpoints_and_events = db_session.query(EndpointRestriction.operation_uu_id, Events.function_code
).join(EndpointRestriction, EndpointRestriction.id == Events.endpoint_id).filter().all()
reachable_event_codes = {endpoint_name: function_code for endpoint_name, function_code in filter_endpoints_and_events}
# Get reachable applications
reachable_app_codes = Application2Employee.get_application_codes(employee_id=int(result_with_keys_dict['Employees.id']), db=db_session)
add_company = {
"uu_id": str(result_with_keys_dict["Employees.uu_id"]),
"public_name": result_with_keys_dict["Companies.public_name"],