alchemy functions updated

This commit is contained in:
2024-11-10 12:14:10 +03:00
parent 1f75e49a07
commit e01a2c8afb
24 changed files with 543 additions and 389 deletions

View File

@@ -118,7 +118,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
department_ids = [
department.id
for department in Departments.filter_all(
Departments.company_id==selected_company.id
Departments.company_id == selected_company.id
).data
]
duties_ids = [
@@ -130,9 +130,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
]
staff_ids = [
staff.id
for staff in Staff.filter_all(
Staff.duties_id.in_(duties_ids)
).data
for staff in Staff.filter_all(Staff.duties_id.in_(duties_ids)).data
]
employee = Employees.filter_one(
Employees.people_id == token_user.person_id,
@@ -142,13 +140,15 @@ class AuthenticationSelectEventMethods(MethodToEvent):
reachable_event_list_id, reachable_event_list_uu_id = (
Event2Employee.get_event_id_by_employee_id(employee_id=employee.id)
)
staff = Staff.filter_one(Staff.id==employee.staff_id).data
duties = Duties.find_one(Duties.id==staff.duties_id).data
department = Departments.find_one(Departments.id==duties.department_id).data
bulk_id = Duty.filter_one(Duty.duty_code=="BULK").data
staff = Staff.filter_one(Staff.id == employee.staff_id).data
duties = Duties.find_one(Duties.id == staff.duties_id).data
department = Departments.find_one(
Departments.id == duties.department_id
).data
bulk_id = Duty.filter_one(Duty.duty_code == "BULK").data
bulk_duty_id = Duties.filter_one(
Duties.company_id==selected_company.id,
Duties.duties_id==bulk_id.id
Duties.company_id == selected_company.id,
Duties.duties_id == bulk_id.id,
).data
update_selected_to_redis(
request=request,
@@ -176,36 +176,41 @@ class AuthenticationSelectEventMethods(MethodToEvent):
status_code=status.HTTP_200_OK,
)
elif token_user.user_type == 2:
occupant_type = OccupantTypes.filter_one(OccupantTypes.uu_id==data.occupant_uu_id).data
occupant_type = OccupantTypes.filter_one(
OccupantTypes.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_one(BuildParts.uu_id==data.build_part_uu_id).data
build_part = BuildParts.filter_one(
BuildParts.uu_id == data.build_part_uu_id
).data
if not build_part:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Build Part is not found",
)
build = Build.filter_one(Build.id==build_part.build_id).data
build = Build.filter_one(Build.id == build_part.build_id).data
related_company = RelationshipEmployee2Build.filter_one(
RelationshipEmployee2Build.member_id==build.id
RelationshipEmployee2Build.member_id == build.id
).data
company_related = Companies.filter_one(
Companies.id==related_company.company_id
Companies.id == related_company.company_id
).data
responsible_employee = Employees.filter_one(
Employees.id==related_company.employee_id
Employees.id == related_company.employee_id
).data
if selected_occupant_type := BuildLivingSpace.filter_one(
BuildLivingSpace.occupant_type==occupant_type.id,
BuildLivingSpace.person_id==token_user.person_id,
BuildLivingSpace.build_parts_id==build_part.id,
BuildLivingSpace.occupant_type == occupant_type.id,
BuildLivingSpace.person_id == token_user.person_id,
BuildLivingSpace.build_parts_id == build_part.id,
).data:
reachable_event_list_id, reachable_event_list_uu_id = (
Event2Occupant.get_event_id_by_build_living_space_id(
Event2Occupant.build_living_space_id==selected_occupant_type.id
Event2Occupant.build_living_space_id
== selected_occupant_type.id
)
)
update_selected_to_redis(
@@ -250,7 +255,9 @@ class AuthenticationCheckTokenEventMethods(MethodToEvent):
@classmethod
def authentication_login_with_domain_and_creds(
cls, request, token_dict: typing.Union[EmployeeSelection, OccupantSelection],
cls,
request,
token_dict: typing.Union[EmployeeSelection, OccupantSelection],
):
if get_object_via_access_key(request=request):
return JSONResponse(
@@ -272,15 +279,19 @@ class AuthenticationRefreshEventMethods(MethodToEvent):
@classmethod
def authentication_refresh_user_info(
cls, request, token_dict: typing.Union[EmployeeSelection, OccupantSelection],
cls,
request,
token_dict: typing.Union[EmployeeSelection, OccupantSelection],
):
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(Users.uu_id==token_user.get("uu_id")).data:
if found_user := Users.filter_one(
Users.uu_id == token_user.get("uu_id")
).data:
user_token = UsersTokens.filter_one(
UsersTokens.domain==found_user.domain_name,
UsersTokens.user_id==found_user.id,
UsersTokens.token_type=="RememberMe",
UsersTokens.domain == found_user.domain_name,
UsersTokens.user_id == found_user.id,
UsersTokens.token_type == "RememberMe",
).data
access_dict = {
"access_token": access_token,
@@ -309,11 +320,14 @@ class AuthenticationChangePasswordEventMethods(MethodToEvent):
@classmethod
def authentication_change_password(
cls, request, data: ChangePassword, token_dict: typing.Union[EmployeeSelection, OccupantSelection],
cls,
request,
data: ChangePassword,
token_dict: typing.Union[EmployeeSelection, OccupantSelection],
):
token_user = get_object_via_access_key(request=request)
if token_user.user_type == 1:
if found_user := Users.filter_one(Users.uu_id==token_user.uu_id).data:
if found_user := Users.filter_one(Users.uu_id == token_user.uu_id).data:
if found_user.check_password(data.old_password):
found_user.set_password(data.new_password)
return JSONResponse(
@@ -353,7 +367,7 @@ class AuthenticationCreatePasswordEventMethods(MethodToEvent):
status_code=status.HTTP_406_NOT_ACCEPTABLE, detail="Password must match"
)
if found_user := Users.filter_one(
Users.password_token==data.password_token
Users.password_token == data.password_token
).data:
found_user.create_password(password=data.password)
found_user.password_token = None
@@ -398,9 +412,7 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
):
if token_user := get_object_via_access_key(request=request):
found_user = Users.filter_one(
Users.uu_id==token_user.get("uu_id")
).data
found_user = Users.filter_one(Users.uu_id == token_user.get("uu_id")).data
if not found_user:
return JSONResponse(
content={
@@ -415,7 +427,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")
).data
selected_user.remove_refresher_token(
domain=data.domain, disconnect=True
@@ -466,7 +478,7 @@ class AuthenticationLogoutEventMethods(MethodToEvent):
if token_user.get("domain") == data.domain:
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")
).data
selected_user.remove_refresher_token(domain=data.domain)
# UserLogger.log_error(
@@ -521,9 +533,7 @@ class AuthenticationRefreshTokenEventMethods(MethodToEvent):
content={"completed": False, "message": "Invalid data", "data": {}},
status_code=status.HTTP_202_ACCEPTED,
)
if found_user := Users.filter_one(
Users.id==token_refresher.user_id
).data:
if found_user := Users.filter_one(Users.id == token_refresher.user_id).data:
found_user: Users = found_user
access_key = save_access_token_to_redis(
request=request, found_user=found_user, domain=data.domain