migrator functions updated

This commit is contained in:
2024-11-11 22:23:07 +03:00
parent f6135ced5f
commit ffb85a62f6
56 changed files with 567 additions and 485 deletions

View File

@@ -71,6 +71,12 @@ class AuthenticationLoginEventMethods(MethodToEvent):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials"
)
access_object = access_dict.get("access_object")
if not access_object:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="This User has no active role registered. Please contact your administrator."
)
return JSONResponse(
content={
@@ -111,11 +117,15 @@ class AuthenticationSelectEventMethods(MethodToEvent):
},
status_code=status.HTTP_401_UNAUTHORIZED,
)
if selected_company := Companies.find_one(uu_id=data.company_uu_id):
if selected_company := Companies.filter_one(
Companies.uu_id==data.company_uu_id,
*Companies.valid_record_args(Companies),
).data:
department_ids = [
department.id
for department in Departments.filter_by_active(
company_id=selected_company.id
for department in Departments.filter_all(
Departments.company_id==selected_company.id,
*Departments.valid_record_args(Departments),
).data
]
duties_ids = [
@@ -154,12 +164,12 @@ class AuthenticationSelectEventMethods(MethodToEvent):
Departments.id == duties.department_id,
).data
bulk_id = Duty.filter_by_one(
duty_code="BULK", **Duty.valid_record_args(Duty)
duty_code="BULK", **Duty.valid_record_dict
).data
bulk_duty_id = Duties.filter_by_one(
company_id=selected_company.id,
duties_id=bulk_id.id,
*Duties.valid_record_dict,
**Duties.valid_record_dict,
).data
update_selected_to_redis(
request=request,
@@ -187,13 +197,13 @@ class AuthenticationSelectEventMethods(MethodToEvent):
status_code=status.HTTP_200_OK,
)
elif token_user.user_type == 2:
occupant_type = OccupantTypes.filter_by_one(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(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,
@@ -213,7 +223,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
Companies.id == related_company.company_id,
*Companies.valid_record_args(Companies),
).data
responsible_employee = Employees.find_one(
responsible_employee = Employees.filter_one(
Employees.id == related_company.employee_id,
*Employees.valid_record_args(Employees),
).data
@@ -389,7 +399,7 @@ class AuthenticationCreatePasswordEventMethods(MethodToEvent):
},
status_code=status.HTTP_202_ACCEPTED,
)
found_user.create_password(found_user=found_user,password=data.password)
found_user.create_password(found_user=found_user, password=data.password)
# send_email_completed = send_email(
# subject=f"Dear {found_user.user_tag}, your password has been changed.",
# receivers=[str(found_user.email)],
@@ -409,7 +419,6 @@ class AuthenticationCreatePasswordEventMethods(MethodToEvent):
)
class AuthenticationDisconnectUserEventMethods(MethodToEvent):
event_type = "UPDATE"
@@ -441,7 +450,10 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
for key in already_tokens:
token_user = json.loads(redis_cli.get(key) or {})
redis_cli.delete(key)
selected_user = Users.find_one(uu_id=token_user.get("uu_id"))
selected_user = Users.filter_one(
Users.uu_id==token_user.get("uu_id"),
*Users.valid_record_args(Users),
)
selected_user.remove_refresher_token(
domain=data.domain, disconnect=True
)
@@ -499,7 +511,10 @@ class AuthenticationLogoutEventMethods(MethodToEvent):
for token_user in token_users:
if token_dict.domain == data.domain:
redis_cli.delete(token_user)
selected_user = Users.find_one(uu_id=token_user.get("uu_id"))
selected_user = Users.filter_one(
Users.uu_id==token_user.get("uu_id"),
*Users.valid_record_args(Users),
)
selected_user.remove_refresher_token(domain=data.domain)
# UserLogger.log_error(
# str(
@@ -537,8 +552,8 @@ class AuthenticationRefreshTokenEventMethods(MethodToEvent):
def authentication_refresher_token(
cls, request: Request, data: Remember, token_dict: dict = None
):
token_refresher = UsersTokens.find_one(
token=data.refresh_token, domain=data.domain
token_refresher = UsersTokens.filter_by_one(
system=True, token=data.refresh_token, domain=data.domain
)
if not token_refresher:
return JSONResponse(