alchemy functions updated
This commit is contained in:
parent
1f75e49a07
commit
e01a2c8afb
|
|
@ -113,7 +113,7 @@ class AddressCreateEventMethods(MethodToEvent):
|
||||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
):
|
):
|
||||||
post_code = AddressPostcode.filter_one(
|
post_code = AddressPostcode.filter_one(
|
||||||
AddressPostcode.uu_id==data.post_code_uu_id,
|
AddressPostcode.uu_id == data.post_code_uu_id,
|
||||||
AddressPostcode.active == True,
|
AddressPostcode.active == True,
|
||||||
).data
|
).data
|
||||||
if not post_code:
|
if not post_code:
|
||||||
|
|
@ -232,7 +232,7 @@ class AddressUpdateEventMethods(MethodToEvent):
|
||||||
):
|
):
|
||||||
address = Addresses.find_one_or_abort(uu_id=address_uu_id)
|
address = Addresses.find_one_or_abort(uu_id=address_uu_id)
|
||||||
post_code = RelationshipEmployee2PostCode.filter_one(
|
post_code = RelationshipEmployee2PostCode.filter_one(
|
||||||
RelationshipEmployee2PostCode.member_id==address.post_code_id
|
RelationshipEmployee2PostCode.member_id == address.post_code_id
|
||||||
).data
|
).data
|
||||||
if not post_code:
|
if not post_code:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -309,7 +309,7 @@ class AddressPostCodeCreateEventMethods(MethodToEvent):
|
||||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
):
|
):
|
||||||
data_dump = data.excluded_dump()
|
data_dump = data.excluded_dump()
|
||||||
street = AddressStreet.filter_one(AddressStreet.uu_id==data.street_uu_id).data
|
street = AddressStreet.filter_one(AddressStreet.uu_id == data.street_uu_id).data
|
||||||
if not street:
|
if not street:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=404,
|
status_code=404,
|
||||||
|
|
@ -351,8 +351,12 @@ class AddressPostCodeUpdateEventMethods(MethodToEvent):
|
||||||
data: InsertPostCode,
|
data: InsertPostCode,
|
||||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
):
|
):
|
||||||
post_code = AddressPostcode.filter_one(AddressPostcode.uu_id==post_code_uu_id).data
|
post_code = AddressPostcode.filter_one(
|
||||||
street = AddressStreet.filter_one(AddressPostcode.uu_id==data.street_uu_id).data
|
AddressPostcode.uu_id == post_code_uu_id
|
||||||
|
).data
|
||||||
|
street = AddressStreet.filter_one(
|
||||||
|
AddressPostcode.uu_id == data.street_uu_id
|
||||||
|
).data
|
||||||
if not street:
|
if not street:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=404,
|
status_code=404,
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||||
department_ids = [
|
department_ids = [
|
||||||
department.id
|
department.id
|
||||||
for department in Departments.filter_all(
|
for department in Departments.filter_all(
|
||||||
Departments.company_id==selected_company.id
|
Departments.company_id == selected_company.id
|
||||||
).data
|
).data
|
||||||
]
|
]
|
||||||
duties_ids = [
|
duties_ids = [
|
||||||
|
|
@ -130,9 +130,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||||
]
|
]
|
||||||
staff_ids = [
|
staff_ids = [
|
||||||
staff.id
|
staff.id
|
||||||
for staff in Staff.filter_all(
|
for staff in Staff.filter_all(Staff.duties_id.in_(duties_ids)).data
|
||||||
Staff.duties_id.in_(duties_ids)
|
|
||||||
).data
|
|
||||||
]
|
]
|
||||||
employee = Employees.filter_one(
|
employee = Employees.filter_one(
|
||||||
Employees.people_id == token_user.person_id,
|
Employees.people_id == token_user.person_id,
|
||||||
|
|
@ -142,13 +140,15 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||||
reachable_event_list_id, reachable_event_list_uu_id = (
|
reachable_event_list_id, reachable_event_list_uu_id = (
|
||||||
Event2Employee.get_event_id_by_employee_id(employee_id=employee.id)
|
Event2Employee.get_event_id_by_employee_id(employee_id=employee.id)
|
||||||
)
|
)
|
||||||
staff = Staff.filter_one(Staff.id==employee.staff_id).data
|
staff = Staff.filter_one(Staff.id == employee.staff_id).data
|
||||||
duties = Duties.find_one(Duties.id==staff.duties_id).data
|
duties = Duties.find_one(Duties.id == staff.duties_id).data
|
||||||
department = Departments.find_one(Departments.id==duties.department_id).data
|
department = Departments.find_one(
|
||||||
bulk_id = Duty.filter_one(Duty.duty_code=="BULK").data
|
Departments.id == duties.department_id
|
||||||
|
).data
|
||||||
|
bulk_id = Duty.filter_one(Duty.duty_code == "BULK").data
|
||||||
bulk_duty_id = Duties.filter_one(
|
bulk_duty_id = Duties.filter_one(
|
||||||
Duties.company_id==selected_company.id,
|
Duties.company_id == selected_company.id,
|
||||||
Duties.duties_id==bulk_id.id
|
Duties.duties_id == bulk_id.id,
|
||||||
).data
|
).data
|
||||||
update_selected_to_redis(
|
update_selected_to_redis(
|
||||||
request=request,
|
request=request,
|
||||||
|
|
@ -176,36 +176,41 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||||
status_code=status.HTTP_200_OK,
|
status_code=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
elif token_user.user_type == 2:
|
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:
|
if not occupant_type:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
detail="Occupant Type is not found",
|
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:
|
if not build_part:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
detail="Build Part is not found",
|
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(
|
related_company = RelationshipEmployee2Build.filter_one(
|
||||||
RelationshipEmployee2Build.member_id==build.id
|
RelationshipEmployee2Build.member_id == build.id
|
||||||
).data
|
).data
|
||||||
company_related = Companies.filter_one(
|
company_related = Companies.filter_one(
|
||||||
Companies.id==related_company.company_id
|
Companies.id == related_company.company_id
|
||||||
).data
|
).data
|
||||||
responsible_employee = Employees.filter_one(
|
responsible_employee = Employees.filter_one(
|
||||||
Employees.id==related_company.employee_id
|
Employees.id == related_company.employee_id
|
||||||
).data
|
).data
|
||||||
if selected_occupant_type := BuildLivingSpace.filter_one(
|
if selected_occupant_type := BuildLivingSpace.filter_one(
|
||||||
BuildLivingSpace.occupant_type==occupant_type.id,
|
BuildLivingSpace.occupant_type == occupant_type.id,
|
||||||
BuildLivingSpace.person_id==token_user.person_id,
|
BuildLivingSpace.person_id == token_user.person_id,
|
||||||
BuildLivingSpace.build_parts_id==build_part.id,
|
BuildLivingSpace.build_parts_id == build_part.id,
|
||||||
).data:
|
).data:
|
||||||
reachable_event_list_id, reachable_event_list_uu_id = (
|
reachable_event_list_id, reachable_event_list_uu_id = (
|
||||||
Event2Occupant.get_event_id_by_build_living_space_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(
|
update_selected_to_redis(
|
||||||
|
|
@ -250,7 +255,9 @@ class AuthenticationCheckTokenEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def authentication_login_with_domain_and_creds(
|
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):
|
if get_object_via_access_key(request=request):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
|
|
@ -272,15 +279,19 @@ class AuthenticationRefreshEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def authentication_refresh_user_info(
|
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))
|
access_token = str(request.headers.get(Auth.ACCESS_TOKEN_TAG))
|
||||||
if token_user := get_object_via_access_key(request=request):
|
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(
|
user_token = UsersTokens.filter_one(
|
||||||
UsersTokens.domain==found_user.domain_name,
|
UsersTokens.domain == found_user.domain_name,
|
||||||
UsersTokens.user_id==found_user.id,
|
UsersTokens.user_id == found_user.id,
|
||||||
UsersTokens.token_type=="RememberMe",
|
UsersTokens.token_type == "RememberMe",
|
||||||
).data
|
).data
|
||||||
access_dict = {
|
access_dict = {
|
||||||
"access_token": access_token,
|
"access_token": access_token,
|
||||||
|
|
@ -309,11 +320,14 @@ class AuthenticationChangePasswordEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def authentication_change_password(
|
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)
|
token_user = get_object_via_access_key(request=request)
|
||||||
if token_user.user_type == 1:
|
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):
|
if found_user.check_password(data.old_password):
|
||||||
found_user.set_password(data.new_password)
|
found_user.set_password(data.new_password)
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
|
|
@ -353,7 +367,7 @@ class AuthenticationCreatePasswordEventMethods(MethodToEvent):
|
||||||
status_code=status.HTTP_406_NOT_ACCEPTABLE, detail="Password must match"
|
status_code=status.HTTP_406_NOT_ACCEPTABLE, detail="Password must match"
|
||||||
)
|
)
|
||||||
if found_user := Users.filter_one(
|
if found_user := Users.filter_one(
|
||||||
Users.password_token==data.password_token
|
Users.password_token == data.password_token
|
||||||
).data:
|
).data:
|
||||||
found_user.create_password(password=data.password)
|
found_user.create_password(password=data.password)
|
||||||
found_user.password_token = None
|
found_user.password_token = None
|
||||||
|
|
@ -398,9 +412,7 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
|
||||||
):
|
):
|
||||||
|
|
||||||
if token_user := get_object_via_access_key(request=request):
|
if token_user := get_object_via_access_key(request=request):
|
||||||
found_user = Users.filter_one(
|
found_user = Users.filter_one(Users.uu_id == token_user.get("uu_id")).data
|
||||||
Users.uu_id==token_user.get("uu_id")
|
|
||||||
).data
|
|
||||||
if not found_user:
|
if not found_user:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
|
|
@ -415,7 +427,7 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
|
||||||
token_user = json.loads(redis_cli.get(key) or {})
|
token_user = json.loads(redis_cli.get(key) or {})
|
||||||
redis_cli.delete(key)
|
redis_cli.delete(key)
|
||||||
selected_user = Users.filter_one(
|
selected_user = Users.filter_one(
|
||||||
Users.uu_id==token_user.get("uu_id")
|
Users.uu_id == token_user.get("uu_id")
|
||||||
).data
|
).data
|
||||||
selected_user.remove_refresher_token(
|
selected_user.remove_refresher_token(
|
||||||
domain=data.domain, disconnect=True
|
domain=data.domain, disconnect=True
|
||||||
|
|
@ -466,7 +478,7 @@ class AuthenticationLogoutEventMethods(MethodToEvent):
|
||||||
if token_user.get("domain") == data.domain:
|
if token_user.get("domain") == data.domain:
|
||||||
redis_cli.delete(key)
|
redis_cli.delete(key)
|
||||||
selected_user = Users.filter_one(
|
selected_user = Users.filter_one(
|
||||||
Users.uu_id==token_user.get("uu_id")
|
Users.uu_id == token_user.get("uu_id")
|
||||||
).data
|
).data
|
||||||
selected_user.remove_refresher_token(domain=data.domain)
|
selected_user.remove_refresher_token(domain=data.domain)
|
||||||
# UserLogger.log_error(
|
# UserLogger.log_error(
|
||||||
|
|
@ -521,9 +533,7 @@ class AuthenticationRefreshTokenEventMethods(MethodToEvent):
|
||||||
content={"completed": False, "message": "Invalid data", "data": {}},
|
content={"completed": False, "message": "Invalid data", "data": {}},
|
||||||
status_code=status.HTTP_202_ACCEPTED,
|
status_code=status.HTTP_202_ACCEPTED,
|
||||||
)
|
)
|
||||||
if found_user := Users.filter_one(
|
if found_user := Users.filter_one(Users.id == token_refresher.user_id).data:
|
||||||
Users.id==token_refresher.user_id
|
|
||||||
).data:
|
|
||||||
found_user: Users = found_user
|
found_user: Users = found_user
|
||||||
access_key = save_access_token_to_redis(
|
access_key = save_access_token_to_redis(
|
||||||
request=request, found_user=found_user, domain=data.domain
|
request=request, found_user=found_user, domain=data.domain
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import json
|
import json
|
||||||
import typing
|
import typing
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from fastapi import status
|
from fastapi import status
|
||||||
from fastapi.requests import Request
|
from fastapi.requests import Request
|
||||||
|
|
@ -96,8 +97,8 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||||
def authentication_select_company_or_occupant_type(
|
def authentication_select_company_or_occupant_type(
|
||||||
cls,
|
cls,
|
||||||
request: Request,
|
request: Request,
|
||||||
data: typing.Union[EmployeeSelection, OccupantSelection],
|
data,
|
||||||
token_dict: dict = None,
|
token_dict: typing.Union[EmployeeSelection, OccupantSelection],
|
||||||
):
|
):
|
||||||
from api_objects.auth.token_objects import OccupantToken, CompanyToken
|
from api_objects.auth.token_objects import OccupantToken, CompanyToken
|
||||||
|
|
||||||
|
|
@ -120,32 +121,45 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||||
]
|
]
|
||||||
duties_ids = [
|
duties_ids = [
|
||||||
duties.id
|
duties.id
|
||||||
for duties in Duties.filter_active(
|
for duties in Duties.filter_all(
|
||||||
Duties.company_id == selected_company.id,
|
Duties.company_id == selected_company.id,
|
||||||
Duties.department_id.in_(department_ids),
|
Duties.department_id.in_(department_ids),
|
||||||
|
*Duties.valid_record_args(Duties),
|
||||||
).data
|
).data
|
||||||
]
|
]
|
||||||
staff_ids = [
|
staff_ids = [
|
||||||
staff.id
|
staff.id
|
||||||
for staff in Staff.filter_active(
|
for staff in Staff.filter_all(
|
||||||
Staff.duties_id.in_(duties_ids)
|
Staff.duties_id.in_(duties_ids),
|
||||||
|
*Staff.valid_record_args(Staff),
|
||||||
).data
|
).data
|
||||||
]
|
]
|
||||||
employee = Employees.filter_active(
|
employee = Employees.filter_one(
|
||||||
Employees.people_id == token_user.person_id,
|
Employees.people_id == token_user.person_id,
|
||||||
Employees.staff_id.in_(staff_ids),
|
Employees.staff_id.in_(staff_ids),
|
||||||
).data[0]
|
*Employees.valid_record_args(Employees),
|
||||||
|
).data
|
||||||
|
|
||||||
reachable_event_list_id, reachable_event_list_uu_id = (
|
reachable_event_list_id, reachable_event_list_uu_id = (
|
||||||
Event2Employee.get_event_id_by_employee_id(employee_id=employee.id)
|
Event2Employee.get_event_id_by_employee_id(employee_id=employee.id)
|
||||||
)
|
)
|
||||||
staff = Staff.find_one(id=employee.staff_id)
|
staff = Staff.filter_one(
|
||||||
duties = Duties.find_one(id=staff.duties_id)
|
Staff.id==employee.staff_id,
|
||||||
department = Departments.find_one(id=duties.department_id)
|
*Staff.valid_record_args(Staff),
|
||||||
bulk_id = Duty.find_one(duty_code="BULK")
|
).data
|
||||||
bulk_duty_id = Duties.find_one(
|
duties = Duties.filter_one(
|
||||||
company_id=selected_company.id, duties_id=bulk_id.id
|
Duties.id==staff.duties_id,
|
||||||
)
|
*Duties.valid_record_args(Duties),
|
||||||
|
).data
|
||||||
|
department = Departments.filter_one(
|
||||||
|
Departments.id==duties.department_id,
|
||||||
|
).data
|
||||||
|
bulk_id = Duty.filter_by_one(
|
||||||
|
duty_code="BULK", *Duty.valid_record_args(Duty)
|
||||||
|
).data
|
||||||
|
bulk_duty_id = Duties.filter_by_one(
|
||||||
|
company_id=selected_company.id, duties_id=bulk_id.id, *Duties.valid_record_dict
|
||||||
|
).data
|
||||||
update_selected_to_redis(
|
update_selected_to_redis(
|
||||||
request=request,
|
request=request,
|
||||||
add_payload=CompanyToken(
|
add_payload=CompanyToken(
|
||||||
|
|
@ -172,27 +186,40 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||||
status_code=status.HTTP_200_OK,
|
status_code=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
elif token_user.user_type == 2:
|
elif token_user.user_type == 2:
|
||||||
occupant_type = OccupantTypes.find_one(uu_id=data.occupant_uu_id)
|
occupant_type = OccupantTypes.filter_by_one(uu_id=data.occupant_uu_id)
|
||||||
if not occupant_type:
|
if not occupant_type:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
detail="Occupant Type is not found",
|
detail="Occupant Type is not found",
|
||||||
)
|
)
|
||||||
build_part = BuildParts.find_one(uu_id=data.build_part_uu_id)
|
build_part = BuildParts.filter_by_one(uu_id=data.build_part_uu_id)
|
||||||
if not build_part:
|
if not build_part:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
detail="Build Part is not found",
|
detail="Build Part is not found",
|
||||||
)
|
)
|
||||||
build = Build.find_one(id=build_part.build_id)
|
build = Build.filter_one(
|
||||||
related_company = RelationshipEmployee2Build.find_one(member_id=build.id)
|
Build.id==build_part.build_id,
|
||||||
company_related = Companies.find_one(id=related_company.company_id)
|
*Build.valid_record_args(Build),
|
||||||
responsible_employee = Employees.find_one(id=related_company.employee_id)
|
).data
|
||||||
if selected_occupant_type := BuildLivingSpace.find_one(
|
related_company = RelationshipEmployee2Build.filter_one(
|
||||||
occupant_type=occupant_type.id,
|
RelationshipEmployee2Build.member_id==build.id,
|
||||||
person_id=token_user.person_id,
|
*RelationshipEmployee2Build.valid_record_args(RelationshipEmployee2Build),
|
||||||
build_parts_id=build_part.id,
|
).data
|
||||||
):
|
company_related = Companies.filter_one(
|
||||||
|
Companies.id==related_company.company_id,
|
||||||
|
*Companies.valid_record_args(Companies),
|
||||||
|
).data
|
||||||
|
responsible_employee = Employees.find_one(
|
||||||
|
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 = (
|
reachable_event_list_id, reachable_event_list_uu_id = (
|
||||||
Event2Occupant.get_event_id_by_build_living_space_id(
|
Event2Occupant.get_event_id_by_build_living_space_id(
|
||||||
build_living_space_id=selected_occupant_type.id
|
build_living_space_id=selected_occupant_type.id
|
||||||
|
|
@ -265,12 +292,16 @@ class AuthenticationRefreshEventMethods(MethodToEvent):
|
||||||
|
|
||||||
access_token = str(request.headers.get(Auth.ACCESS_TOKEN_TAG))
|
access_token = str(request.headers.get(Auth.ACCESS_TOKEN_TAG))
|
||||||
if token_user := get_object_via_access_key(request=request):
|
if token_user := get_object_via_access_key(request=request):
|
||||||
if found_user := Users.find_one(uu_id=token_user.get("uu_id")):
|
if found_user := Users.filter_one(
|
||||||
user_token = UsersTokens.find_one(
|
Users.uu_id==token_user.get("uu_id"),
|
||||||
domain=found_user.domain_name,
|
*Users.valid_record_args(Users),
|
||||||
user_id=found_user.id,
|
).data:
|
||||||
token_type="RememberMe",
|
user_token = UsersTokens.filter_one(
|
||||||
)
|
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_dict = {
|
||||||
"access_token": access_token,
|
"access_token": access_token,
|
||||||
"refresh_token": getattr(user_token, "token", None),
|
"refresh_token": getattr(user_token, "token", None),
|
||||||
|
|
@ -298,11 +329,13 @@ class AuthenticationChangePasswordEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def authentication_change_password(
|
def authentication_change_password(
|
||||||
cls, request, data: ChangePassword, token_dict: dict = None
|
cls, data: ChangePassword, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||||
):
|
):
|
||||||
token_user = get_object_via_access_key(request=request)
|
if token_dict.user_type == 1:
|
||||||
if token_user.user_type == 1:
|
if found_user := Users.filter_one(
|
||||||
if found_user := Users.find_one(uu_id=token_user.uu_id):
|
Users.uu_id==token_dict.person_uu_id,
|
||||||
|
*Users.valid_record_args(Users),
|
||||||
|
).data:
|
||||||
if found_user.check_password(data.old_password):
|
if found_user.check_password(data.old_password):
|
||||||
found_user.set_password(data.new_password)
|
found_user.set_password(data.new_password)
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
|
|
@ -334,13 +367,16 @@ class AuthenticationCreatePasswordEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def authentication_create_password(
|
def authentication_create_password(
|
||||||
cls, request, data: CreatePassword, token_dict: dict = None
|
cls, data: CreatePassword
|
||||||
):
|
):
|
||||||
if not data.re_password == data.password:
|
if not data.re_password == data.password:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_406_NOT_ACCEPTABLE, detail="Password must match"
|
status_code=status.HTTP_406_NOT_ACCEPTABLE, detail="Password must match"
|
||||||
)
|
)
|
||||||
if found_user := Users.find_one(password_token=data.password_token):
|
if found_user := Users.filter_one(
|
||||||
|
Users.password_token==data.password_token,
|
||||||
|
*Users.valid_record_args(Users),
|
||||||
|
).data:
|
||||||
found_user.create_password(password=data.password)
|
found_user.create_password(password=data.password)
|
||||||
found_user.password_token = None
|
found_user.password_token = None
|
||||||
found_user.save()
|
found_user.save()
|
||||||
|
|
@ -380,10 +416,12 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def authentication_disconnect_user(
|
def authentication_disconnect_user(
|
||||||
cls, request: Request, data: Logout, token_dict: dict = None
|
cls, request: Request, data: Logout, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||||
):
|
):
|
||||||
if token_user := get_object_via_access_key(request=request):
|
found_user = Users.filter_one(
|
||||||
found_user = Users.find_one(uu_id=token_user.get("uu_id"))
|
Users.uu_id==token_dict.person_uu_id,
|
||||||
|
*Users.valid_record_args(Users),
|
||||||
|
).data
|
||||||
if not found_user:
|
if not found_user:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
|
|
@ -438,14 +476,22 @@ class AuthenticationLogoutEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def authentication_logout_user(
|
def authentication_logout_user(
|
||||||
cls, request: Request, data: Logout, token_dict: dict = None
|
cls, data: Logout, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||||
):
|
):
|
||||||
token_user = None
|
from api_services.redis.functions import get_object_via_user_uu_id
|
||||||
if already_tokens := get_object_via_access_key(request=request):
|
if not token_dict:
|
||||||
for key in already_tokens:
|
return JSONResponse(
|
||||||
token_user = json.loads(redis_cli.get(key) or {})
|
content={
|
||||||
if token_user.get("domain") == data.domain:
|
"completed": False,
|
||||||
redis_cli.delete(key)
|
"message": "Logout is not successfully completed",
|
||||||
|
"data": None,
|
||||||
|
},
|
||||||
|
status_code=status.HTTP_202_ACCEPTED,
|
||||||
|
)
|
||||||
|
token_users = get_object_via_user_uu_id(token_dict.user_uu_id)
|
||||||
|
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.find_one(uu_id=token_user.get("uu_id"))
|
||||||
selected_user.remove_refresher_token(domain=data.domain)
|
selected_user.remove_refresher_token(domain=data.domain)
|
||||||
# UserLogger.log_error(
|
# UserLogger.log_error(
|
||||||
|
|
@ -471,14 +517,7 @@ class AuthenticationLogoutEventMethods(MethodToEvent):
|
||||||
},
|
},
|
||||||
status_code=status.HTTP_200_OK,
|
status_code=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
return JSONResponse(
|
|
||||||
content={
|
|
||||||
"completed": False,
|
|
||||||
"message": "Logout is not successfully completed",
|
|
||||||
"data": None,
|
|
||||||
},
|
|
||||||
status_code=status.HTTP_202_ACCEPTED,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class AuthenticationRefreshTokenEventMethods(MethodToEvent):
|
class AuthenticationRefreshTokenEventMethods(MethodToEvent):
|
||||||
|
|
@ -500,7 +539,10 @@ class AuthenticationRefreshTokenEventMethods(MethodToEvent):
|
||||||
content={"completed": False, "message": "Invalid data", "data": {}},
|
content={"completed": False, "message": "Invalid data", "data": {}},
|
||||||
status_code=status.HTTP_202_ACCEPTED,
|
status_code=status.HTTP_202_ACCEPTED,
|
||||||
)
|
)
|
||||||
if found_user := Users.find_one(id=token_refresher.user_id):
|
if found_user := Users.filter_one(
|
||||||
|
Users.id==token_refresher.user_id,
|
||||||
|
*Users.valid_record_args(Users),
|
||||||
|
):
|
||||||
found_user: Users = found_user
|
found_user: Users = found_user
|
||||||
access_key = save_access_token_to_redis(
|
access_key = save_access_token_to_redis(
|
||||||
request=request, found_user=found_user, domain=data.domain
|
request=request, found_user=found_user, domain=data.domain
|
||||||
|
|
|
||||||
|
|
@ -83,13 +83,15 @@ class BuildCreateEventMethods(MethodToEvent):
|
||||||
|
|
||||||
created_build = Build.create_action(data=data, token=token_dict)
|
created_build = Build.create_action(data=data, token=token_dict)
|
||||||
if not created_build.is_found:
|
if not created_build.is_found:
|
||||||
build_type = BuildTypes.filter_by_one(type_code="APT_YNT").data
|
build_type = BuildTypes.filter_by_one(type_code="APT_YNT", *BuildTypes.valid_record_dict).data
|
||||||
if not build_type:
|
if not build_type:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
detail="Build type APT_YNT is not found. Please contact with your system administrator.",
|
detail="Build type APT_YNT is not found. Please contact with your system administrator.",
|
||||||
)
|
)
|
||||||
api_enum = ApiEnumDropdown.filter_by_one(enum_class="Directions", key="NN").data
|
api_enum = ApiEnumDropdown.filter_by_one(
|
||||||
|
enum_class="Directions", key="NN"
|
||||||
|
).data
|
||||||
if not api_enum:
|
if not api_enum:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,9 @@ class BuildingBuildPartsListEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def building_build_parts_list(
|
def building_build_parts_list(
|
||||||
cls, list_options: ListOptions, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
cls,
|
||||||
|
list_options: ListOptions,
|
||||||
|
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
):
|
):
|
||||||
build_list_query = Build.select_action(
|
build_list_query = Build.select_action(
|
||||||
employee_id=token_dict.selected_company.employee_id,
|
employee_id=token_dict.selected_company.employee_id,
|
||||||
|
|
@ -54,7 +56,9 @@ class BuildingBuildPartsCreateEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def building_build_parts_create(
|
def building_build_parts_create(
|
||||||
cls, data: InsertBuildParts, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
cls,
|
||||||
|
data: InsertBuildParts,
|
||||||
|
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
):
|
):
|
||||||
created_build = BuildParts.create_action(data=data, token=token_dict)
|
created_build = BuildParts.create_action(data=data, token=token_dict)
|
||||||
if not created_build:
|
if not created_build:
|
||||||
|
|
@ -86,7 +90,9 @@ class BuildingBuildPartsUpdateEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def building_build_parts_update(
|
def building_build_parts_update(
|
||||||
cls, data: InsertBuildParts, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
cls,
|
||||||
|
data: InsertBuildParts,
|
||||||
|
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
):
|
):
|
||||||
if updated_build := BuildParts.update_action(data=data, token=token_dict):
|
if updated_build := BuildParts.update_action(data=data, token=token_dict):
|
||||||
updated_build.save()
|
updated_build.save()
|
||||||
|
|
@ -117,7 +123,7 @@ class BuildingBuildPartsPatchEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def building_build_parts_patch(cls, data, token_dict):
|
def building_build_parts_patch(cls, data, token_dict):
|
||||||
find_one_build = BuildParts.filter_one(BuildParts.uu_id==data.uu_id).data
|
find_one_build = BuildParts.filter_one(BuildParts.uu_id == data.uu_id).data
|
||||||
access_authorized_build = BuildParts.select_action(
|
access_authorized_build = BuildParts.select_action(
|
||||||
duty_id=token_dict.selected_company.duty_id,
|
duty_id=token_dict.selected_company.duty_id,
|
||||||
filter_expr=[BuildParts.id == find_one_build.id],
|
filter_expr=[BuildParts.id == find_one_build.id],
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
|
||||||
detail=f"{data.build_parts_uu_id} - Build Part is not found in database. Check build part uu_id",
|
detail=f"{data.build_parts_uu_id} - Build Part is not found in database. Check build part uu_id",
|
||||||
)
|
)
|
||||||
|
|
||||||
life_person = People.filter_one(People.uu_id==data.person_uu_id or "").data
|
life_person = People.filter_one(People.uu_id == data.person_uu_id or "").data
|
||||||
if not life_person:
|
if not life_person:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_418_IM_A_TEAPOT,
|
status_code=status.HTTP_418_IM_A_TEAPOT,
|
||||||
|
|
@ -145,7 +145,7 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
|
||||||
str(system_arrow.now()) >= BuildLivingSpace.expiry_starts,
|
str(system_arrow.now()) >= BuildLivingSpace.expiry_starts,
|
||||||
select_args=[BuildLivingSpace.id],
|
select_args=[BuildLivingSpace.id],
|
||||||
order_by=BuildLivingSpace.expiry_starts.desc(),
|
order_by=BuildLivingSpace.expiry_starts.desc(),
|
||||||
limit=1
|
limit=1,
|
||||||
).data
|
).data
|
||||||
|
|
||||||
last_living_space = BuildLivingSpace.filter_one(
|
last_living_space = BuildLivingSpace.filter_one(
|
||||||
|
|
@ -162,7 +162,9 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
|
||||||
last_living_space.expiry_ends = str(system_arrow.shift(minutes=-10))
|
last_living_space.expiry_ends = str(system_arrow.shift(minutes=-10))
|
||||||
last_living_space.save()
|
last_living_space.save()
|
||||||
|
|
||||||
user_module = Modules.filter_one(Modules.module_code == "USR-PUB", system=True).data
|
user_module = Modules.filter_one(
|
||||||
|
Modules.module_code == "USR-PUB", system=True
|
||||||
|
).data
|
||||||
ModulesBindOccupantEventMethods.modules_bind_occupant_system(
|
ModulesBindOccupantEventMethods.modules_bind_occupant_system(
|
||||||
build_living_space_id=created_living_space.id,
|
build_living_space_id=created_living_space.id,
|
||||||
modules_id=user_module.id,
|
modules_id=user_module.id,
|
||||||
|
|
@ -198,7 +200,9 @@ class BuildingLivingSpacesPartsUpdateEventMethods(MethodToEvent):
|
||||||
detail=f"{data.build_parts_uu_id} - Build Part is not found in database. Check build part uu_id",
|
detail=f"{data.build_parts_uu_id} - Build Part is not found in database. Check build part uu_id",
|
||||||
)
|
)
|
||||||
|
|
||||||
life_person = People.filter_one(People.uu_id==data.life_person_uu_id or "").data
|
life_person = People.filter_one(
|
||||||
|
People.uu_id == data.life_person_uu_id or ""
|
||||||
|
).data
|
||||||
if not life_person:
|
if not life_person:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_418_IM_A_TEAPOT,
|
status_code=status.HTTP_418_IM_A_TEAPOT,
|
||||||
|
|
@ -209,7 +213,7 @@ class BuildingLivingSpacesPartsUpdateEventMethods(MethodToEvent):
|
||||||
living_space_id = BuildLivingSpace.select_only(
|
living_space_id = BuildLivingSpace.select_only(
|
||||||
select_args=[BuildLivingSpace.id],
|
select_args=[BuildLivingSpace.id],
|
||||||
order_by=BuildLivingSpace.expiry_starts.desc(),
|
order_by=BuildLivingSpace.expiry_starts.desc(),
|
||||||
limit=1
|
limit=1,
|
||||||
).get(1)
|
).get(1)
|
||||||
|
|
||||||
last_living_space = BuildLivingSpace.filter_one(
|
last_living_space = BuildLivingSpace.filter_one(
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,6 @@ class DecisionBookCreateEventMethods(MethodToEvent):
|
||||||
data_dict["resp_company_id"] = company.id
|
data_dict["resp_company_id"] = company.id
|
||||||
data_dict["resp_company_uu_id"] = str(company.uu_id)
|
data_dict["resp_company_uu_id"] = str(company.uu_id)
|
||||||
|
|
||||||
|
|
||||||
decision_period_date = DateTimeLocal.get(build.decision_period_date)
|
decision_period_date = DateTimeLocal.get(build.decision_period_date)
|
||||||
data_dict["expiry_starts"] = DateTimeLocal.get(
|
data_dict["expiry_starts"] = DateTimeLocal.get(
|
||||||
system_arrow.now().date().year,
|
system_arrow.now().date().year,
|
||||||
|
|
@ -143,11 +142,11 @@ class DecisionBookCreateEventMethods(MethodToEvent):
|
||||||
)
|
)
|
||||||
|
|
||||||
occupant_build = Build.filter_one(
|
occupant_build = Build.filter_one(
|
||||||
Build.id==token_dict.selected_occupant.build_id,
|
Build.id == token_dict.selected_occupant.build_id,
|
||||||
Build.active == True,
|
Build.active == True,
|
||||||
).get(1)
|
).get(1)
|
||||||
occupant_company = Companies.find_one(
|
occupant_company = Companies.find_one(
|
||||||
Companies.id==token_dict.selected_occupant.responsible_company_id,
|
Companies.id == token_dict.selected_occupant.responsible_company_id,
|
||||||
Companies.active == True,
|
Companies.active == True,
|
||||||
).get(1)
|
).get(1)
|
||||||
data_dict["build_id"] = occupant_build.id
|
data_dict["build_id"] = occupant_build.id
|
||||||
|
|
@ -155,9 +154,7 @@ class DecisionBookCreateEventMethods(MethodToEvent):
|
||||||
data_dict["resp_company_id"] = occupant_company.id
|
data_dict["resp_company_id"] = occupant_company.id
|
||||||
data_dict["resp_company_uu_id"] = str(occupant_company.uu_id)
|
data_dict["resp_company_uu_id"] = str(occupant_company.uu_id)
|
||||||
|
|
||||||
decision_period_date = system_arrow.get(
|
decision_period_date = system_arrow.get(occupant_build.decision_period_date)
|
||||||
occupant_build.decision_period_date
|
|
||||||
)
|
|
||||||
data_dict["expiry_starts"] = DateTimeLocal.get(
|
data_dict["expiry_starts"] = DateTimeLocal.get(
|
||||||
system_arrow.now().date().year,
|
system_arrow.now().date().year,
|
||||||
int(decision_period_date.date().month),
|
int(decision_period_date.date().month),
|
||||||
|
|
|
||||||
|
|
@ -92,10 +92,11 @@ class DecisionBookPersonAddEventMethods(MethodToEvent):
|
||||||
)
|
)
|
||||||
|
|
||||||
manger_book_person = BuildDecisionBookPerson.filter_one(
|
manger_book_person = BuildDecisionBookPerson.filter_one(
|
||||||
BuildDecisionBookPerson.token==data.token,
|
BuildDecisionBookPerson.token == data.token,
|
||||||
BuildDecisionBookPerson.build_decision_book_uu_id==data.build_decision_book_uu_id,
|
BuildDecisionBookPerson.build_decision_book_uu_id
|
||||||
BuildDecisionBookPerson.is_confirmed==True,
|
== data.build_decision_book_uu_id,
|
||||||
BuildDecisionBookPerson.active==True,
|
BuildDecisionBookPerson.is_confirmed == True,
|
||||||
|
BuildDecisionBookPerson.active == True,
|
||||||
).get(1)
|
).get(1)
|
||||||
if not manger_book_person:
|
if not manger_book_person:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -103,8 +104,9 @@ class DecisionBookPersonAddEventMethods(MethodToEvent):
|
||||||
detail="Manager person not found. Please check token",
|
detail="Manager person not found. Please check token",
|
||||||
)
|
)
|
||||||
book_invite = BuildDecisionBookInvitations.filter_one(
|
book_invite = BuildDecisionBookInvitations.filter_one(
|
||||||
BuildDecisionBookInvitations.id==manger_book_person.invite_id,
|
BuildDecisionBookInvitations.id == manger_book_person.invite_id,
|
||||||
BuildDecisionBookInvitations.build_id==token_dict.selected_occupant.build_id,
|
BuildDecisionBookInvitations.build_id
|
||||||
|
== token_dict.selected_occupant.build_id,
|
||||||
).get(1)
|
).get(1)
|
||||||
if not book_invite:
|
if not book_invite:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -112,10 +114,10 @@ class DecisionBookPersonAddEventMethods(MethodToEvent):
|
||||||
detail="Invitation not found. Please check token",
|
detail="Invitation not found. Please check token",
|
||||||
)
|
)
|
||||||
selected_book_person = BuildDecisionBookPerson.filter_one(
|
selected_book_person = BuildDecisionBookPerson.filter_one(
|
||||||
BuildDecisionBookPerson.invite_id==book_invite.id,
|
BuildDecisionBookPerson.invite_id == book_invite.id,
|
||||||
BuildDecisionBookPerson.person_uu_id==data.person_uu_id,
|
BuildDecisionBookPerson.person_uu_id == data.person_uu_id,
|
||||||
BuildDecisionBookPerson.is_confirmed==True,
|
BuildDecisionBookPerson.is_confirmed == True,
|
||||||
BuildDecisionBookPerson.active==True,
|
BuildDecisionBookPerson.active == True,
|
||||||
).get(1)
|
).get(1)
|
||||||
if not selected_book_person:
|
if not selected_book_person:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -171,11 +173,11 @@ class DecisionBookPersonAttendEventMethods(MethodToEvent):
|
||||||
detail="Employee cannot create decision book invitations",
|
detail="Employee cannot create decision book invitations",
|
||||||
)
|
)
|
||||||
|
|
||||||
token_user = Users.filter_one(Users.id==token_dict.user_id).get(1)
|
token_user = Users.filter_one(Users.id == token_dict.user_id).get(1)
|
||||||
invitation_person = BuildDecisionBookPerson.filter_one(
|
invitation_person = BuildDecisionBookPerson.filter_one(
|
||||||
BuildDecisionBookPerson.token==data.token,
|
BuildDecisionBookPerson.token == data.token,
|
||||||
BuildDecisionBookPerson.active==True,
|
BuildDecisionBookPerson.active == True,
|
||||||
BuildDecisionBookPerson.is_confirmed==True
|
BuildDecisionBookPerson.is_confirmed == True,
|
||||||
).get(1)
|
).get(1)
|
||||||
if not invitation_person:
|
if not invitation_person:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -192,9 +194,10 @@ class DecisionBookPersonAttendEventMethods(MethodToEvent):
|
||||||
# )
|
# )
|
||||||
# todo check if vicarious person is valid
|
# todo check if vicarious person is valid
|
||||||
invitation = BuildDecisionBookInvitations.filter_one(
|
invitation = BuildDecisionBookInvitations.filter_one(
|
||||||
BuildDecisionBookInvitations.id==invitation_person.invite_id,
|
BuildDecisionBookInvitations.id == invitation_person.invite_id,
|
||||||
BuildDecisionBookInvitations.build_id==token_dict.selected_occupant.build_id,
|
BuildDecisionBookInvitations.build_id
|
||||||
BuildDecisionBookInvitations.active==True,
|
== token_dict.selected_occupant.build_id,
|
||||||
|
BuildDecisionBookInvitations.active == True,
|
||||||
).get(1)
|
).get(1)
|
||||||
if not invitation:
|
if not invitation:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -240,10 +243,11 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
|
||||||
)
|
)
|
||||||
|
|
||||||
book_person_manager = BuildDecisionBookPerson.filter_one(
|
book_person_manager = BuildDecisionBookPerson.filter_one(
|
||||||
BuildDecisionBookPerson.token==data.token,
|
BuildDecisionBookPerson.token == data.token,
|
||||||
BuildDecisionBookPerson.build_living_space_id==token_dict.selected_occupant.living_space_id,
|
BuildDecisionBookPerson.build_living_space_id
|
||||||
BuildDecisionBookPerson.active==True,
|
== token_dict.selected_occupant.living_space_id,
|
||||||
BuildDecisionBookPerson.is_confirmed==True,
|
BuildDecisionBookPerson.active == True,
|
||||||
|
BuildDecisionBookPerson.is_confirmed == True,
|
||||||
).get(1)
|
).get(1)
|
||||||
manager_occupant_type = OccupantTypes.filter_by_one(
|
manager_occupant_type = OccupantTypes.filter_by_one(
|
||||||
occupant_code="BU-MNG", occupant_category_type="BU"
|
occupant_code="BU-MNG", occupant_category_type="BU"
|
||||||
|
|
@ -254,9 +258,10 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
|
||||||
# book_person_supervisor.check_occupant_type(supervisor_occupant_type)
|
# book_person_supervisor.check_occupant_type(supervisor_occupant_type)
|
||||||
|
|
||||||
invitation = BuildDecisionBookInvitations.filter_one(
|
invitation = BuildDecisionBookInvitations.filter_one(
|
||||||
BuildDecisionBookInvitations.id==book_person_manager.invite_id,
|
BuildDecisionBookInvitations.id == book_person_manager.invite_id,
|
||||||
BuildDecisionBookInvitations.build_id==token_dict.selected_occupant.build_id,
|
BuildDecisionBookInvitations.build_id
|
||||||
BuildDecisionBookInvitations.active==True,
|
== token_dict.selected_occupant.build_id,
|
||||||
|
BuildDecisionBookInvitations.active == True,
|
||||||
).get(1)
|
).get(1)
|
||||||
if not invitation:
|
if not invitation:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -265,7 +270,7 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
|
||||||
)
|
)
|
||||||
|
|
||||||
assign_occupant_type = OccupantTypes.filter_by_one(
|
assign_occupant_type = OccupantTypes.filter_by_one(
|
||||||
uu_id=data.occupant_type_uu_id, active=True
|
uu_id=data.occupant_type_uu_id
|
||||||
).get(1)
|
).get(1)
|
||||||
if not assign_occupant_type:
|
if not assign_occupant_type:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -288,11 +293,14 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
|
||||||
detail=f"Person not found. Please check person uuid",
|
detail=f"Person not found. Please check person uuid",
|
||||||
)
|
)
|
||||||
|
|
||||||
book_person_to_assign: BuildDecisionBookPerson = BuildDecisionBookPerson.filter_one(
|
book_person_to_assign: BuildDecisionBookPerson = (
|
||||||
BuildDecisionBookPerson.build_living_space_id==selected_living_space.id,
|
BuildDecisionBookPerson.filter_one(
|
||||||
BuildDecisionBookPerson.invite_id==invitation.id,
|
BuildDecisionBookPerson.build_living_space_id
|
||||||
BuildDecisionBookPerson.active==True
|
== selected_living_space.id,
|
||||||
|
BuildDecisionBookPerson.invite_id == invitation.id,
|
||||||
|
BuildDecisionBookPerson.active == True,
|
||||||
).get(1)
|
).get(1)
|
||||||
|
)
|
||||||
if not book_person_to_assign:
|
if not book_person_to_assign:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
|
|
@ -311,11 +319,14 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
|
||||||
occupant_category_type="MT",
|
occupant_category_type="MT",
|
||||||
).get(1)
|
).get(1)
|
||||||
if assigned_book_person_occupant := BuildDecisionBookPersonOccupants.filter_one(
|
if assigned_book_person_occupant := BuildDecisionBookPersonOccupants.filter_one(
|
||||||
BuildDecisionBookPersonOccupants.invite_id==invitation.id,
|
BuildDecisionBookPersonOccupants.invite_id == invitation.id,
|
||||||
BuildDecisionBookPersonOccupants.occupant_type_id==occupant_type_unique.id,
|
BuildDecisionBookPersonOccupants.occupant_type_id
|
||||||
BuildDecisionBookPersonOccupants.active==True,
|
== occupant_type_unique.id,
|
||||||
BuildDecisionBookPersonOccupants.is_confirmed==True,
|
BuildDecisionBookPersonOccupants.active == True,
|
||||||
).get(1):
|
BuildDecisionBookPersonOccupants.is_confirmed == True,
|
||||||
|
).get(
|
||||||
|
1
|
||||||
|
):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
detail=f"Only one person can be assigned to {assign_occupant_type.occupant_code} type"
|
detail=f"Only one person can be assigned to {assign_occupant_type.occupant_code} type"
|
||||||
|
|
@ -324,10 +335,11 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
|
||||||
|
|
||||||
if assign_occupant_type.occupant_code == "BU-MNG":
|
if assign_occupant_type.occupant_code == "BU-MNG":
|
||||||
person_occupant_manager = BuildDecisionBookPersonOccupants.filter_one(
|
person_occupant_manager = BuildDecisionBookPersonOccupants.filter_one(
|
||||||
BuildDecisionBookPersonOccupants.invite_id==invitation.id,
|
BuildDecisionBookPersonOccupants.invite_id == invitation.id,
|
||||||
BuildDecisionBookPersonOccupants.occupant_type_id==manager_occupant_type.id,
|
BuildDecisionBookPersonOccupants.occupant_type_id
|
||||||
BuildDecisionBookPersonOccupants.active==True,
|
== manager_occupant_type.id,
|
||||||
BuildDecisionBookPersonOccupants.is_confirmed==True,
|
BuildDecisionBookPersonOccupants.active == True,
|
||||||
|
BuildDecisionBookPersonOccupants.is_confirmed == True,
|
||||||
)
|
)
|
||||||
person_occupant_manager.query.delete()
|
person_occupant_manager.query.delete()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,9 +73,9 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||||
|
|
||||||
# Check decision book is valid for this token and building
|
# Check decision book is valid for this token and building
|
||||||
decision_book = BuildDecisionBook.filter_one(
|
decision_book = BuildDecisionBook.filter_one(
|
||||||
BuildDecisionBook.uu_id==data.build_decision_book_uu_id,
|
BuildDecisionBook.uu_id == data.build_decision_book_uu_id,
|
||||||
BuildDecisionBook.build_id==token_dict.selected_occupant.build_id,
|
BuildDecisionBook.build_id == token_dict.selected_occupant.build_id,
|
||||||
BuildDecisionBook.active==True,
|
BuildDecisionBook.active == True,
|
||||||
).get(1)
|
).get(1)
|
||||||
if not decision_book:
|
if not decision_book:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -83,7 +83,7 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||||
detail="Decision book not found. Please create decision book first",
|
detail="Decision book not found. Please create decision book first",
|
||||||
)
|
)
|
||||||
occupant_building = Build.filter_one(
|
occupant_building = Build.filter_one(
|
||||||
Build.id==token_dict.selected_occupant.build_id
|
Build.id == token_dict.selected_occupant.build_id
|
||||||
).get(1)
|
).get(1)
|
||||||
|
|
||||||
# Check meeting type is valid
|
# Check meeting type is valid
|
||||||
|
|
@ -107,9 +107,9 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create an invitation for specific invitation type to start invite sending process
|
# Create an invitation for specific invitation type to start invite sending process
|
||||||
planned_date_expires = str(
|
planned_date_expires = (
|
||||||
system_arrow.get(data.planned_date).shift(days=15).date()
|
str(system_arrow.get(data.planned_date).shift(days=15).date()),
|
||||||
),
|
)
|
||||||
book_invitation = BuildDecisionBookInvitations.find_or_create(
|
book_invitation = BuildDecisionBookInvitations.find_or_create(
|
||||||
build_id=token_dict.selected_occupant.build_id,
|
build_id=token_dict.selected_occupant.build_id,
|
||||||
build_uu_id=token_dict.selected_occupant.build_uuid,
|
build_uu_id=token_dict.selected_occupant.build_uuid,
|
||||||
|
|
@ -136,21 +136,24 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||||
|
|
||||||
# Get all the parts of the building that is occupant in token
|
# Get all the parts of the building that is occupant in token
|
||||||
build_parts = BuildParts.filter_all(
|
build_parts = BuildParts.filter_all(
|
||||||
BuildParts.build_id == occupant_building.id,
|
BuildParts.build_id == occupant_building.id, BuildParts.active == True
|
||||||
BuildParts.active == True
|
|
||||||
).data
|
).data
|
||||||
|
|
||||||
# Get all build living spaces that is found in building with distinct person id
|
# Get all build living spaces that is found in building with distinct person id
|
||||||
occupants = OccupantTypes.filter_all(system=True)
|
occupants = OccupantTypes.filter_all(system=True)
|
||||||
BuildLivingSpace.filter_attr = None
|
BuildLivingSpace.filter_attr = None
|
||||||
build_living_spaces_people = BuildLivingSpace.filter_all(
|
build_living_spaces_people = (
|
||||||
|
BuildLivingSpace.filter_all(
|
||||||
BuildLivingSpace.build_parts_id.in_(
|
BuildLivingSpace.build_parts_id.in_(
|
||||||
[build_part.id for build_part in build_parts.data]
|
[build_part.id for build_part in build_parts.data]
|
||||||
),
|
),
|
||||||
BuildLivingSpace.occupant_type.in_(
|
BuildLivingSpace.occupant_type.in_(
|
||||||
[occupant.id for occupant in occupants.data]
|
[occupant.id for occupant in occupants.data]
|
||||||
),
|
),
|
||||||
).query.distinct(BuildLivingSpace.person_id).all()
|
)
|
||||||
|
.query.distinct(BuildLivingSpace.person_id)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
if not build_living_spaces_people:
|
if not build_living_spaces_people:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
|
@ -201,9 +204,9 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||||
if invitations_person and not invitations_person.is_found:
|
if invitations_person and not invitations_person.is_found:
|
||||||
print(f'"{invitations_person.token}",')
|
print(f'"{invitations_person.token}",')
|
||||||
spaces_user = Users.filter_one(
|
spaces_user = Users.filter_one(
|
||||||
Users.active==True,
|
Users.active == True,
|
||||||
Users.is_confirmed==True,
|
Users.is_confirmed == True,
|
||||||
Users.person_id==build_living_spaces_user.person_id,
|
Users.person_id == build_living_spaces_user.person_id,
|
||||||
).data
|
).data
|
||||||
# print(
|
# print(
|
||||||
# f"Invitation is send : {spaces_user.email} "
|
# f"Invitation is send : {spaces_user.email} "
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,10 @@ class EventBindOccupantEventMethods(MethodToEvent):
|
||||||
detail="This employee is not authorized to add event to this occupant",
|
detail="This employee is not authorized to add event to this occupant",
|
||||||
)
|
)
|
||||||
|
|
||||||
occupants_build_part = BuildParts.find_one(uu_id=data.build_part_uu_id)
|
occupants_build_part = BuildParts.filter_one(
|
||||||
|
BuildParts.uu_id == data.build_part_uu_id,
|
||||||
|
BuildParts.active == True,
|
||||||
|
).data
|
||||||
if not occupants_build_part:
|
if not occupants_build_part:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
|
|
@ -48,7 +51,9 @@ class EventBindOccupantEventMethods(MethodToEvent):
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
)
|
)
|
||||||
|
|
||||||
occupant_occupant_type = OccupantTypes.find_one(uu_id=data.occupant_uu_id)
|
occupant_occupant_type = OccupantTypes.filter_by_one(
|
||||||
|
uu_id=data.occupant_uu_id
|
||||||
|
).data
|
||||||
if not occupant_occupant_type:
|
if not occupant_occupant_type:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
|
|
@ -59,8 +64,9 @@ class EventBindOccupantEventMethods(MethodToEvent):
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
)
|
)
|
||||||
|
|
||||||
events_to_add_to_occupant = Events.filter_active(
|
events_to_add_to_occupant = Events.filter_all(
|
||||||
Events.uu_id.in_(list(data.event_uu_id_list))
|
Events.uu_id.in_(list(data.event_uu_id_list)),
|
||||||
|
Events.active == True,
|
||||||
)
|
)
|
||||||
if not events_to_add_to_occupant.data:
|
if not events_to_add_to_occupant.data:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
|
|
@ -85,11 +91,11 @@ class EventBindOccupantEventMethods(MethodToEvent):
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
)
|
)
|
||||||
|
|
||||||
occupant_to_add_event = BuildLivingSpace.find_one(
|
occupant_to_add_event = BuildLivingSpace.filter_one(
|
||||||
build_parts_id=occupants_build_part.id,
|
BuildLivingSpace.build_parts_id == occupants_build_part.id,
|
||||||
occupant_type=occupant_occupant_type.id,
|
BuildLivingSpace.occupant_type == occupant_occupant_type.id,
|
||||||
)
|
BuildLivingSpace.active == True,
|
||||||
|
).data
|
||||||
if not occupant_to_add_event:
|
if not occupant_to_add_event:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,12 @@ class ModulesBindOccupantEventMethods(MethodToEvent):
|
||||||
):
|
):
|
||||||
|
|
||||||
living_space = BuildLivingSpace.filter_one(
|
living_space = BuildLivingSpace.filter_one(
|
||||||
Modules.id == build_living_space_id
|
Modules.id == build_living_space_id,
|
||||||
|
Modules.active == True,
|
||||||
|
).data
|
||||||
|
modules = Modules.filter_one(
|
||||||
|
Modules.id == modules_id, Modules.active == True
|
||||||
).data
|
).data
|
||||||
modules = Modules.filter_one(Modules.id == modules_id).data
|
|
||||||
|
|
||||||
service_build_dict = dict(build_living_space_id=living_space.id)
|
service_build_dict = dict(build_living_space_id=living_space.id)
|
||||||
service_build_dict["expires_at"] = str(
|
service_build_dict["expires_at"] = str(
|
||||||
|
|
|
||||||
|
|
@ -37,11 +37,16 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
||||||
from sqlalchemy.dialects.postgresql import insert
|
from sqlalchemy.dialects.postgresql import insert
|
||||||
|
|
||||||
living_space = BuildLivingSpace.filter_one(
|
living_space = BuildLivingSpace.filter_one(
|
||||||
BuildLivingSpace.id == build_living_space_id
|
BuildLivingSpace.id == build_living_space_id,
|
||||||
)
|
BuildLivingSpace.active == True,
|
||||||
service = Services.filter_one(Services.id == service_id)
|
).data
|
||||||
|
service = Services.filter_one(
|
||||||
|
Services.id == service_id,
|
||||||
|
Services.active == True,
|
||||||
|
).data
|
||||||
add_events_list = Service2Events.filter_all(
|
add_events_list = Service2Events.filter_all(
|
||||||
Service2Events.service_id == service.id
|
Service2Events.service_id == service.id,
|
||||||
|
Service2Events.active == True,
|
||||||
).data
|
).data
|
||||||
if not add_events_list:
|
if not add_events_list:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
|
|
@ -85,10 +90,11 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
||||||
detail="Employee is not authorized to add service to any occupant",
|
detail="Employee is not authorized to add service to any occupant",
|
||||||
)
|
)
|
||||||
|
|
||||||
occupants_build_part = BuildParts.find_one(
|
occupants_build_part = BuildParts.filter_one(
|
||||||
uu_id=data.build_part_uu_id,
|
BuildParts.uu_id == data.build_part_uu_id,
|
||||||
build_id=token_dict.selected_occupant.build_id,
|
BuildParts.build_id == token_dict.selected_occupant.build_id,
|
||||||
)
|
BuildParts.active == True,
|
||||||
|
).data
|
||||||
print("occupants_build_part", occupants_build_part)
|
print("occupants_build_part", occupants_build_part)
|
||||||
if not occupants_build_part:
|
if not occupants_build_part:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
|
|
@ -100,7 +106,7 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
)
|
)
|
||||||
|
|
||||||
occupant_occupant_type = OccupantTypes.find_one(uu_id=data.occupant_uu_id)
|
occupant_occupant_type = OccupantTypes.filter_by_one(uu_id=data.occupant_uu_id)
|
||||||
if not occupant_occupant_type:
|
if not occupant_occupant_type:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
|
|
@ -111,7 +117,7 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
)
|
)
|
||||||
|
|
||||||
service = Services.find_one(uu_id=data.service_uu_id)
|
service = Services.filter_one(Services.uu_id == data.service_uu_id).data
|
||||||
if not service:
|
if not service:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
|
|
@ -122,26 +128,22 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
)
|
)
|
||||||
|
|
||||||
default_module = Modules.find_one(module_code="USR-PUB")
|
|
||||||
add_default_service = Services.find_one(module_id=default_module.id)
|
|
||||||
service_events = Service2Events.filter_all(
|
service_events = Service2Events.filter_all(
|
||||||
Service2Events.service_id == service.id,
|
Service2Events.service_id == service.id,
|
||||||
)
|
Service2Events.active == True,
|
||||||
default_service_events = Service2Events.filter_all(
|
).data
|
||||||
Service2Events.service_id == add_default_service.id,
|
if not service_events:
|
||||||
)
|
|
||||||
add_events_list = service_events.data + default_service_events.data
|
|
||||||
if not add_events_list:
|
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
detail="Service has no events registered. Please contact with your manager",
|
detail="Service has no events registered. Please contact with your manager",
|
||||||
)
|
)
|
||||||
|
|
||||||
living_space = BuildLivingSpace.find_one(
|
living_space = BuildLivingSpace.filter_one(
|
||||||
build_parts_id=occupants_build_part.id,
|
BuildLivingSpace.build_parts_id == occupants_build_part.id,
|
||||||
occupant_types_id=occupant_occupant_type.id,
|
BuildLivingSpace.occupant_types_id == occupant_occupant_type.id,
|
||||||
person_id=token_dict.person_id,
|
BuildLivingSpace.person_id == token_dict.person_id,
|
||||||
)
|
BuildLivingSpace.active == True,
|
||||||
|
).data
|
||||||
if not living_space:
|
if not living_space:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
|
|
@ -160,7 +162,7 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
||||||
"event_uu_id": str(service_event.event_uu_id),
|
"event_uu_id": str(service_event.event_uu_id),
|
||||||
"is_confirmed": True,
|
"is_confirmed": True,
|
||||||
}
|
}
|
||||||
for service_event in add_events_list
|
for service_event in service_events
|
||||||
]
|
]
|
||||||
|
|
||||||
session_execute = Services.session.execute(
|
session_execute = Services.session.execute(
|
||||||
|
|
@ -186,22 +188,13 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
||||||
def bind_services_employee(cls, service_id: int, employee_id: int):
|
def bind_services_employee(cls, service_id: int, employee_id: int):
|
||||||
from sqlalchemy.dialects.postgresql import insert
|
from sqlalchemy.dialects.postgresql import insert
|
||||||
|
|
||||||
employee = Employees.find_or_abort(
|
employee = Employees.filter_by_one(id=employee_id, *Employees.valid_record_dict)
|
||||||
id=employee_id,
|
service = Services.filter_by_one(id=service_id, *Services.valid_record_dict)
|
||||||
)
|
|
||||||
service = Services.find_or_abort(
|
|
||||||
id=service_id,
|
|
||||||
)
|
|
||||||
default_module = Modules.find_one(module_code="USR-PUB")
|
|
||||||
add_default_service = Services.find_one(module_id=default_module.id)
|
|
||||||
service_events = Service2Events.filter_all(
|
service_events = Service2Events.filter_all(
|
||||||
Service2Events.service_id == service.id,
|
Service2Events.service_id == service.id,
|
||||||
)
|
Service2Events.active == True,
|
||||||
default_service_events = Service2Events.filter_all(
|
).data
|
||||||
Service2Events.service_id == add_default_service.id,
|
if not service_events:
|
||||||
)
|
|
||||||
add_events_list = service_events.data + default_service_events.data
|
|
||||||
if not add_events_list:
|
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"Service has no events registered. Please contact with your manager"
|
"Service has no events registered. Please contact with your manager"
|
||||||
)
|
)
|
||||||
|
|
@ -214,7 +207,7 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
||||||
"event_uu_id": str(service_event.event_uu_id),
|
"event_uu_id": str(service_event.event_uu_id),
|
||||||
"is_confirmed": True,
|
"is_confirmed": True,
|
||||||
}
|
}
|
||||||
for service_event in add_events_list
|
for service_event in service_events
|
||||||
]
|
]
|
||||||
|
|
||||||
session_execute = Services.session.execute(
|
session_execute = Services.session.execute(
|
||||||
|
|
@ -242,7 +235,7 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
||||||
detail="Occupant is not authorized to add service to any employee",
|
detail="Occupant is not authorized to add service to any employee",
|
||||||
)
|
)
|
||||||
|
|
||||||
employee = Employees.find_one(uu_id=data.employee_uu_id)
|
employee = Employees.filter_by_one(uu_id=data.employee_uu_id, *Employees.valid_record_dict).data
|
||||||
if not employee:
|
if not employee:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
|
|
@ -253,7 +246,7 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
)
|
)
|
||||||
|
|
||||||
service = Services.find_one(uu_id=data.service_uu_id)
|
service = Services.filter_by_one(uu_id=data.service_uu_id, *Services.valid_record_dict).data
|
||||||
if not service:
|
if not service:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
|
|
@ -266,16 +259,9 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
||||||
|
|
||||||
service_events = Service2Events.filter_all(
|
service_events = Service2Events.filter_all(
|
||||||
Service2Events.service_id == service.id,
|
Service2Events.service_id == service.id,
|
||||||
)
|
Service2Events.active == True,
|
||||||
|
).data
|
||||||
default_module = Modules.find_one(module_code="USR-PUB")
|
if not service_events:
|
||||||
add_default_service = Services.find_one(module_id=default_module.id)
|
|
||||||
default_service_events = Service2Events.filter_all(
|
|
||||||
Service2Events.service_id == add_default_service.id,
|
|
||||||
)
|
|
||||||
|
|
||||||
add_events_list = service_events.data + default_service_events.data
|
|
||||||
if not add_events_list:
|
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
detail="Service has no events registered. Please contact with your manager",
|
detail="Service has no events registered. Please contact with your manager",
|
||||||
|
|
@ -289,7 +275,7 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
||||||
"event_uu_id": service_event.event_uu_id,
|
"event_uu_id": service_event.event_uu_id,
|
||||||
"is_confirmed": True,
|
"is_confirmed": True,
|
||||||
}
|
}
|
||||||
for service_event in add_events_list
|
for service_event in service_events
|
||||||
]
|
]
|
||||||
|
|
||||||
session_execute = Services.session.execute(
|
session_execute = Services.session.execute(
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ class EventsListEventMethods(MethodToEvent):
|
||||||
Events.filter_attr = list_options
|
Events.filter_attr = list_options
|
||||||
records = Events.filter_active(
|
records = Events.filter_active(
|
||||||
*Events.get_smart_query(list_options.query),
|
*Events.get_smart_query(list_options.query),
|
||||||
|
Events.active == True,
|
||||||
)
|
)
|
||||||
return AlchemyJsonResponse(
|
return AlchemyJsonResponse(
|
||||||
completed=True,
|
completed=True,
|
||||||
|
|
@ -82,7 +83,7 @@ class EventsUpdateEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def events_update(cls, data: CreateEvents, token_dict):
|
def events_update(cls, data: CreateEvents, token_dict):
|
||||||
event = Events.find_one(uu_id=data.uu_id)
|
event = Events.filter_by_one(uu_id=data.uu_id, *Events.valid_record_dict)
|
||||||
if not event:
|
if not event:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=404,
|
status_code=404,
|
||||||
|
|
@ -112,7 +113,7 @@ class EventsPatchEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def events_patch(cls, data: CreateEvents, token_dict):
|
def events_patch(cls, data: CreateEvents, token_dict):
|
||||||
event = Events.find_one(uu_id=data.uu_id)
|
event = Events.filter_by_one(uu_id=data.uu_id, *Events.valid_record_dict)
|
||||||
if not event:
|
if not event:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=404,
|
status_code=404,
|
||||||
|
|
@ -141,18 +142,29 @@ class EventsBindEventToOccupantMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def bind_events_employee(cls, data: RegisterEvents2Employee, token_dict):
|
def bind_events_employee(cls, data: RegisterEvents2Employee, token_dict):
|
||||||
events = Events.filter_active(Events.uu_id.in_(data.event_id))
|
events = Events.filter_all(
|
||||||
|
Events.uu_id.in_(data.event_id),
|
||||||
|
*Events.valid_record_args(Events),
|
||||||
|
).data
|
||||||
if not events:
|
if not events:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=401,
|
status_code=401,
|
||||||
detail="No event found. Please contact your super user.",
|
detail="No event found. Please contact your super user.",
|
||||||
)
|
)
|
||||||
|
|
||||||
employee = Employees.find_one(employee_uu_id=data.employee_uu_id)
|
|
||||||
employee_is_not_valid = False
|
employee_is_not_valid = False
|
||||||
|
employee = Employees.filter_one(
|
||||||
|
Employees.employee_uu_id == data.employee_uu_id,
|
||||||
|
*Employees.valid_record_args(Employees),
|
||||||
|
).data
|
||||||
if employee:
|
if employee:
|
||||||
staff = Staff.find_one(id=employee.staff_id)
|
staff = Staff.filter_one(
|
||||||
duties = Duties.find_one(id=staff.duties_id)
|
Staff.id == employee.staff_id,
|
||||||
|
*Staff.valid_record_args(Staff),
|
||||||
|
).data
|
||||||
|
duties = Duties.filter_one(
|
||||||
|
Duties.id == staff.duties_id,
|
||||||
|
*Duties.valid_record_args(Duties),
|
||||||
|
).data
|
||||||
if duties.company_id not in token_dict.companies_id_list:
|
if duties.company_id not in token_dict.companies_id_list:
|
||||||
employee_is_not_valid = True
|
employee_is_not_valid = True
|
||||||
|
|
||||||
|
|
@ -162,7 +174,7 @@ class EventsBindEventToOccupantMethods(MethodToEvent):
|
||||||
detail="This employee can not be reached by this user. Please contact your super user.",
|
detail="This employee can not be reached by this user. Please contact your super user.",
|
||||||
)
|
)
|
||||||
|
|
||||||
for event in events.data:
|
for event in events:
|
||||||
employee = Event2Employee.find_or_create(
|
employee = Event2Employee.find_or_create(
|
||||||
**token_dict.user_creds, employee_id=employee.id, event_id=event.id
|
**token_dict.user_creds, employee_id=employee.id, event_id=event.id
|
||||||
)
|
)
|
||||||
|
|
@ -183,21 +195,25 @@ class EventsBindEventToEmployeeMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def bind_events_occupant(cls, data: RegisterEvents2Occupant, token_dict):
|
def bind_events_occupant(cls, data: RegisterEvents2Occupant, token_dict):
|
||||||
events = Events.filter_active(Events.uu_id.in_(data.event_id))
|
events = Events.filter_all(
|
||||||
|
Events.uu_id.in_(data.event_id),
|
||||||
|
*Events.valid_record_args(Events),
|
||||||
|
).data
|
||||||
if not events:
|
if not events:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=401,
|
status_code=401,
|
||||||
detail="No event found. Please contact your super user.",
|
detail="No event found. Please contact your super user.",
|
||||||
)
|
)
|
||||||
occupant = BuildLivingSpace.find_one(uu_id=data.build_living_space_uu_id)
|
occupant = BuildLivingSpace.filter_one(
|
||||||
occupant_is_not_valid = False
|
BuildLivingSpace.uu_id == data.build_living_space_uu_id,
|
||||||
if occupant_is_not_valid:
|
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||||
|
).data
|
||||||
|
if not occupant:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=401,
|
status_code=401,
|
||||||
detail="This occupant can not be reached by this user. Please contact your super user.",
|
detail="This occupant can not be reached by this user. Please contact your super user.",
|
||||||
)
|
)
|
||||||
|
for event in events:
|
||||||
for event in events.data:
|
|
||||||
occupant = Event2Occupant.find_or_create(
|
occupant = Event2Occupant.find_or_create(
|
||||||
**token_dict.user_creds,
|
**token_dict.user_creds,
|
||||||
build_living_space_id=occupant.id,
|
build_living_space_id=occupant.id,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from api_validations.validations_request import (
|
from api_validations.validations_request import (
|
||||||
DepartmentsPydantic,
|
DepartmentsPydantic,
|
||||||
PatchRecord,
|
PatchRecord,
|
||||||
|
|
@ -12,27 +14,49 @@ from api_validations.core_response import AlchemyJsonResponse
|
||||||
class ServicesEvents(MethodToEvent):
|
class ServicesEvents(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def services_list(cls, list_options: ListOptions):
|
def services_list(
|
||||||
|
cls,
|
||||||
|
list_options: ListOptions,
|
||||||
|
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def services_create(cls, data: DepartmentsPydantic, token_dict):
|
def services_create(
|
||||||
|
cls,
|
||||||
|
data: DepartmentsPydantic,
|
||||||
|
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def services_update(cls, service_uu_id: str, data: DepartmentsPydantic, token_dict):
|
def services_update(
|
||||||
|
cls,
|
||||||
|
service_uu_id: str,
|
||||||
|
data: DepartmentsPydantic,
|
||||||
|
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def services_patch(cls, service_uu_id: str, data: PatchRecord, token_dict):
|
def services_patch(
|
||||||
|
cls,
|
||||||
|
service_uu_id: str,
|
||||||
|
data: PatchRecord,
|
||||||
|
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def bind_service_to_action(cls, data, token_dict):
|
def bind_service_to_action(
|
||||||
|
cls, data, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||||
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def bind_module_to_service(cls, data, token_dict):
|
def bind_module_to_service(
|
||||||
|
cls, data, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||||
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,13 @@ class PeopleListEventMethods(MethodToEvent):
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def super_users_people_list(cls, list_options, token_dict):
|
def super_users_people_list(
|
||||||
records = People.filter_active(
|
cls, list_options, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||||
*People.get_smart_query(smart_query=list_options.query)
|
):
|
||||||
)
|
records = People.filter_all(
|
||||||
|
*People.get_smart_query(smart_query=list_options.query),
|
||||||
|
*People.valid_record_args(People),
|
||||||
|
).data
|
||||||
return AlchemyJsonResponse(
|
return AlchemyJsonResponse(
|
||||||
completed=True,
|
completed=True,
|
||||||
message="People are listed successfully",
|
message="People are listed successfully",
|
||||||
|
|
@ -38,9 +41,13 @@ class PeopleListEventMethods(MethodToEvent):
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def sales_users_people_list(cls, data, token_dict):
|
def sales_users_people_list(
|
||||||
|
cls, list_options, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||||
records = People.filter_active(*People.get_smart_query(smart_query=data.query))
|
):
|
||||||
|
records = People.filter_all(
|
||||||
|
*People.get_smart_query(smart_query=list_options.query),
|
||||||
|
*People.valid_record_args(People),
|
||||||
|
).data
|
||||||
return AlchemyJsonResponse(
|
return AlchemyJsonResponse(
|
||||||
completed=True,
|
completed=True,
|
||||||
message="People are listed successfully",
|
message="People are listed successfully",
|
||||||
|
|
@ -48,9 +55,13 @@ class PeopleListEventMethods(MethodToEvent):
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def human_resources_users_people_list(cls, data, token_dict):
|
def human_resources_users_people_list(
|
||||||
|
cls, list_options, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||||
records = People.filter_active(*People.get_smart_query(smart_query=data.query))
|
):
|
||||||
|
records = People.filter_all(
|
||||||
|
*People.get_smart_query(smart_query=list_options.query),
|
||||||
|
*People.valid_record_args(People),
|
||||||
|
).data
|
||||||
return AlchemyJsonResponse(
|
return AlchemyJsonResponse(
|
||||||
completed=True,
|
completed=True,
|
||||||
message="People are listed successfully",
|
message="People are listed successfully",
|
||||||
|
|
@ -97,7 +108,10 @@ class PeopleUpdateEventMethods(MethodToEvent):
|
||||||
user_uu_id: str,
|
user_uu_id: str,
|
||||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
):
|
):
|
||||||
find_one_user = Users.find_one_or_abort(uu_id=user_uu_id)
|
find_one_user = Users.filter_one(
|
||||||
|
Users.uu_id == user_uu_id,
|
||||||
|
*Users.valid_record_args(Users),
|
||||||
|
).data
|
||||||
access_authorized_company = Companies.select_action(
|
access_authorized_company = Companies.select_action(
|
||||||
duty_id_list=[getattr(token_dict, "duty_id")],
|
duty_id_list=[getattr(token_dict, "duty_id")],
|
||||||
filter_expr=[Companies.id == find_one_user.id],
|
filter_expr=[Companies.id == find_one_user.id],
|
||||||
|
|
|
||||||
|
|
@ -40,19 +40,27 @@ class UserListEventMethods(MethodToEvent):
|
||||||
# ])
|
# ])
|
||||||
if "user_uu_id_list" in list_options.query:
|
if "user_uu_id_list" in list_options.query:
|
||||||
people_ids = list_options.query.pop("user_uu_id_list")
|
people_ids = list_options.query.pop("user_uu_id_list")
|
||||||
people_id_list = [
|
people_id_list = (
|
||||||
user.person_id
|
user.person_id
|
||||||
for user in Users.filter_active(Users.uu_id.in_(people_ids)).data
|
for user in Users.filter_all(
|
||||||
]
|
Users.uu_id.in_(people_ids), *Users.valid_record_args(Users)
|
||||||
|
).data
|
||||||
|
)
|
||||||
People.filter_attr = list_options
|
People.filter_attr = list_options
|
||||||
records = People.filter_active(People.id.in_(people_id_list))
|
records = People.filter_all(
|
||||||
|
People.id.in_(people_id_list),
|
||||||
|
*People.valid_record_args(People),
|
||||||
|
).data
|
||||||
return AlchemyJsonResponse(
|
return AlchemyJsonResponse(
|
||||||
completed=True,
|
completed=True,
|
||||||
message="Users are listed successfully",
|
message="Users are listed successfully",
|
||||||
result=records,
|
result=records,
|
||||||
)
|
)
|
||||||
People.filter_attr = list_options
|
Users.filter_attr = list_options
|
||||||
records = Users.filter_active(*Users.get_smart_query(list_options.query))
|
records = Users.filter_all(
|
||||||
|
*Users.get_smart_query(list_options.query),
|
||||||
|
*Users.valid_record_args(Users),
|
||||||
|
)
|
||||||
return AlchemyJsonResponse(
|
return AlchemyJsonResponse(
|
||||||
completed=True,
|
completed=True,
|
||||||
message="Users are listed successfully",
|
message="Users are listed successfully",
|
||||||
|
|
@ -114,9 +122,12 @@ class UserUpdateEventMethods(MethodToEvent):
|
||||||
user_uu_id: str,
|
user_uu_id: str,
|
||||||
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
):
|
):
|
||||||
find_one_user = Users.find_one_or_abort(uu_id=user_uu_id)
|
find_one_user = Users.filter_one(
|
||||||
|
Users.uu_id==user_uu_id,
|
||||||
|
*Users.valid_record_args(Users),
|
||||||
|
).data
|
||||||
access_authorized_company = Companies.select_action(
|
access_authorized_company = Companies.select_action(
|
||||||
duty_id=getattr(token_dict, "duty_id", 5),
|
duty_id_list=[getattr(token_dict, "duty_id", 5)],
|
||||||
filter_expr=[Companies.id == token_dict.get("")],
|
filter_expr=[Companies.id == token_dict.get("")],
|
||||||
)
|
)
|
||||||
if access_authorized_company.count:
|
if access_authorized_company.count:
|
||||||
|
|
@ -146,9 +157,12 @@ class UserPatchEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def user_patch(cls, data: PatchRecord, user_uu_id: str, token_dict):
|
def user_patch(cls, data: PatchRecord, user_uu_id: str, token_dict):
|
||||||
find_one_user = Users.find_one_or_abort(uu_id=user_uu_id)
|
find_one_user = Users.filter_one(
|
||||||
|
Users.uu_id==user_uu_id,
|
||||||
|
*Users.valid_record_args(Users),
|
||||||
|
).data
|
||||||
access_authorized_company = Companies.select_action(
|
access_authorized_company = Companies.select_action(
|
||||||
duty_id=getattr(token_dict, "duty_id", 5),
|
duty_id_list=[getattr(token_dict, "duty_id", 5)],
|
||||||
filter_expr=[Companies.id == find_one_user.id],
|
filter_expr=[Companies.id == find_one_user.id],
|
||||||
)
|
)
|
||||||
if access_authorized_company.count:
|
if access_authorized_company.count:
|
||||||
|
|
|
||||||
|
|
@ -74,11 +74,13 @@ class AuthModule(PasswordModule):
|
||||||
def remove_refresher_token(self, domain, disconnect: bool = False):
|
def remove_refresher_token(self, domain, disconnect: bool = False):
|
||||||
if disconnect:
|
if disconnect:
|
||||||
registered_tokens = UsersTokens.filter_all(
|
registered_tokens = UsersTokens.filter_all(
|
||||||
UsersTokens.user_id==self.id, system=True
|
UsersTokens.user_id == self.id, system=True
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
registered_tokens = UsersTokens.filter_all(
|
registered_tokens = UsersTokens.filter_all(
|
||||||
UsersTokens.domain==domain, UsersTokens.user_id==self.id, system=True
|
UsersTokens.domain == domain,
|
||||||
|
UsersTokens.user_id == self.id,
|
||||||
|
system=True,
|
||||||
)
|
)
|
||||||
registered_tokens.query.delete()
|
registered_tokens.query.delete()
|
||||||
UsersTokens.save()
|
UsersTokens.save()
|
||||||
|
|
|
||||||
|
|
@ -341,15 +341,16 @@ class Build(CrudCollection, SelectActionWithEmployee):
|
||||||
@classmethod
|
@classmethod
|
||||||
def update_action(cls, data: UpdateBuild, build_uu_id: str, token):
|
def update_action(cls, data: UpdateBuild, build_uu_id: str, token):
|
||||||
from databases import Addresses
|
from databases import Addresses
|
||||||
|
|
||||||
data_dict = data.excluded_dump()
|
data_dict = data.excluded_dump()
|
||||||
if data.official_address_uu_id:
|
if data.official_address_uu_id:
|
||||||
official_address = Addresses.filter_one(
|
official_address = Addresses.filter_one(
|
||||||
Addresses.uu_id==data.address_uu_id
|
Addresses.uu_id == data.address_uu_id
|
||||||
).data
|
).data
|
||||||
data_dict["address_id"] = official_address.id if official_address else None
|
data_dict["address_id"] = official_address.id if official_address else None
|
||||||
del data_dict["address_uu_id"]
|
del data_dict["address_uu_id"]
|
||||||
if build_to_update := cls.filter_one(
|
if build_to_update := cls.filter_one(
|
||||||
cls.uu_id==build_uu_id, cls.person_id==token.id
|
cls.uu_id == build_uu_id, cls.person_id == token.id
|
||||||
).data:
|
).data:
|
||||||
return build_to_update.update(**data_dict)
|
return build_to_update.update(**data_dict)
|
||||||
|
|
||||||
|
|
@ -491,7 +492,7 @@ class BuildParts(CrudCollection):
|
||||||
)
|
)
|
||||||
|
|
||||||
if build_types := BuildTypes.filter_one(
|
if build_types := BuildTypes.filter_one(
|
||||||
BuildTypes.uu_id==data.build_part_type_uu_id
|
BuildTypes.uu_id == data.build_part_type_uu_id
|
||||||
).data:
|
).data:
|
||||||
part_direction = ApiEnumDropdown.get_by_uuid(
|
part_direction = ApiEnumDropdown.get_by_uuid(
|
||||||
uuid=str(data.part_direction_uu_id)
|
uuid=str(data.part_direction_uu_id)
|
||||||
|
|
|
||||||
|
|
@ -406,9 +406,9 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||||
**book_dict
|
**book_dict
|
||||||
):
|
):
|
||||||
decision_book = BuildDecisionBook.filter_one(
|
decision_book = BuildDecisionBook.filter_one(
|
||||||
BuildDecisionBook.id==self.build_decision_book_id,
|
BuildDecisionBook.id == self.build_decision_book_id,
|
||||||
BuildDecisionBook.active==True,
|
BuildDecisionBook.active == True,
|
||||||
BuildDecisionBook.is_confirmed==True
|
BuildDecisionBook.is_confirmed == True,
|
||||||
).data
|
).data
|
||||||
person_occupants.update(
|
person_occupants.update(
|
||||||
expiry_starts=decision_book.expiry_starts,
|
expiry_starts=decision_book.expiry_starts,
|
||||||
|
|
@ -417,8 +417,7 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||||
if build_living_space_id:
|
if build_living_space_id:
|
||||||
related_service = Services.filter_by_one(
|
related_service = Services.filter_by_one(
|
||||||
related_responsibility=str(occupant_type.occupant_code),
|
related_responsibility=str(occupant_type.occupant_code),
|
||||||
active=True,
|
*Services.valid_record_dict
|
||||||
is_confirmed=True,
|
|
||||||
)
|
)
|
||||||
if not related_service:
|
if not related_service:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -427,9 +426,9 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||||
)
|
)
|
||||||
|
|
||||||
decision_build = Build.filter_one(
|
decision_build = Build.filter_one(
|
||||||
Build.id==decision_book.build_id,
|
Build.id == decision_book.build_id,
|
||||||
Build.active==True,
|
Build.active == True,
|
||||||
Build.is_confirmed==True
|
Build.is_confirmed == True,
|
||||||
).data
|
).data
|
||||||
management_room = decision_build.management_room
|
management_room = decision_build.management_room
|
||||||
if not management_room:
|
if not management_room:
|
||||||
|
|
@ -439,16 +438,14 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||||
)
|
)
|
||||||
|
|
||||||
living_space = BuildLivingSpace.filter_one(
|
living_space = BuildLivingSpace.filter_one(
|
||||||
BuildLivingSpace.id==build_living_space_id,
|
BuildLivingSpace.id == build_living_space_id,
|
||||||
BuildLivingSpace.active==True,
|
BuildLivingSpace.active == True,
|
||||||
BuildLivingSpace.is_confirmed==True
|
BuildLivingSpace.is_confirmed == True,
|
||||||
).data
|
).data
|
||||||
expiry_ends = str(
|
expiry_ends = str(
|
||||||
system_arrow.get(decision_book.meeting_date).shift(hours=23)
|
system_arrow.get(decision_book.meeting_date).shift(hours=23)
|
||||||
)
|
)
|
||||||
expiry_starts = str(
|
expiry_starts = str(system_arrow.get(decision_book.meeting_date))
|
||||||
system_arrow.get(decision_book.meeting_date)
|
|
||||||
)
|
|
||||||
related_living_space = BuildLivingSpace.find_or_create(
|
related_living_space = BuildLivingSpace.find_or_create(
|
||||||
build_parts_id=management_room.id,
|
build_parts_id=management_room.id,
|
||||||
build_parts_uu_id=str(management_room.uu_id),
|
build_parts_uu_id=str(management_room.uu_id),
|
||||||
|
|
@ -481,10 +478,10 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||||
|
|
||||||
def check_occupant_type(self, occupant_type):
|
def check_occupant_type(self, occupant_type):
|
||||||
book_person_occupant_type = BuildDecisionBookPersonOccupants.filter_one(
|
book_person_occupant_type = BuildDecisionBookPersonOccupants.filter_one(
|
||||||
BuildDecisionBookPersonOccupants.build_decision_book_person_id==self.id,
|
BuildDecisionBookPersonOccupants.build_decision_book_person_id == self.id,
|
||||||
BuildDecisionBookPersonOccupants.occupant_type_id==occupant_type.id,
|
BuildDecisionBookPersonOccupants.occupant_type_id == occupant_type.id,
|
||||||
BuildDecisionBookPersonOccupants.active==True,
|
BuildDecisionBookPersonOccupants.active == True,
|
||||||
BuildDecisionBookPersonOccupants.is_confirmed==True,
|
BuildDecisionBookPersonOccupants.is_confirmed == True,
|
||||||
).data
|
).data
|
||||||
if not book_person_occupant_type:
|
if not book_person_occupant_type:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,8 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||||
|
|
||||||
creds: Credentials = None # The credentials to use in the model.
|
creds: Credentials = None # The credentials to use in the model.
|
||||||
client_arrow: DateTimeLocal = None # The arrow to use in the model.
|
client_arrow: DateTimeLocal = None # The arrow to use in the model.
|
||||||
|
valid_record_dict: dict = {"active": True, "deleted": False}
|
||||||
|
valid_record_args = lambda class_: [class_.active == True, class_.deleted == False]
|
||||||
|
|
||||||
expiry_starts: Mapped[TIMESTAMP] = mapped_column(
|
expiry_starts: Mapped[TIMESTAMP] = mapped_column(
|
||||||
TIMESTAMP, server_default=func.now(), nullable=False
|
TIMESTAMP, server_default=func.now(), nullable=False
|
||||||
|
|
|
||||||
|
|
@ -181,12 +181,16 @@ class Event2Occupant(CrudCollection):
|
||||||
def get_event_id_by_build_living_space_id(
|
def get_event_id_by_build_living_space_id(
|
||||||
cls, build_living_space_id
|
cls, build_living_space_id
|
||||||
) -> (list, list):
|
) -> (list, list):
|
||||||
active_events = cls.filter_by_active(
|
active_events = cls.filter_all(
|
||||||
build_living_space_id=build_living_space_id
|
cls.build_living_space_id==build_living_space_id,
|
||||||
)
|
*cls.valid_record_args(cls)
|
||||||
active_events_id = [event.event_id for event in active_events.data]
|
).data
|
||||||
active_events = Events.filter_active(Events.id.in_(active_events_id))
|
active_events_id = [event.event_id for event in active_events]
|
||||||
active_events_uu_id = [str(event.uu_id) for event in active_events.data]
|
active_events = Events.filter_all(
|
||||||
|
Events.id.in_(active_events_id),
|
||||||
|
*Events.valid_record_args(Events)
|
||||||
|
).data
|
||||||
|
active_events_uu_id = [str(event.uu_id) for event in active_events]
|
||||||
return active_events_id, active_events_uu_id
|
return active_events_id, active_events_uu_id
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -136,8 +136,10 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_action(cls, create_user: InsertUsers):
|
def create_action(cls, create_user: InsertUsers):
|
||||||
|
found_person = People.filter_one(
|
||||||
found_person = People.find_one(uu_id=create_user.people_uu_id)
|
People.uu_id==create_user.people_uu_id,
|
||||||
|
*People.valid_record_args(People),
|
||||||
|
).data
|
||||||
if not found_person:
|
if not found_person:
|
||||||
raise HTTPException(status_code=400, detail="Person not found.")
|
raise HTTPException(status_code=400, detail="Person not found.")
|
||||||
if (
|
if (
|
||||||
|
|
@ -403,7 +405,6 @@ class People(CrudCollection, SelectAction):
|
||||||
create_dict["surname"] = str(create_dict["surname"]).upper()
|
create_dict["surname"] = str(create_dict["surname"]).upper()
|
||||||
create_dict["birth_place"] = str(create_dict["birth_place"]).upper()
|
create_dict["birth_place"] = str(create_dict["birth_place"]).upper()
|
||||||
created_people = cls.find_or_create(**create_dict)
|
created_people = cls.find_or_create(**create_dict)
|
||||||
if not created_people.is_found:
|
|
||||||
RelationshipDutyPeople.find_or_create(
|
RelationshipDutyPeople.find_or_create(
|
||||||
company_id=token.selected_company.company_id,
|
company_id=token.selected_company.company_id,
|
||||||
duties_id=bulk_duty.id,
|
duties_id=bulk_duty.id,
|
||||||
|
|
@ -495,7 +496,7 @@ class Addresses(CrudCollection):
|
||||||
post_code_list = RelationshipEmployee2PostCode.filter_all(
|
post_code_list = RelationshipEmployee2PostCode.filter_all(
|
||||||
RelationshipEmployee2PostCode.employee_id
|
RelationshipEmployee2PostCode.employee_id
|
||||||
== token_dict.selected_company.employee_id,
|
== token_dict.selected_company.employee_id,
|
||||||
RelationshipEmployee2PostCode.active==True,
|
RelationshipEmployee2PostCode.active == True,
|
||||||
).data
|
).data
|
||||||
post_code_id_list = [post_code.member_id for post_code in post_code_list]
|
post_code_id_list = [post_code.member_id for post_code in post_code_list]
|
||||||
if not post_code_id_list:
|
if not post_code_id_list:
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,8 @@ class ApiEnumDropdown(BaseCollection):
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_due_types(cls):
|
def get_due_types(cls):
|
||||||
if due_list := cls.filter_all(
|
if due_list := cls.filter_all(
|
||||||
cls.enum_class == "BuildDuesTypes", cls.key.in_(["BDT-A", "BDT-D"]),
|
cls.enum_class == "BuildDuesTypes",
|
||||||
|
cls.key.in_(["BDT-A", "BDT-D"]),
|
||||||
cls.active == True,
|
cls.active == True,
|
||||||
).data:
|
).data:
|
||||||
return [due.uu_id.__str__() for due in due_list]
|
return [due.uu_id.__str__() for due in due_list]
|
||||||
|
|
@ -98,9 +99,13 @@ class ApiEnumDropdown(BaseCollection):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def uuid_of_enum(cls, enum_class: str, key: str):
|
def uuid_of_enum(cls, enum_class: str, key: str):
|
||||||
return str(getattr(cls.filter_one(
|
return str(
|
||||||
cls.enum_class==enum_class, cls.key==key
|
getattr(
|
||||||
).data, "uu_id", None))
|
cls.filter_one(cls.enum_class == enum_class, cls.key == key).data,
|
||||||
|
"uu_id",
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
ApiEnumDropdown.set_session(ApiEnumDropdown.__session__)
|
ApiEnumDropdown.set_session(ApiEnumDropdown.__session__)
|
||||||
|
|
|
||||||
|
|
@ -76,22 +76,21 @@ def authentication_refresh_user_info(request: Request):
|
||||||
|
|
||||||
@login_route.post(path="/change_password", summary="Change password with access token")
|
@login_route.post(path="/change_password", summary="Change password with access token")
|
||||||
def authentication_change_password(request: Request, data: ChangePassword):
|
def authentication_change_password(request: Request, data: ChangePassword):
|
||||||
|
token_dict = parse_token_object_to_dict(request=request)
|
||||||
active_function = getattr(
|
active_function = getattr(
|
||||||
AuthenticationChangePasswordEventMethod, "authentication_change_password"
|
AuthenticationChangePasswordEventMethod, "authentication_change_password"
|
||||||
)
|
)
|
||||||
return active_function(data=data, request=request, token_dict=None)
|
return active_function(data=data, token_dict=token_dict)
|
||||||
|
|
||||||
|
|
||||||
@login_route.post(
|
@login_route.post(
|
||||||
path="/create_password", summary="Create password with password token"
|
path="/create_password", summary="Create password with password token"
|
||||||
)
|
)
|
||||||
def authentication_create_password(request: Request, data: CreatePassword):
|
def authentication_create_password(data: CreatePassword):
|
||||||
|
|
||||||
active_function = getattr(
|
active_function = getattr(
|
||||||
AuthenticationCreatePasswordEventMethod, "authentication_create_password"
|
AuthenticationCreatePasswordEventMethod, "authentication_create_password"
|
||||||
)
|
)
|
||||||
return active_function(data=data, request=request, token_dict=None)
|
return active_function(data=data)
|
||||||
|
|
||||||
|
|
||||||
@login_route.post(path="/disconnect", summary="Disconnect user with access token")
|
@login_route.post(path="/disconnect", summary="Disconnect user with access token")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue