updated reachables
This commit is contained in:
parent
658a26a123
commit
8573c8021b
|
|
@ -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"],
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue