alchemy functions updated
This commit is contained in:
@@ -15,7 +15,6 @@ from databases import (
|
||||
BuildLivingSpace,
|
||||
BuildParts,
|
||||
Build,
|
||||
RelationshipEmployee2PostCode,
|
||||
Duty,
|
||||
Event2Occupant,
|
||||
Event2Employee,
|
||||
@@ -37,7 +36,7 @@ from api_services import (
|
||||
|
||||
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
|
||||
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
|
||||
from api_library.date_time_actions.date_functions import DateTimeLocal, system_arrow
|
||||
from api_library.date_time_actions.date_functions import system_arrow
|
||||
from api_configs import ApiStatic, Auth
|
||||
from databases.no_sql_models.login_handlers import load_user_with_erp_details
|
||||
|
||||
@@ -114,11 +113,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_all(
|
||||
Departments.company_id == selected_company.id
|
||||
Departments.company_id == selected_company.id,
|
||||
*Departments.valid_record_args(Departments),
|
||||
).data
|
||||
]
|
||||
duties_ids = [
|
||||
@@ -126,29 +129,41 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
for duties in Duties.filter_all(
|
||||
Duties.company_id == selected_company.id,
|
||||
Duties.department_id.in_(department_ids),
|
||||
*Duties.valid_record_args(Duties),
|
||||
).data
|
||||
]
|
||||
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), *Staff.valid_record_args(Staff)
|
||||
).data
|
||||
]
|
||||
employee = Employees.filter_one(
|
||||
Employees.people_id == token_user.person_id,
|
||||
Employees.staff_id.in_(staff_ids),
|
||||
*Employees.valid_record_args(Employees),
|
||||
).data
|
||||
|
||||
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
|
||||
staff = Staff.filter_one(
|
||||
Staff.id == employee.staff_id, *Staff.valid_record_args(Staff)
|
||||
).data
|
||||
duties = Duties.find_one(
|
||||
Duties.id == staff.duties_id, *Duties.valid_record_args(Duties)
|
||||
).data
|
||||
department = Departments.find_one(
|
||||
Departments.id == duties.department_id,
|
||||
*Departments.valid_record_args(Departments),
|
||||
).data
|
||||
bulk_id = Duty.filter_one(
|
||||
Duty.duty_code == "BULK", *Duty.valid_record_args(Duty)
|
||||
).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.valid_record_args(Duties),
|
||||
).data
|
||||
update_selected_to_redis(
|
||||
request=request,
|
||||
@@ -185,27 +200,36 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
detail="Occupant Type is not found",
|
||||
)
|
||||
build_part = BuildParts.filter_one(
|
||||
BuildParts.uu_id == data.build_part_uu_id
|
||||
BuildParts.uu_id == data.build_part_uu_id,
|
||||
*BuildParts.valid_record_args(BuildParts),
|
||||
).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, *Build.valid_record_args(Build)
|
||||
).data
|
||||
related_company = RelationshipEmployee2Build.filter_one(
|
||||
RelationshipEmployee2Build.member_id == build.id
|
||||
RelationshipEmployee2Build.member_id == build.id,
|
||||
*RelationshipEmployee2Build.valid_record_args(
|
||||
RelationshipEmployee2Build
|
||||
),
|
||||
).data
|
||||
company_related = Companies.filter_one(
|
||||
Companies.id == related_company.company_id
|
||||
Companies.id == related_company.company_id,
|
||||
*Companies.valid_record_args(Companies),
|
||||
).data
|
||||
responsible_employee = Employees.filter_one(
|
||||
Employees.id == related_company.employee_id
|
||||
Employees.id == related_company.employee_id,
|
||||
*Employees.valid_record_args(Employees),
|
||||
).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.valid_record_args(BuildLivingSpace),
|
||||
).data:
|
||||
reachable_event_list_id, reachable_event_list_uu_id = (
|
||||
Event2Occupant.get_event_id_by_build_living_space_id(
|
||||
@@ -292,6 +316,7 @@ class AuthenticationRefreshEventMethods(MethodToEvent):
|
||||
UsersTokens.domain == found_user.domain_name,
|
||||
UsersTokens.user_id == found_user.id,
|
||||
UsersTokens.token_type == "RememberMe",
|
||||
*UsersTokens.valid_record_args(UsersTokens),
|
||||
).data
|
||||
access_dict = {
|
||||
"access_token": access_token,
|
||||
@@ -327,7 +352,9 @@ class AuthenticationChangePasswordEventMethods(MethodToEvent):
|
||||
):
|
||||
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, *Users.valid_record_args(Users)
|
||||
).data:
|
||||
if found_user.check_password(data.old_password):
|
||||
found_user.set_password(data.new_password)
|
||||
return JSONResponse(
|
||||
@@ -367,7 +394,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, *Users.valid_record_args(Users)
|
||||
).data:
|
||||
found_user.create_password(password=data.password)
|
||||
found_user.password_token = None
|
||||
@@ -412,7 +439,9 @@ 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"), *Users.valid_record_args(Users)
|
||||
).data
|
||||
if not found_user:
|
||||
return JSONResponse(
|
||||
content={
|
||||
@@ -427,7 +456,8 @@ 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),
|
||||
).data
|
||||
selected_user.remove_refresher_token(
|
||||
domain=data.domain, disconnect=True
|
||||
@@ -478,7 +508,8 @@ 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"),
|
||||
*Users.valid_record_args(Users),
|
||||
).data
|
||||
selected_user.remove_refresher_token(domain=data.domain)
|
||||
# UserLogger.log_error(
|
||||
@@ -533,7 +564,9 @@ 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, *Users.valid_record_args(Users)
|
||||
).data:
|
||||
found_user: Users = found_user
|
||||
access_key = save_access_token_to_redis(
|
||||
request=request, found_user=found_user, domain=data.domain
|
||||
|
||||
Reference in New Issue
Block a user