updated app reachable codes

This commit is contained in:
2025-04-09 11:51:28 +03:00
parent 7eadadbd1d
commit 7c2150a8b0
23 changed files with 1040 additions and 187 deletions

View File

@@ -29,14 +29,16 @@ from Schemas import (
)
from Modules.Token.password_module import PasswordModule
from Schemas.building.build import RelationshipEmployee2Build
from Schemas.event.event import Event2Occupant
from Schemas.event.event import Event2Occupant, Application2Employee
from Controllers.Redis.database import RedisActions
from Controllers.Mongo.database import mongo_handler
TokenDictType = Union[EmployeeTokenObject, OccupantTokenObject]
class RedisHandlers:
AUTH_TOKEN: str = "AUTH_TOKEN"
@classmethod
@@ -79,9 +81,7 @@ class RedisHandlers:
return generated_access_token
@classmethod
def update_token_at_redis(
cls, token: str, add_payload: Union[CompanyToken, OccupantToken]
):
def update_token_at_redis(cls, token: str, add_payload: Union[CompanyToken, OccupantToken]):
if already_token_data := RedisActions.get_json(
list_keys=[RedisHandlers.AUTH_TOKEN, token, "*"]
).first:
@@ -124,9 +124,7 @@ class UserHandlers:
return found_user
@staticmethod
def check_password_valid(
domain: str, id_: str, password: str, password_hashed: str
) -> bool:
def check_password_valid(domain: str, id_: str, password: str, password_hashed: str) -> bool:
"""
Check if the password is valid.
"""
@@ -144,6 +142,10 @@ class UserHandlers:
return True
raise ValueError("EYS_0004")
@staticmethod
def update_password():
return
class LoginHandler:
@@ -156,9 +158,7 @@ class LoginHandler:
return str(email).split("@")[1] == api_config.ACCESS_EMAIL_EXT
@classmethod
def do_employee_login(
cls, request: Any, data: Any, extra_dict: Optional[Dict[str, Any]] = None
):
def do_employee_login(cls, request: Any, data: Any, extra_dict: Optional[Dict[str, Any]] = None):
"""
Handle employee login.
"""
@@ -268,9 +268,7 @@ class LoginHandler:
raise ValueError("Something went wrong")
@classmethod
def do_employee_occupant(
cls, request: Any, data: Any, extra_dict: Optional[Dict[str, Any]] = None
):
def do_employee_occupant(cls, request: Any, data: Any, extra_dict: Optional[Dict[str, Any]] = None):
"""
Handle occupant login.
"""
@@ -421,9 +419,7 @@ class LoginHandler:
return request.headers.get(api_config.ACCESS_TOKEN_TAG)
@classmethod
def handle_employee_selection(
cls, access_token: str, data: Any, token_dict: TokenDictType
):
def handle_employee_selection(cls, access_token: str, data: Any, token_dict: TokenDictType):
with Users.new_session() as db:
if data.company_uu_id not in token_dict.companies_uu_id_list:
ValueError("EYS_0011")
@@ -479,6 +475,10 @@ class LoginHandler:
db=db,
).data
reachable_app_codes = Application2Employee.get_application_codes(
employee_id=employee.id, db=db
)
# Create company token
company_token = CompanyToken(
company_uu_id=selected_company.uu_id.__str__(),
@@ -493,6 +493,7 @@ class LoginHandler:
employee_id=employee.id,
employee_uu_id=employee.uu_id.__str__(),
reachable_event_codes=reachable_event_codes,
reachable_app_codes=reachable_app_codes
)
redis_handler = RedisHandlers()
redis_result = redis_handler.update_token_at_redis(
@@ -503,9 +504,7 @@ class LoginHandler:
}
@classmethod
def handle_occupant_selection(
cls, access_token: str, data: Any, token_dict: TokenDictType
):
def handle_occupant_selection(cls, access_token: str, data: Any, token_dict: TokenDictType):
"""Handle occupant type selection"""
with BuildLivingSpace.new_session() as db:
# Get selected occupant type
@@ -707,6 +706,22 @@ class PasswordHandler:
return found_user
class PageHandlers:
@classmethod
def retrieve_valid_page_via_token(cls, access_token: str, page_url: str):
if result := RedisHandlers.get_object_from_redis(access_token=access_token):
if result.is_employee:
if application := result.selected_company.reachable_app_codes.get(page_url, None):
return application
elif result.is_occupant:
if application := result.selected_company.reachable_app_codes.get(page_url, None):
return application
raise ValueError("EYS_0013")
class AuthHandlers:
LoginHandler: LoginHandler = LoginHandler()
PasswordHandler: PasswordHandler = PasswordHandler()
PageHandlers: PageHandlers = PageHandlers()