From 8573c8021b073714d68b7949396e3c1274ab7b27 Mon Sep 17 00:00:00 2001 From: Berkay Date: Sun, 15 Jun 2025 22:22:29 +0300 Subject: [PATCH] updated reachables --- ServicesApi/Builds/Auth/events/auth/events.py | 32 ++++++++++++++++--- .../Restriction/endpoints/pages/router.py | 1 - .../Extensions/OnMemory/redis_handlers.py | 1 - ServicesApi/Schemas/event/event.py | 3 ++ ServicesApi/Validations/token/validations.py | 21 ++++-------- .../src/fetchers/custom/login/login.tsx | 17 +++------- .../src/fetchers/custom/restriction/fetch.tsx | 0 7 files changed, 42 insertions(+), 33 deletions(-) create mode 100644 ServicesWeb/customer/src/fetchers/custom/restriction/fetch.tsx diff --git a/ServicesApi/Builds/Auth/events/auth/events.py b/ServicesApi/Builds/Auth/events/auth/events.py index 8978c82..660a581 100644 --- a/ServicesApi/Builds/Auth/events/auth/events.py +++ b/ServicesApi/Builds/Auth/events/auth/events.py @@ -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"], diff --git a/ServicesApi/Builds/Restriction/endpoints/pages/router.py b/ServicesApi/Builds/Restriction/endpoints/pages/router.py index fdba8ca..141ef90 100644 --- a/ServicesApi/Builds/Restriction/endpoints/pages/router.py +++ b/ServicesApi/Builds/Restriction/endpoints/pages/router.py @@ -22,7 +22,6 @@ def authentication_page_valid(data: RequestApplication, headers: CommonHeaders = page: { url = /building/create} | result: { "application": "4c11f5ef-0bbd-41ac-925e-f79d9aac2b0e" } """ list_of = PageHandlers.retrieve_valid_page_via_token(access_token=headers.token, page_url=data.page) - print('list_of', list_of) return {"completed": True, "application": list_of} diff --git a/ServicesApi/Extensions/OnMemory/redis_handlers.py b/ServicesApi/Extensions/OnMemory/redis_handlers.py index 36ebaf7..17bd866 100644 --- a/ServicesApi/Extensions/OnMemory/redis_handlers.py +++ b/ServicesApi/Extensions/OnMemory/redis_handlers.py @@ -61,7 +61,6 @@ class RedisHandlers: elif already_token.is_occupant: already_token.selected_occupant = add_payload list_keys = [cls.AUTH_TOKEN, token, str(user_uuid)] - print("already_token", already_token) result = RedisActions.set_json(list_keys=list_keys, value=already_token.model_dump(), expires={"hours": 1, "minutes": 30}) return result.first raise ValueError("Something went wrong") diff --git a/ServicesApi/Schemas/event/event.py b/ServicesApi/Schemas/event/event.py index a41e676..a91f43d 100644 --- a/ServicesApi/Schemas/event/event.py +++ b/ServicesApi/Schemas/event/event.py @@ -374,6 +374,8 @@ class Event2Occupant(CrudCollection): cls.set_session(db) Service2Events.set_session(db) Events.set_session(db) + Event2OccupantExtra.set_session(db) + occupant_events = cls.query.filter(cls.build_living_space_id == build_living_space_id).all() service_ids = list(set([event.event_service_id for event in occupant_events])) active_event_ids = Service2Events.query.filter(Service2Events.service_id.in_(service_ids)).all() @@ -409,6 +411,7 @@ class Application2Employee(CrudCollection): Service2Application.set_session(db) Applications.set_session(db) Application2EmployeeExtra.set_session(db) + employee_services = cls.query.filter(cls.employee_id == employee_id).all() service_ids = [service.service_id for service in employee_services] active_applications = Service2Application.query.filter(Service2Application.service_id.in_(service_ids)).all() diff --git a/ServicesApi/Validations/token/validations.py b/ServicesApi/Validations/token/validations.py index bcab34a..d38d9f7 100644 --- a/ServicesApi/Validations/token/validations.py +++ b/ServicesApi/Validations/token/validations.py @@ -1,7 +1,6 @@ from enum import Enum from pydantic import BaseModel -from typing import Optional, Union - +from typing import Optional, Union, Any class UserType(Enum): @@ -30,6 +29,12 @@ class ApplicationToken(BaseModel): request: Optional[dict] = None # Request Info of Client expires_at: Optional[float] = None # Expiry timestamp + # ID list of reachable event codes as "endpoint_code": ["UUID", "UUID"] + reachable_event_codes: Optional[dict[str, Any]] = None + + # ID list of reachable applications as "page_url": ["UUID", "UUID"] + reachable_app_codes: Optional[dict[str, Any]] = None + class OccupantToken(BaseModel): @@ -52,12 +57,6 @@ class OccupantToken(BaseModel): responsible_employee_id: Optional[int] = None responsible_employee_uuid: Optional[str] = None - # ID list of reachable event codes as "endpoint_code": ["UUID", "UUID"] - reachable_event_codes: Optional[dict[str, str]] = None - - # ID list of reachable applications as "page_url": ["UUID", "UUID"] - reachable_app_codes: Optional[dict[str, str]] = None - class CompanyToken(BaseModel): @@ -78,12 +77,6 @@ class CompanyToken(BaseModel): employee_uu_id: str bulk_duties_id: int - # ID list of reachable event codes as "endpoint_code": ["UUID", "UUID"] - reachable_event_codes: Optional[dict[str, str]] = None - - # ID list of reachable applications as "page_url": ["UUID", "UUID"] - reachable_app_codes: Optional[dict[str, str]] = None - class OccupantTokenObject(ApplicationToken): # Occupant Token Object -> Requires selection of the occupant type for a specific build part diff --git a/ServicesWeb/customer/src/fetchers/custom/login/login.tsx b/ServicesWeb/customer/src/fetchers/custom/login/login.tsx index 82d6518..42efd2d 100644 --- a/ServicesWeb/customer/src/fetchers/custom/login/login.tsx +++ b/ServicesWeb/customer/src/fetchers/custom/login/login.tsx @@ -121,10 +121,7 @@ async function loginViaAccessKeys(payload: LoginViaAccessKeys) { completed: true, message: "Login successful", status: 200, - data: { - userType, - firstSelection, - }, + data: { userType, firstSelection }, }; } catch (error) { console.error("JSON parse error:", error); @@ -132,10 +129,7 @@ async function loginViaAccessKeys(payload: LoginViaAccessKeys) { completed: false, message: "Login NOT successful", status: 401, - data: { - userType, - firstSelection, - }, + data: { userType, firstSelection }, }; } } @@ -162,8 +156,8 @@ async function loginSelectEmployee(payload: LoginSelect) { const selectResponse: any = await fetchDataWithToken(urlLoginSelectEndpoint, { uuid: employeeUUID }, "POST", false); if (selectResponse.status === 200 || selectResponse.status === 202) { try { - console.log("selectResponse", selectResponse) - // Get Menu URL's of Employee + console.log("selectResponse", selectResponse) // Get Menu URL's of Employee + } catch (error) { } } return selectResponse; @@ -174,8 +168,7 @@ async function loginSelectOccupant(payload: LoginSelect) { const selectResponse: any = await fetchDataWithToken(urlLoginSelectEndpoint, { uuid: livingSpaceUUID }, "POST", false); if (selectResponse.status === 200 || selectResponse.status === 202) { try { - console.log("selectResponse", selectResponse) - // Get Menu URL's of Occupant + console.log("selectResponse", selectResponse) // Get Menu URL's of Occupant } catch (error) { } } return selectResponse; diff --git a/ServicesWeb/customer/src/fetchers/custom/restriction/fetch.tsx b/ServicesWeb/customer/src/fetchers/custom/restriction/fetch.tsx new file mode 100644 index 0000000..e69de29