events updated

This commit is contained in:
2024-11-13 10:38:00 +03:00
parent 952d742999
commit 077d264b28
48 changed files with 277300 additions and 913 deletions

View File

@@ -63,7 +63,7 @@ class AuthenticationLoginEventMethods(MethodToEvent):
def authentication_login_with_domain_and_creds(
cls,
data: Login,
request,
request: Request,
):
access_dict = Users.login_user_with_credentials(data=data, request=request)
found_user = access_dict.get("user", None)
@@ -75,7 +75,7 @@ class AuthenticationLoginEventMethods(MethodToEvent):
if not access_object:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="This User has no active role registered. Please contact your administrator."
detail="This User has no active role registered. Please contact your administrator.",
)
return JSONResponse(
@@ -103,7 +103,6 @@ class AuthenticationSelectEventMethods(MethodToEvent):
cls,
request: Request,
data,
token_dict: typing.Union[EmployeeSelection, OccupantSelection],
):
from api_objects.auth.token_objects import OccupantToken, CompanyToken
@@ -118,13 +117,13 @@ class AuthenticationSelectEventMethods(MethodToEvent):
status_code=status.HTTP_401_UNAUTHORIZED,
)
if selected_company := Companies.filter_one(
Companies.uu_id==data.company_uu_id,
*Companies.valid_record_args(Companies),
Companies.uu_id == data.company_uu_id,
*Companies.valid_record_args(Companies),
).data:
department_ids = [
department.id
for department in Departments.filter_all(
Departments.company_id==selected_company.id,
Departments.company_id == selected_company.id,
*Departments.valid_record_args(Departments),
).data
]
@@ -197,13 +196,17 @@ class AuthenticationSelectEventMethods(MethodToEvent):
status_code=status.HTTP_200_OK,
)
elif token_user.user_type == 2:
occupant_type = OccupantTypes.filter_by_one(system=True, uu_id=data.occupant_uu_id).data
occupant_type = OccupantTypes.filter_by_one(
system=True, uu_id=data.occupant_uu_id
).data
if not occupant_type:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Occupant Type is not found",
)
build_part = BuildParts.filter_by_one(system=True, uu_id=data.build_part_uu_id).data
build_part = BuildParts.filter_by_one(
system=True, uu_id=data.build_part_uu_id
).data
if not build_part:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
@@ -280,7 +283,8 @@ class AuthenticationCheckTokenEventMethods(MethodToEvent):
@classmethod
def authentication_login_with_domain_and_creds(
cls, request, token_dict: dict = None
cls,
request,
):
if get_object_via_access_key(request=request):
return JSONResponse(
@@ -301,8 +305,10 @@ class AuthenticationRefreshEventMethods(MethodToEvent):
}
@classmethod
def authentication_refresh_user_info(cls, request, token_dict: dict = None):
def authentication_refresh_user_info(
cls,
request,
):
access_token = str(request.headers.get(Auth.ACCESS_TOKEN_TAG))
if token_user := get_object_via_access_key(request=request):
if found_user := Users.filter_one(
@@ -344,7 +350,7 @@ class AuthenticationChangePasswordEventMethods(MethodToEvent):
def authentication_change_password(
cls,
data: ChangePassword,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
token_dict: typing.Union[EmployeeSelection, OccupantSelection]
):
if token_dict.user_type == 1:
if found_user := Users.filter_one(
@@ -381,7 +387,10 @@ class AuthenticationCreatePasswordEventMethods(MethodToEvent):
}
@classmethod
def authentication_create_password(cls, data: CreatePassword):
def authentication_create_password(
cls,
data: CreatePassword,
):
if not data.re_password == data.password:
raise HTTPException(
status_code=status.HTTP_406_NOT_ACCEPTABLE, detail="Password must match"
@@ -451,7 +460,7 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
token_user = json.loads(redis_cli.get(key) or {})
redis_cli.delete(key)
selected_user = Users.filter_one(
Users.uu_id==token_user.get("uu_id"),
Users.uu_id == token_user.get("uu_id"),
*Users.valid_record_args(Users),
)
selected_user.remove_refresher_token(
@@ -512,7 +521,7 @@ class AuthenticationLogoutEventMethods(MethodToEvent):
if token_dict.domain == data.domain:
redis_cli.delete(token_user)
selected_user = Users.filter_one(
Users.uu_id==token_user.get("uu_id"),
Users.uu_id == token_user.get("uu_id"),
*Users.valid_record_args(Users),
)
selected_user.remove_refresher_token(domain=data.domain)
@@ -550,7 +559,10 @@ class AuthenticationRefreshTokenEventMethods(MethodToEvent):
@classmethod
def authentication_refresher_token(
cls, request: Request, data: Remember, token_dict: dict = None
cls,
request: Request,
data: Remember,
token_dict: typing.Union[EmployeeSelection, OccupantSelection],
):
token_refresher = UsersTokens.filter_by_one(
system=True, token=data.refresh_token, domain=data.domain
@@ -618,7 +630,10 @@ class AuthenticationForgotPasswordEventMethods(MethodToEvent):
@classmethod
def authentication_forgot_password(
cls, request: Request, data: Forgot, token_dict: dict = None
cls,
request: Request,
data: Forgot,
token_dict: typing.Union[EmployeeSelection, OccupantSelection],
):
found_user: Users = Users.check_user_exits(
access_key=data.access_key, domain=data.domain
@@ -677,7 +692,10 @@ class AuthenticationDownloadAvatarEventMethods(MethodToEvent):
@classmethod
def authentication_download_avatar(
cls, request: Request, data: Forgot, token_dict: dict = None
cls,
request: Request,
data: Forgot,
token_dict: typing.Union[EmployeeSelection, OccupantSelection],
):
found_user = Users.check_user_exits(
access_key=data.access_key, domain=data.domain