updated services web user selection

This commit is contained in:
2025-06-16 15:52:50 +03:00
parent 8573c8021b
commit b73417a625
14 changed files with 117 additions and 62 deletions

View File

@@ -210,7 +210,7 @@ class LoginHandler:
user_dict = found_user.get_dict()
person_dict = found_user.person.get_dict()
for living_space in living_spaces:
build_part = BuildParts.query.filter(BuildParts.id == living_space.build_parts_id).first()
if not build_part:
@@ -344,7 +344,12 @@ class LoginHandler:
# TODO: erase this bypass later
filter_endpoints_and_events = db_session.query(EndpointRestriction.operation_uu_id, Events.function_code
).join(EndpointRestriction, EndpointRestriction.id == Events.endpoint_id).filter().all()
# Get reachable applications
reachable_app_codes = Application2Employee.get_application_codes(employee_id=int(result_with_keys_dict['Employees.id']), db=db_session)
# Get reachable events
reachable_event_codes = {endpoint_name: function_code for endpoint_name, function_code in filter_endpoints_and_events}
add_company = {
"uu_id": str(result_with_keys_dict["Employees.uu_id"]),
"public_name": result_with_keys_dict["Companies.public_name"],
@@ -356,7 +361,7 @@ class LoginHandler:
redis_handler = RedisHandlers()
user_uu_id = Users.query.filter(Users.person_id == result_with_keys_dict['People.id']).first().uu_id
redis_result = redis_handler.update_token_at_redis(token=access_token, add_payload=add_company, user_uuid=user_uu_id)
return {"selected_uu_id": data.uuid}
return {"selected_uu_id": data.uuid, "reachable_app_codes": reachable_app_codes}
@classmethod
def handle_occupant_selection(cls, access_token: str, data: Any, token_dict: TokenDictType):
@@ -391,7 +396,9 @@ class LoginHandler:
reachable_event_codes = {endpoint_name: function_code for endpoint_name, function_code in filter_endpoints_and_events}
# Get reachable applications
print('selected_build_living_space_first', selected_build_living_space_first.id)
reachable_app_codes = Application2Occupant.get_application_codes(build_living_space_id=selected_build_living_space_first.id, db=db)
print('reachable_app_codes', reachable_app_codes)
build_part = BuildParts.query.filter(BuildParts.id == result_with_keys_dict['BuildParts.id']).first()
if not build_part:
@@ -410,7 +417,7 @@ class LoginHandler:
user_uu_id = Users.query.filter(Users.person_id == result_with_keys_dict['People.id']).first().uu_id
redis_handler.update_token_at_redis(token=access_token, add_payload=add_build_living_space, user_uuid=user_uu_id)
return {"selected_uu_id": data.uuid}
return {"selected_uu_id": data.uuid, "reachable_app_codes": reachable_app_codes}
@classmethod
def authentication_select_company_or_occupant_type(cls, request: Any, data: Any):

View File

@@ -21,14 +21,14 @@ class PageHandlers:
@classmethod
def retrieve_valid_sites_via_token(cls, access_token: str) -> list:
"""
Retrieve valid pages via token. {"access_token": "string"} | Results: list(sites)
"""
""" Retrieve valid pages via token. {"access_token": "string"} | Results: list(sites) """
if result := RedisHandlers.get_object_from_redis(access_token=access_token):
if result.is_employee:
if result.selected_company and result.selected_company.reachable_app_codes:
return result.selected_company.reachable_app_codes.keys()
elif result.is_occupant:
if result.selected_occupant and result.selected_occupant.reachable_app_codes:
return result.selected_occupant.reachable_app_codes.keys()
if result.is_employee and result.selected_company:
employee_uuid = result.selected_company.get("employee_uu_id", "")
if reachable_app_codes_dict := result.reachable_app_codes:
return reachable_app_codes_dict.get(employee_uuid, {}).keys()
elif result.is_occupant and result.selected_occupant:
living_space_uu_id = result.selected_occupant.get("build_living_space_uu_id", "")
if reachable_app_codes_dict := result.reachable_app_codes:
return reachable_app_codes_dict.get(living_space_uu_id, {}).keys()
raise ValueError("EYS_0013")

View File

@@ -211,19 +211,11 @@ class Service2Application(CrudCollection):
__tablename__ = "services2applications"
__exclude__fields__ = []
application_id: Mapped[int] = mapped_column(
ForeignKey("applications.id"), nullable=False
)
application_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Application UUID"
)
application_id: Mapped[int] = mapped_column(ForeignKey("applications.id"), nullable=False)
application_uu_id: Mapped[str] = mapped_column(String, nullable=False, comment="Application UUID")
service_id: Mapped[int] = mapped_column(ForeignKey("services.id"), nullable=False)
service_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Service UUID"
)
application_code: Mapped[str] = mapped_column(
String, nullable=False, comment="Application Code"
)
service_uu_id: Mapped[str] = mapped_column(String, nullable=False, comment="Service UUID")
application_code: Mapped[str] = mapped_column(String, nullable=False, comment="Application Code")
site_url: Mapped[str] = mapped_column(String, nullable=False, comment="Site URL")
__table_args__ = {"comment": "Service2Applications Information"}
@@ -237,13 +229,9 @@ class Event2OccupantExtra(CrudCollection):
build_living_space_id: Mapped[int] = mapped_column(
ForeignKey("build_living_space.id"), nullable=False
)
build_living_space_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Build Living Space UUID"
)
build_living_space_uu_id: Mapped[str] = mapped_column(String, nullable=False, comment="Build Living Space UUID")
event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), nullable=False)
event_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Event UUID"
)
event_uu_id: Mapped[str] = mapped_column(String, nullable=False, comment="Event UUID")
__table_args__ = (
Index(
@@ -265,14 +253,10 @@ class Event2EmployeeExtra(CrudCollection):
__exclude__fields__ = []
employee_id: Mapped[int] = mapped_column(ForeignKey("employees.id"), nullable=False)
employee_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Employee UUID"
)
employee_uu_id: Mapped[str] = mapped_column(String, nullable=False, comment="Employee UUID")
event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), nullable=False)
event_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Event UUID"
)
event_uu_id: Mapped[str] = mapped_column(String, nullable=False, comment="Event UUID")
__table_args__ = (
Index(
@@ -447,12 +431,8 @@ class Application2Occupant(CrudCollection):
__tablename__ = "application2occupant"
__exclude__fields__ = []
build_living_space_id: Mapped[int] = mapped_column(
ForeignKey("build_living_space.id"), nullable=False
)
build_living_space_uu_id = mapped_column(
String, nullable=False, comment="Build Living Space UUID"
)
build_living_space_id: Mapped[int] = mapped_column(ForeignKey("build_living_space.id"), nullable=False)
build_living_space_uu_id = mapped_column(String, nullable=False, comment="Build Living Space UUID")
service_id: Mapped[int] = mapped_column(ForeignKey("services.id"), nullable=False)
service_uu_id = mapped_column(String, nullable=False, comment="Service UUID")
@@ -462,6 +442,7 @@ class Application2Occupant(CrudCollection):
Service2Application.set_session(db)
Applications.set_session(db)
Application2OccupantExtra.set_session(db)
occupant_services = cls.query.filter(cls.build_living_space_id == build_living_space_id).all()
service_ids = [service.service_id for service in occupant_services]
active_applications = Service2Application.query.filter(Service2Application.service_id.in_(service_ids)).all()