base context for wrappers updated
This commit is contained in:
@@ -15,7 +15,9 @@ from ApiValidations.Custom.token_objects import CompanyToken
|
||||
from ApiValidations.Request.authentication import (
|
||||
Login,
|
||||
EmployeeSelectionValidation,
|
||||
OccupantSelectionValidation, OccupantSelection, EmployeeSelection,
|
||||
OccupantSelectionValidation,
|
||||
OccupantSelection,
|
||||
EmployeeSelection,
|
||||
)
|
||||
from ErrorHandlers import HTTPExceptionApi
|
||||
from Schemas.company.company import Companies
|
||||
@@ -39,10 +41,7 @@ from .models import (
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from fastapi import Request
|
||||
from ApiServices.Token.token_handler import (
|
||||
OccupantTokenObject,
|
||||
EmployeeTokenObject
|
||||
)
|
||||
from ApiServices.Token.token_handler import OccupantTokenObject, EmployeeTokenObject
|
||||
|
||||
# Type aliases for common types
|
||||
TokenDictType = Union["EmployeeTokenObject", "OccupantTokenObject"]
|
||||
@@ -116,7 +115,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
lang=token_dict.lang,
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg="Company not found in token"
|
||||
sys_msg="Company not found in token",
|
||||
)
|
||||
selected_company = Companies.filter_one(
|
||||
Companies.uu_id == data.company_uu_id,
|
||||
@@ -127,7 +126,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
lang=token_dict.lang,
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg="Company not found in token"
|
||||
sys_msg="Company not found in token",
|
||||
)
|
||||
|
||||
# Get department IDs for the company
|
||||
@@ -142,12 +141,17 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
# Get duties IDs for the company
|
||||
duties_ids = [
|
||||
duty.id
|
||||
for duty in Duties.filter_all(Duties.company_id == selected_company.id, db=db_session).data
|
||||
for duty in Duties.filter_all(
|
||||
Duties.company_id == selected_company.id, db=db_session
|
||||
).data
|
||||
]
|
||||
|
||||
# Get staff IDs
|
||||
staff_ids = [
|
||||
staff.id for staff in Staff.filter_all(Staff.duties_id.in_(duties_ids), db=db_session).data
|
||||
staff.id
|
||||
for staff in Staff.filter_all(
|
||||
Staff.duties_id.in_(duties_ids), db=db_session
|
||||
).data
|
||||
]
|
||||
|
||||
# Get employee
|
||||
@@ -162,7 +166,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
lang=token_dict.lang,
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg="Employee not found in token"
|
||||
sys_msg="Employee not found in token",
|
||||
)
|
||||
|
||||
# Get reachable events
|
||||
@@ -173,7 +177,9 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
# Get staff and duties
|
||||
staff = Staff.filter_one(Staff.id == employee.staff_id, db=db_session).data
|
||||
duties = Duties.filter_one(Duties.id == staff.duties_id, db=db_session).data
|
||||
department = Departments.filter_one(Departments.id == duties.department_id, db=db_session).data
|
||||
department = Departments.filter_one(
|
||||
Departments.id == duties.department_id, db=db_session
|
||||
).data
|
||||
|
||||
# Get bulk duty
|
||||
bulk_id = Duty.filter_by_one(system=True, duty_code="BULK", db=db_session).data
|
||||
@@ -199,12 +205,17 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
employee_uu_id=employee.uu_id.__str__(),
|
||||
reachable_event_list_id=reachable_event_list_id,
|
||||
)
|
||||
try: # Update Redis
|
||||
update_token = TokenService.update_token_at_redis(request=request, add_payload=company_token)
|
||||
try: # Update Redis
|
||||
update_token = TokenService.update_token_at_redis(
|
||||
request=request, add_payload=company_token
|
||||
)
|
||||
return update_token
|
||||
except Exception as e:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="", lang="en", loc=get_line_number_for_error(), sys_msg=f"{e}"
|
||||
error_code="",
|
||||
lang="en",
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg=f"{e}",
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -42,7 +42,11 @@ from .models import (
|
||||
RememberRequestModel,
|
||||
)
|
||||
from ApiEvents.base_request_model import DictRequestModel, EndpointBaseRequestModel
|
||||
from ApiEvents.abstract_class import RouteFactoryConfig, EndpointFactoryConfig, endpoint_wrapper
|
||||
from ApiEvents.abstract_class import (
|
||||
RouteFactoryConfig,
|
||||
EndpointFactoryConfig,
|
||||
endpoint_wrapper,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from fastapi import Request
|
||||
@@ -51,6 +55,7 @@ from ApiValidations.Custom.token_objects import EmployeeTokenObject, OccupantTok
|
||||
|
||||
# Type aliases for common types
|
||||
|
||||
|
||||
@endpoint_wrapper("/authentication/select")
|
||||
async def authentication_select_company_or_occupant_type(
|
||||
request: "Request",
|
||||
@@ -64,7 +69,7 @@ async def authentication_select_company_or_occupant_type(
|
||||
data = EmployeeSelection(**data.data)
|
||||
elif data.data.get("build_living_space_uu_id"):
|
||||
data = OccupantSelection(**data.data)
|
||||
if r := await AuthenticationSelectEventMethods.authentication_select_company_or_occupant_type(
|
||||
if await AuthenticationSelectEventMethods.authentication_select_company_or_occupant_type(
|
||||
request=request, data=data, token_dict=auth_dict
|
||||
):
|
||||
if isinstance(data, EmployeeSelection):
|
||||
@@ -100,7 +105,6 @@ async def authentication_check_token_is_valid(
|
||||
}
|
||||
|
||||
|
||||
|
||||
@endpoint_wrapper("/authentication/refresh")
|
||||
async def authentication_refresh_user_info(
|
||||
request: "Request",
|
||||
@@ -139,6 +143,7 @@ async def authentication_create_password(
|
||||
"status": "OK",
|
||||
}
|
||||
|
||||
|
||||
@endpoint_wrapper("/authentication/forgot-password")
|
||||
async def authentication_forgot_password(
|
||||
request: "Request",
|
||||
@@ -151,6 +156,7 @@ async def authentication_forgot_password(
|
||||
"status": "OK",
|
||||
}
|
||||
|
||||
|
||||
@endpoint_wrapper("/authentication/reset-password")
|
||||
async def authentication_reset_password(
|
||||
request: "Request",
|
||||
@@ -163,6 +169,7 @@ async def authentication_reset_password(
|
||||
"status": "OK",
|
||||
}
|
||||
|
||||
|
||||
@endpoint_wrapper("/authentication/disconnect")
|
||||
async def authentication_disconnect_user(
|
||||
request: "Request",
|
||||
|
||||
@@ -12,15 +12,16 @@ if TYPE_CHECKING:
|
||||
|
||||
class TokenObjectBase(BaseModel):
|
||||
"""Base model for token objects."""
|
||||
|
||||
user_type: str = Field(..., description="Type of user")
|
||||
user_id: str = Field(..., description="User ID")
|
||||
token: str = Field(..., description="Authentication token")
|
||||
permissions: Dict[str, Any] = Field(default_factory=dict, description="User permissions")
|
||||
|
||||
permissions: Dict[str, Any] = Field(description="User permissions")
|
||||
|
||||
|
||||
class LoginData(TypedDict):
|
||||
"""Type for login data."""
|
||||
|
||||
domain: str
|
||||
access_key: str
|
||||
password: str
|
||||
@@ -29,13 +30,14 @@ class LoginData(TypedDict):
|
||||
|
||||
class LoginRequestModel(BaseRequestModel[LoginData]):
|
||||
"""Request model for login endpoint."""
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"domain": "example.com",
|
||||
"access_key": "user@example",
|
||||
"password": "password",
|
||||
"remember_me": False
|
||||
"remember_me": False,
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -43,96 +45,90 @@ class LoginRequestModel(BaseRequestModel[LoginData]):
|
||||
|
||||
class LogoutData(TypedDict):
|
||||
"""Type for logout data."""
|
||||
|
||||
token: str
|
||||
|
||||
|
||||
class LogoutRequestModel(BaseRequestModel[LogoutData]):
|
||||
"""Request model for logout endpoint."""
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"token": "your-token-here"
|
||||
}
|
||||
}
|
||||
json_schema_extra={"example": {"token": "your-token-here"}}
|
||||
)
|
||||
|
||||
|
||||
class RememberData(TypedDict):
|
||||
"""Type for remember token data."""
|
||||
|
||||
remember_token: str
|
||||
|
||||
|
||||
class RememberRequestModel(BaseRequestModel[RememberData]):
|
||||
"""Request model for remember token endpoint."""
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"remember_token": "your-remember-token-here"
|
||||
}
|
||||
}
|
||||
json_schema_extra={"example": {"remember_token": "your-remember-token-here"}}
|
||||
)
|
||||
|
||||
|
||||
class ForgotData(TypedDict):
|
||||
"""Type for forgot password data."""
|
||||
|
||||
email: str
|
||||
domain: str
|
||||
|
||||
|
||||
class ForgotRequestModel(BaseRequestModel[ForgotData]):
|
||||
"""Request model for forgot password endpoint."""
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"email": "user@example.com",
|
||||
"domain": "example.com"
|
||||
}
|
||||
"example": {"email": "user@example.com", "domain": "example.com"}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class ChangePasswordData(TypedDict):
|
||||
"""Type for change password data."""
|
||||
|
||||
old_password: str
|
||||
new_password: str
|
||||
|
||||
|
||||
class ChangePasswordRequestModel(BaseRequestModel[ChangePasswordData]):
|
||||
"""Request model for change password endpoint."""
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"old_password": "old-pass",
|
||||
"new_password": "new-pass"
|
||||
}
|
||||
"example": {"old_password": "old-pass", "new_password": "new-pass"}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class CreatePasswordData(TypedDict):
|
||||
"""Type for create password data."""
|
||||
|
||||
token: str
|
||||
password: str
|
||||
|
||||
|
||||
class CreatePasswordRequestModel(BaseRequestModel[CreatePasswordData]):
|
||||
"""Request model for create password endpoint."""
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"token": "password-creation-token",
|
||||
"password": "new-password"
|
||||
}
|
||||
"example": {"token": "password-creation-token", "password": "new-password"}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class SelectionDataOccupant(BaseModel):
|
||||
"""Type for selection data."""
|
||||
|
||||
build_living_space_uu_id: Optional[str]
|
||||
|
||||
|
||||
class SelectionDataEmployee(BaseModel):
|
||||
"""Type for selection data."""
|
||||
company_uu_id: Optional[str]
|
||||
|
||||
company_uu_id: Optional[str]
|
||||
|
||||
Reference in New Issue
Block a user