updated app reachable codes
This commit is contained in:
@@ -342,7 +342,6 @@ def authentication_token_refresh_post(
|
||||
status_code=status.HTTP_406_NOT_ACCEPTABLE,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
return JSONResponse(
|
||||
content={},
|
||||
status_code=status.HTTP_202_ACCEPTED,
|
||||
@@ -374,7 +373,6 @@ def authentication_password_verify_otp(
|
||||
"tz": tz or "GMT+3",
|
||||
"token": token,
|
||||
}
|
||||
print("Token&OTP : ", data.otp, data.token)
|
||||
if not domain or not language:
|
||||
return JSONResponse(
|
||||
content={"error": "EYS_0003"},
|
||||
@@ -419,8 +417,17 @@ def authentication_page_valid(
|
||||
status_code=status.HTTP_406_NOT_ACCEPTABLE,
|
||||
headers=headers,
|
||||
)
|
||||
result = AuthHandlers.PageHandlers.retrieve_valid_page_via_token(
|
||||
page_url=data.page_url, access_token=token
|
||||
)
|
||||
if not result:
|
||||
return JSONResponse(
|
||||
content={"error": "EYS_0004"},
|
||||
status_code=status.HTTP_406_NOT_ACCEPTABLE,
|
||||
headers=headers,
|
||||
)
|
||||
return JSONResponse(
|
||||
content={},
|
||||
content={"application": result},
|
||||
status_code=status.HTTP_202_ACCEPTED,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -59,8 +59,8 @@ class OccupantToken(BaseModel):
|
||||
responsible_employee_id: Optional[int] = None
|
||||
responsible_employee_uuid: Optional[str] = None
|
||||
|
||||
reachable_event_codes: Optional[list[str]] = None # ID list of reachable modules
|
||||
reachable_app_codes: Optional[list[str]] = None # ID list of reachable modules
|
||||
reachable_event_codes: Optional[dict[str, str]] = None # ID list of reachable modules
|
||||
reachable_app_codes: Optional[dict[str, str]] = None # ID list of reachable modules
|
||||
|
||||
|
||||
class CompanyToken(BaseModel):
|
||||
@@ -83,8 +83,8 @@ class CompanyToken(BaseModel):
|
||||
|
||||
bulk_duties_id: int
|
||||
|
||||
reachable_event_codes: Optional[list[str]] = None # ID list of reachable modules
|
||||
reachable_app_codes: Optional[list[str]] = None # ID list of reachable modules
|
||||
reachable_event_codes: Optional[dict[str, str]] = None # ID list of reachable modules
|
||||
reachable_app_codes: Optional[dict[str, str]] = None # ID list of reachable modules
|
||||
|
||||
|
||||
class OccupantTokenObject(ApplicationToken):
|
||||
|
||||
@@ -15,7 +15,7 @@ class RequestVerifyOTP(BaseModel):
|
||||
|
||||
|
||||
class RequestApplication(BaseModel):
|
||||
page: str # /building/create
|
||||
page_url: str # /building/create
|
||||
|
||||
|
||||
class RequestSelectEmployee(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user