migrator functions updated
This commit is contained in:
parent
f6135ced5f
commit
ffb85a62f6
|
|
@ -14,8 +14,7 @@ class ActionsSchema(ABC):
|
|||
from databases import EndpointRestriction
|
||||
|
||||
endpoint_restriction = EndpointRestriction.filter_one(
|
||||
EndpointRestriction.endpoint_name.ilike(f"%{self.endpoint}%"),
|
||||
system=True
|
||||
EndpointRestriction.endpoint_name.ilike(f"%{self.endpoint}%"), system=True
|
||||
).data
|
||||
if not endpoint_restriction:
|
||||
raise HTTPException(
|
||||
|
|
|
|||
|
|
@ -558,7 +558,9 @@ class AuthenticationRefreshTokenEventMethods(MethodToEvent):
|
|||
cls, request: Request, data: Remember, token_dict: dict = None
|
||||
):
|
||||
token_refresher = UsersTokens.filter_by_one(
|
||||
token=data.refresh_token, domain=data.domain, **UsersTokens.valid_record_dict
|
||||
token=data.refresh_token,
|
||||
domain=data.domain,
|
||||
**UsersTokens.valid_record_dict,
|
||||
).data
|
||||
if not token_refresher:
|
||||
return JSONResponse(
|
||||
|
|
|
|||
|
|
@ -71,6 +71,12 @@ class AuthenticationLoginEventMethods(MethodToEvent):
|
|||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials"
|
||||
)
|
||||
access_object = access_dict.get("access_object")
|
||||
if not access_object:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="This User has no active role registered. Please contact your administrator."
|
||||
)
|
||||
|
||||
return JSONResponse(
|
||||
content={
|
||||
|
|
@ -111,11 +117,15 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
|||
},
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
)
|
||||
if selected_company := Companies.find_one(uu_id=data.company_uu_id):
|
||||
if selected_company := Companies.filter_one(
|
||||
Companies.uu_id==data.company_uu_id,
|
||||
*Companies.valid_record_args(Companies),
|
||||
).data:
|
||||
department_ids = [
|
||||
department.id
|
||||
for department in Departments.filter_by_active(
|
||||
company_id=selected_company.id
|
||||
for department in Departments.filter_all(
|
||||
Departments.company_id==selected_company.id,
|
||||
*Departments.valid_record_args(Departments),
|
||||
).data
|
||||
]
|
||||
duties_ids = [
|
||||
|
|
@ -154,12 +164,12 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
|||
Departments.id == duties.department_id,
|
||||
).data
|
||||
bulk_id = Duty.filter_by_one(
|
||||
duty_code="BULK", **Duty.valid_record_args(Duty)
|
||||
duty_code="BULK", **Duty.valid_record_dict
|
||||
).data
|
||||
bulk_duty_id = Duties.filter_by_one(
|
||||
company_id=selected_company.id,
|
||||
duties_id=bulk_id.id,
|
||||
*Duties.valid_record_dict,
|
||||
**Duties.valid_record_dict,
|
||||
).data
|
||||
update_selected_to_redis(
|
||||
request=request,
|
||||
|
|
@ -187,13 +197,13 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
|||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
elif token_user.user_type == 2:
|
||||
occupant_type = OccupantTypes.filter_by_one(uu_id=data.occupant_uu_id).data
|
||||
occupant_type = OccupantTypes.filter_by_one(system=True, uu_id=data.occupant_uu_id).data
|
||||
if not occupant_type:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Occupant Type is not found",
|
||||
)
|
||||
build_part = BuildParts.filter_by_one(uu_id=data.build_part_uu_id).data
|
||||
build_part = BuildParts.filter_by_one(system=True, uu_id=data.build_part_uu_id).data
|
||||
if not build_part:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
|
|
@ -213,7 +223,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
|||
Companies.id == related_company.company_id,
|
||||
*Companies.valid_record_args(Companies),
|
||||
).data
|
||||
responsible_employee = Employees.find_one(
|
||||
responsible_employee = Employees.filter_one(
|
||||
Employees.id == related_company.employee_id,
|
||||
*Employees.valid_record_args(Employees),
|
||||
).data
|
||||
|
|
@ -389,7 +399,7 @@ class AuthenticationCreatePasswordEventMethods(MethodToEvent):
|
|||
},
|
||||
status_code=status.HTTP_202_ACCEPTED,
|
||||
)
|
||||
found_user.create_password(found_user=found_user,password=data.password)
|
||||
found_user.create_password(found_user=found_user, password=data.password)
|
||||
# send_email_completed = send_email(
|
||||
# subject=f"Dear {found_user.user_tag}, your password has been changed.",
|
||||
# receivers=[str(found_user.email)],
|
||||
|
|
@ -409,7 +419,6 @@ class AuthenticationCreatePasswordEventMethods(MethodToEvent):
|
|||
)
|
||||
|
||||
|
||||
|
||||
class AuthenticationDisconnectUserEventMethods(MethodToEvent):
|
||||
|
||||
event_type = "UPDATE"
|
||||
|
|
@ -441,7 +450,10 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
|
|||
for key in already_tokens:
|
||||
token_user = json.loads(redis_cli.get(key) or {})
|
||||
redis_cli.delete(key)
|
||||
selected_user = Users.find_one(uu_id=token_user.get("uu_id"))
|
||||
selected_user = Users.filter_one(
|
||||
Users.uu_id==token_user.get("uu_id"),
|
||||
*Users.valid_record_args(Users),
|
||||
)
|
||||
selected_user.remove_refresher_token(
|
||||
domain=data.domain, disconnect=True
|
||||
)
|
||||
|
|
@ -499,7 +511,10 @@ class AuthenticationLogoutEventMethods(MethodToEvent):
|
|||
for token_user in token_users:
|
||||
if token_dict.domain == data.domain:
|
||||
redis_cli.delete(token_user)
|
||||
selected_user = Users.find_one(uu_id=token_user.get("uu_id"))
|
||||
selected_user = Users.filter_one(
|
||||
Users.uu_id==token_user.get("uu_id"),
|
||||
*Users.valid_record_args(Users),
|
||||
)
|
||||
selected_user.remove_refresher_token(domain=data.domain)
|
||||
# UserLogger.log_error(
|
||||
# str(
|
||||
|
|
@ -537,8 +552,8 @@ class AuthenticationRefreshTokenEventMethods(MethodToEvent):
|
|||
def authentication_refresher_token(
|
||||
cls, request: Request, data: Remember, token_dict: dict = None
|
||||
):
|
||||
token_refresher = UsersTokens.find_one(
|
||||
token=data.refresh_token, domain=data.domain
|
||||
token_refresher = UsersTokens.filter_by_one(
|
||||
system=True, token=data.refresh_token, domain=data.domain
|
||||
)
|
||||
if not token_refresher:
|
||||
return JSONResponse(
|
||||
|
|
|
|||
|
|
@ -60,27 +60,19 @@ class CompanyCreateEventMethods(MethodToEvent):
|
|||
}
|
||||
|
||||
@classmethod
|
||||
def company_create(cls, data: InsertCompany, token_dict):
|
||||
def company_create(
|
||||
cls, data: InsertCompany, token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject]
|
||||
):
|
||||
created_company = Companies.create_action(
|
||||
data=data, token=token_dict.companies_list
|
||||
data=data, token=token_dict
|
||||
)
|
||||
created_company.related_company = token_dict.get("company_uu_id")
|
||||
created_company.flush()
|
||||
created_company.related_company = token_dict.selected_company.company_uu_id
|
||||
created_company.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
"message": "Create Company record",
|
||||
"data": created_company.get_dict(),
|
||||
"password_token": {
|
||||
"password_token": created_company.password_token,
|
||||
"password_expires_day": str(created_company.password_expires_day),
|
||||
"password_expiry_begins": str(
|
||||
created_company.password_expiry_begins
|
||||
),
|
||||
"hash_password": created_company.hash_password,
|
||||
"related_company": created_company.related_company,
|
||||
},
|
||||
"data": created_company.get_dict()
|
||||
},
|
||||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -58,11 +58,11 @@ class EmployeeCreateEventMethods(MethodToEvent):
|
|||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
person = People.filter_one(
|
||||
People.uu_id==data.people_uu_id,
|
||||
People.uu_id == data.people_uu_id,
|
||||
*People.valid_record_args(People),
|
||||
).data
|
||||
staff = Staff.filter_one(
|
||||
Staff.uu_id==data.staff_uu_id,
|
||||
Staff.uu_id == data.staff_uu_id,
|
||||
*Staff.valid_record_args(Staff),
|
||||
).data
|
||||
if not staff:
|
||||
|
|
@ -101,7 +101,7 @@ class EmployeeUpdateEventMethods(MethodToEvent):
|
|||
@classmethod
|
||||
def employee_update(cls, employee_uu_id: str, data: PatchRecord, token_dict):
|
||||
find_one_employee = Employees.filter_one(
|
||||
Employees.uu_id==employee_uu_id,
|
||||
Employees.uu_id == employee_uu_id,
|
||||
*Employees.valid_record_args(Employees),
|
||||
).data
|
||||
access_authorized_employee = Employees.select_action(
|
||||
|
|
@ -188,12 +188,11 @@ class Employee2PeopleEmployEventMethods(MethodToEvent):
|
|||
@classmethod
|
||||
def company_employee_employ(cls, data: BindEmployees2People, token_dict):
|
||||
selected_staff = Staff.filter_one(
|
||||
Staff.uu_id==data.staff_uu_id,
|
||||
Staff.uu_id == data.staff_uu_id,
|
||||
*Staff.valid_record_args(Staff),
|
||||
).data
|
||||
selected_people = People.filter_one(
|
||||
People.uu_id==data.people_uu_id,
|
||||
*People.valid_record_args
|
||||
People.uu_id == data.people_uu_id, *People.valid_record_args
|
||||
).data
|
||||
if not selected_staff:
|
||||
raise HTTPException(
|
||||
|
|
@ -251,7 +250,7 @@ class Employee2PeopleFireEventMethods(MethodToEvent):
|
|||
@classmethod
|
||||
def company_employee_fire(cls, data: BindEmployees2People, token_dict):
|
||||
selected_people = People.filter_one(
|
||||
People.uu_id==data.people_uu_id,
|
||||
People.uu_id == data.people_uu_id,
|
||||
*People.valid_record_args(People),
|
||||
).data
|
||||
if not selected_people:
|
||||
|
|
@ -261,7 +260,7 @@ class Employee2PeopleFireEventMethods(MethodToEvent):
|
|||
)
|
||||
|
||||
find_one_employee: Employees = Employees.filter_one(
|
||||
Employees.people_id==selected_people.id,
|
||||
Employees.people_id == selected_people.id,
|
||||
*Employees.valid_record_args(Employees),
|
||||
).data
|
||||
if not find_one_employee:
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class StaffCreateEventMethods(MethodToEvent):
|
|||
def staff_create(cls, data: InsertStaff, token_dict: EmployeeTokenObject):
|
||||
data_dict = data.excluded_dump()
|
||||
duties = Duties.filter_one(
|
||||
Duties.uu_id==data.duties_uu_id,
|
||||
Duties.uu_id == data.duties_uu_id,
|
||||
*Duties.valid_record_args(Duties),
|
||||
).data
|
||||
if not duties:
|
||||
|
|
@ -77,12 +77,10 @@ class StaffGetByUUIDEventMethods(MethodToEvent):
|
|||
def staff_get_by_uu_id(cls, data: SelectStaff, token_dict):
|
||||
if data.duties_uu_id:
|
||||
duties_id = Duties.filter_one(
|
||||
Duties.uu_id==data.duties_uu_id,
|
||||
*Duties.valid_record_args(Duties)
|
||||
Duties.uu_id == data.duties_uu_id, *Duties.valid_record_args(Duties)
|
||||
).data
|
||||
selected_staffs = Staff.filter_all(
|
||||
Staff.duties_id == duties_id.id,
|
||||
*Staff.valid_record_args(Staff)
|
||||
Staff.duties_id == duties_id.id, *Staff.valid_record_args(Staff)
|
||||
)
|
||||
return JSONResponse(
|
||||
content={
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class DecisionBookDecisionBookItemsListEventMethods(MethodToEvent):
|
|||
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
decision_book = BuildDecisionBook.filter_one(
|
||||
BuildDecisionBook.uu_id==data.build_decision_book_uu_id,
|
||||
BuildDecisionBook.uu_id == data.build_decision_book_uu_id,
|
||||
*BuildDecisionBook.valid_record_args(BuildDecisionBook),
|
||||
)
|
||||
if not decision_book:
|
||||
|
|
@ -232,17 +232,17 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
|
|||
== f"{decision_book.decision_type}_{data_info_type.key}",
|
||||
).data
|
||||
management_room = BuildParts.filter_one(
|
||||
BuildParts.build_id==build_id,
|
||||
BuildParts.part_no==0,
|
||||
BuildParts.build_id == build_id,
|
||||
BuildParts.part_no == 0,
|
||||
*BuildParts.valid_record_args(BuildParts),
|
||||
).data
|
||||
occupant_man = OccupantTypes.filter_by_one(
|
||||
occupant_code="MT-VPR", occupant_category_type="MT"
|
||||
).data
|
||||
manager_living_space = BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.build_parts_id==management_room.id,
|
||||
BuildLivingSpace.occupant_type==occupant_man.id,
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace)
|
||||
BuildLivingSpace.build_parts_id == management_room.id,
|
||||
BuildLivingSpace.occupant_type == occupant_man.id,
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
).data
|
||||
if not manager_living_space.data:
|
||||
raise HTTPException(
|
||||
|
|
@ -322,12 +322,12 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
|
|||
)
|
||||
|
||||
decision_book_person = BuildDecisionBookPerson.filter_one(
|
||||
BuildDecisionBookPerson.token==data.token,
|
||||
*BuildDecisionBookPerson.valid_record_args(BuildDecisionBookPerson)
|
||||
BuildDecisionBookPerson.token == data.token,
|
||||
*BuildDecisionBookPerson.valid_record_args(BuildDecisionBookPerson),
|
||||
).data
|
||||
decision_book = BuildDecisionBook.filter_one(
|
||||
BuildDecisionBook.id==decision_book_person.build_decision_book_id,
|
||||
*BuildDecisionBook.valid_record_args(BuildDecisionBook)
|
||||
BuildDecisionBook.id == decision_book_person.build_decision_book_id,
|
||||
*BuildDecisionBook.valid_record_args(BuildDecisionBook),
|
||||
).data
|
||||
BuildDecisionBookItems.check_meeting_is_valid_to_start_add_attendance(
|
||||
decision_book=decision_book,
|
||||
|
|
|
|||
|
|
@ -62,8 +62,8 @@ class DecisionBookPersonAddEventMethods(MethodToEvent):
|
|||
)
|
||||
elif isinstance(token_dict, OccupantTokenObject):
|
||||
decision_book = BuildDecisionBook.filter_one(
|
||||
BuildDecisionBook.uu_id==data.build_decision_book_uu_id,
|
||||
*BuildDecisionBook.valid_record_args(BuildDecisionBook)
|
||||
BuildDecisionBook.uu_id == data.build_decision_book_uu_id,
|
||||
*BuildDecisionBook.valid_record_args(BuildDecisionBook),
|
||||
).data
|
||||
if not decision_book:
|
||||
raise HTTPException(
|
||||
|
|
@ -281,7 +281,7 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
|
|||
|
||||
build_parts_of_token = BuildParts.filter_all(
|
||||
BuildParts.build_id == token_dict.selected_occupant.build_id,
|
||||
*BuildParts.valid_record_args(BuildParts)
|
||||
*BuildParts.valid_record_args(BuildParts),
|
||||
).data
|
||||
selected_living_space = BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.uu_id == data.build_living_space_uu_id,
|
||||
|
|
|
|||
|
|
@ -136,7 +136,8 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
|||
|
||||
# Get all the parts of the building that is occupant in token
|
||||
build_parts = BuildParts.filter_all(
|
||||
BuildParts.build_id == occupant_building.id, *BuildParts.valid_record_args(BuildParts)
|
||||
BuildParts.build_id == occupant_building.id,
|
||||
*BuildParts.valid_record_args(BuildParts),
|
||||
)
|
||||
|
||||
# Get all build living spaces that is found in building with distinct person id
|
||||
|
|
@ -184,9 +185,10 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
|||
# Check if the invitation is already created at database
|
||||
for build_living_spaces_user in build_living_spaces_people:
|
||||
if invite := BuildDecisionBookPerson.filter_one(
|
||||
BuildDecisionBookPerson.invite_id==book_invitation.id,
|
||||
BuildDecisionBookPerson.build_living_space_id==build_living_spaces_user.id,
|
||||
*BuildDecisionBookPerson.valid_record_args(BuildDecisionBookPerson)
|
||||
BuildDecisionBookPerson.invite_id == book_invitation.id,
|
||||
BuildDecisionBookPerson.build_living_space_id
|
||||
== build_living_spaces_user.id,
|
||||
*BuildDecisionBookPerson.valid_record_args(BuildDecisionBookPerson),
|
||||
).data:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
|
|
@ -217,7 +219,7 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
|||
|
||||
manager_living_spaces = BuildLivingSpace.filter_all(
|
||||
BuildLivingSpace.person_id == token_dict.person_id,
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace)
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
)
|
||||
manager_people = BuildDecisionBookPerson.filter_all(
|
||||
BuildDecisionBookPerson.invite_id == book_invitation.id,
|
||||
|
|
@ -227,12 +229,14 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
|||
for manager_living_space in manager_living_spaces.data
|
||||
]
|
||||
),
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace)
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
)
|
||||
manager_people_occupants = BuildDecisionBookPersonOccupants.filter_all(
|
||||
BuildDecisionBookPersonOccupants.build_decision_book_person_id
|
||||
== manager_people.get(1).id,
|
||||
*BuildDecisionBookPersonOccupants.valid_record_args(BuildDecisionBookPersonOccupants)
|
||||
*BuildDecisionBookPersonOccupants.valid_record_args(
|
||||
BuildDecisionBookPersonOccupants
|
||||
),
|
||||
)
|
||||
manager_people_occupants.query.delete()
|
||||
manager_people.query.delete()
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class EventBindOccupantEventMethods(MethodToEvent):
|
|||
|
||||
events_to_add_to_occupant = Events.filter_all(
|
||||
Events.uu_id.in_(list(data.event_uu_id_list)),
|
||||
*Events.valid_record_args(Events)
|
||||
*Events.valid_record_args(Events),
|
||||
)
|
||||
if not events_to_add_to_occupant.data:
|
||||
return JSONResponse(
|
||||
|
|
|
|||
|
|
@ -38,15 +38,14 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
|||
|
||||
living_space = BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.id == build_living_space_id,
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace)
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
).data
|
||||
service = Services.filter_one(
|
||||
Services.id == service_id,
|
||||
*Services.valid_record_args(Services)
|
||||
Services.id == service_id, *Services.valid_record_args(Services)
|
||||
).data
|
||||
add_events_list = Service2Events.filter_all(
|
||||
Service2Events.service_id == service.id,
|
||||
*Service2Events.valid_record_args(Service2Events)
|
||||
*Service2Events.valid_record_args(Service2Events),
|
||||
).data
|
||||
if not add_events_list:
|
||||
raise Exception(
|
||||
|
|
@ -106,7 +105,9 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
|||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
|
||||
occupant_occupant_type = OccupantTypes.filter_by_one(uu_id=data.occupant_uu_id).data
|
||||
occupant_occupant_type = OccupantTypes.filter_by_one(
|
||||
uu_id=data.occupant_uu_id
|
||||
).data
|
||||
if not occupant_occupant_type:
|
||||
return JSONResponse(
|
||||
content={
|
||||
|
|
@ -142,7 +143,7 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
|||
BuildLivingSpace.build_parts_id == occupants_build_part.id,
|
||||
BuildLivingSpace.occupant_types_id == occupant_occupant_type.id,
|
||||
BuildLivingSpace.person_id == token_dict.person_id,
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace)
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
).data
|
||||
if not living_space:
|
||||
return JSONResponse(
|
||||
|
|
@ -188,8 +189,12 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
|||
def bind_services_employee(cls, service_id: int, employee_id: int):
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
|
||||
employee = Employees.filter_by_one(id=employee_id, **Employees.valid_record_dict).data
|
||||
service = Services.filter_by_one(id=service_id, **Services.valid_record_dict).data
|
||||
employee = Employees.filter_by_one(
|
||||
id=employee_id, **Employees.valid_record_dict
|
||||
).data
|
||||
service = Services.filter_by_one(
|
||||
id=service_id, **Services.valid_record_dict
|
||||
).data
|
||||
service_events = Service2Events.filter_all(
|
||||
Service2Events.service_id == service.id,
|
||||
*Service2Events.valid_record_args(Service2Events),
|
||||
|
|
@ -220,6 +225,9 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
|||
count_row = session_execute.rowcount
|
||||
print(f"{count_row} events are added to employee {employee.uu_id}")
|
||||
Services.save()
|
||||
for service_event in service_events:
|
||||
service_event.is_confirmed = True
|
||||
Service2Events.save()
|
||||
|
||||
@classmethod
|
||||
def bind_services_employee_super_user(
|
||||
|
|
@ -263,7 +271,7 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
|||
|
||||
service_events = Service2Events.filter_all(
|
||||
Service2Events.service_id == service.id,
|
||||
*Service2Events.valid_record_args(Service2Events)
|
||||
*Service2Events.valid_record_args(Service2Events),
|
||||
).data
|
||||
if not service_events:
|
||||
raise HTTPException(
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class AddEventFunctionality:
|
|||
|
||||
get_event_ids = Events.filter_all(
|
||||
Events.function_code.in_([event["function_code"] for event in events]),
|
||||
system=True
|
||||
system=True,
|
||||
).data
|
||||
if get_event_ids:
|
||||
return [(get_event.id, str(get_event.uu_id)) for get_event in get_event_ids]
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class ApplicationToken(BaseModel):
|
|||
timezone: Optional[str] = "Europe/Istanbul"
|
||||
|
||||
user_type: int = UserType.occupant.value
|
||||
credentials: Credentials
|
||||
credentials: dict = {}
|
||||
|
||||
user_uu_id: str
|
||||
user_id: int
|
||||
|
|
|
|||
|
|
@ -139,7 +139,6 @@ def wag_insert_budget_record(data):
|
|||
similarity_result = parse_comment_with_name(data["iban"], data["process_comment"])
|
||||
build_iban = BuildIbans.find_one(iban=data["iban"])
|
||||
|
||||
|
||||
if payload := InsertBudgetRecord(**data):
|
||||
payload_dict = payload.model_dump(exclude_unset=True, exclude_none=True)
|
||||
decision_books = BuildDecisionBook.select_only(
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ def save_access_token_to_redis(
|
|||
Employees,
|
||||
Staff,
|
||||
)
|
||||
|
||||
if not found_user:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
|
|
@ -82,8 +83,9 @@ def save_access_token_to_redis(
|
|||
)
|
||||
occupants_selection_dict = {}
|
||||
for living_space in living_spaces:
|
||||
build_parts_selection = BuildParts.filter_active(
|
||||
BuildParts.id == living_space.build_parts_id
|
||||
build_parts_selection = BuildParts.filter_all(
|
||||
BuildParts.id == living_space.build_parts_id,
|
||||
*BuildParts.valid_record_args(BuildParts),
|
||||
)
|
||||
if not build_parts_selection.data:
|
||||
raise HTTPException(
|
||||
|
|
@ -129,29 +131,30 @@ def save_access_token_to_redis(
|
|||
available_occupants=new_occupants_selection_dict,
|
||||
)
|
||||
|
||||
list_employee = Employees.filter_active(Employees.people_id == found_user.person_id)
|
||||
list_employee = Employees.filter_all(
|
||||
Employees.people_id == found_user.person_id,
|
||||
*Employees.valid_record_args(Employees),
|
||||
).data
|
||||
companies_uu_id_list, companies_id_list = [], []
|
||||
duty_uu_id_list, duty_id_list = [], []
|
||||
for employee in list_employee.data:
|
||||
for employee in list_employee:
|
||||
staff = Staff.filter_one(
|
||||
Staff.id==employee.staff_id,
|
||||
*Staff.valid_record_args(Staff)
|
||||
Staff.id == employee.staff_id, *Staff.valid_record_args(Staff)
|
||||
).data
|
||||
if duties := Duties.filter_one(
|
||||
Duties.id == staff.duties_id,
|
||||
*Duties.valid_record_args(Duties)
|
||||
Duties.id == staff.duties_id, *Duties.valid_record_args(Duties)
|
||||
).data:
|
||||
if duty_found := Duty.filter_by_one(id=duties.duties_id).data:
|
||||
duty_uu_id_list.append(str(duty_found.uu_id))
|
||||
duty_id_list.append(duty_found.id)
|
||||
|
||||
department = Departments.filter_one(
|
||||
Departments.id==duties.department_id,
|
||||
Departments.id == duties.department_id,
|
||||
*Departments.valid_record_args(Departments),
|
||||
)
|
||||
).data
|
||||
if company := Companies.filter_one(
|
||||
Companies.id==department.company_id,
|
||||
*Companies.valid_record_args(Companies),
|
||||
Companies.id == department.company_id,
|
||||
*Companies.valid_record_args(Companies),
|
||||
).data:
|
||||
companies_uu_id_list.append(str(company.uu_id))
|
||||
companies_id_list.append(company.id)
|
||||
|
|
|
|||
|
|
@ -9,13 +9,14 @@ def parse_token_object_to_dict(request): # from requests import Request
|
|||
|
||||
if valid_token := get_object_via_access_key(request=request):
|
||||
endpoint_name = str(request.url).replace(str(request.base_url), "/")
|
||||
endpoint_active = EndpointRestriction.filter_active(
|
||||
EndpointRestriction.endpoint_name.ilike(f"%{endpoint_name}%")
|
||||
).data[0]
|
||||
endpoint_active = EndpointRestriction.filter_one(
|
||||
EndpointRestriction.endpoint_name.ilike(f"%{endpoint_name}%"),
|
||||
*EndpointRestriction.valid_record_args(EndpointRestriction),
|
||||
).data
|
||||
if not endpoint_active:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="This endpoint is not active for this user, please contact your responsible company for further information.",
|
||||
detail=f"This endpoint {endpoint_name} is not active for this user, please contact your responsible company for further information.",
|
||||
)
|
||||
|
||||
if valid_token.user_type == 1:
|
||||
|
|
@ -24,9 +25,10 @@ def parse_token_object_to_dict(request): # from requests import Request
|
|||
status_code=status.HTTP_418_IM_A_TEAPOT,
|
||||
detail="Selected company is not found in the token object.",
|
||||
)
|
||||
selected_event = Events.filter_active(
|
||||
selected_event = Events.filter_all(
|
||||
Events.endpoint_id == endpoint_active.id,
|
||||
Events.id.in_(valid_token.selected_company.reachable_event_list_id),
|
||||
*Events.valid_record_args(Events)
|
||||
)
|
||||
if not selected_event.data:
|
||||
raise HTTPException(
|
||||
|
|
@ -55,14 +57,15 @@ def parse_token_object_to_dict(request): # from requests import Request
|
|||
status_code=status.HTTP_418_IM_A_TEAPOT,
|
||||
detail="Selected occupant is not found in the token object.",
|
||||
)
|
||||
selected_event = Events.filter_active(
|
||||
selected_event = Events.filter_all(
|
||||
Events.endpoint_id == endpoint_active.id,
|
||||
Events.id.in_(valid_token.selected_occupant.reachable_event_list_id),
|
||||
Events.valid_record_args(Events),
|
||||
)
|
||||
if not selected_event.data:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="This endpoint requires event validation. Please contact your responsible company to use this event.",
|
||||
detail=f"This endpoint {endpoint_name} requires event validation. Please contact your responsible company to use this event.",
|
||||
)
|
||||
selected_event = selected_event.data[0]
|
||||
event_function_class = getattr(selected_event, "function_class", None)
|
||||
|
|
@ -76,7 +79,7 @@ def parse_token_object_to_dict(request): # from requests import Request
|
|||
if not active_function:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="This endpoint requires event validation. Please contact your responsible company to use this event.",
|
||||
detail=f"This endpoint {endpoint_name} requires event validation. Please contact your responsible company to use this event.",
|
||||
)
|
||||
valid_token.available_event = active_function
|
||||
return valid_token
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class InsertCompany(PydanticBaseModel):
|
|||
company_tag: Optional[str] = None
|
||||
default_lang_type: Optional[str] = None
|
||||
default_money_type: Optional[str] = None
|
||||
official_address_uu_id: Optional[int] = None
|
||||
official_address_uu_id: Optional[str] = None
|
||||
# parent_uu_id: Optional[int] = None
|
||||
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ class UpdateCompany(PydanticBaseModel):
|
|||
company_tag: Optional[str] = None
|
||||
default_lang_type: Optional[str] = None
|
||||
default_money_type: Optional[str] = None
|
||||
official_address_uu_id: Optional[int] = None
|
||||
official_address_uu_id: Optional[str] = None
|
||||
|
||||
|
||||
class MatchCompany2Company(PydanticBaseModel):
|
||||
|
|
|
|||
|
|
@ -44,12 +44,13 @@ class AuthModule(PasswordModule):
|
|||
|
||||
@classmethod
|
||||
def check_user_exits(cls, access_key, domain):
|
||||
found_user = cls.filter_one(
|
||||
from databases import Users
|
||||
found_user = Users.query.filter(
|
||||
or_(
|
||||
cls.email == str(access_key).lower(),
|
||||
cls.phone_number == str(access_key).replace(" ", ""),
|
||||
Users.email == str(access_key).lower(),
|
||||
Users.phone_number == str(access_key).replace(" ", ""),
|
||||
),
|
||||
).data
|
||||
).first()
|
||||
if not found_user:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
|
|
@ -73,6 +74,7 @@ class AuthModule(PasswordModule):
|
|||
from databases import (
|
||||
UsersTokens,
|
||||
)
|
||||
|
||||
if disconnect:
|
||||
registered_tokens = UsersTokens.filter_all(
|
||||
UsersTokens.user_id == self.id, system=True
|
||||
|
|
@ -88,19 +90,12 @@ class AuthModule(PasswordModule):
|
|||
|
||||
def check_password(self, password):
|
||||
main_domain = self.get_main_domain_and_other_domains(get_main_domain=True)
|
||||
print('check_password', dict(
|
||||
domain=main_domain,
|
||||
id_=str(self.uu_id),
|
||||
password_hashed=self.hash_password,
|
||||
password=password,
|
||||
))
|
||||
if check_password := self.check_hashed_password(
|
||||
domain=main_domain,
|
||||
id_=str(self.uu_id),
|
||||
password_hashed=self.hash_password,
|
||||
password=password,
|
||||
):
|
||||
print('check_password', check_password)
|
||||
return check_password
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
|
|
@ -120,6 +115,7 @@ class AuthModule(PasswordModule):
|
|||
@staticmethod
|
||||
def create_password(found_user, password, password_token=None):
|
||||
from databases import MongoQueryIdentity
|
||||
|
||||
if found_user.password_token:
|
||||
replace_day = 0
|
||||
try:
|
||||
|
|
@ -141,9 +137,9 @@ class AuthModule(PasswordModule):
|
|||
)
|
||||
query_engine = MongoQueryIdentity(company_uuid=found_user.related_company)
|
||||
|
||||
domain_via_user = query_engine.get_domain_via_user(user_uu_id=str(found_user.uu_id))[
|
||||
"main_domain"
|
||||
]
|
||||
domain_via_user = query_engine.get_domain_via_user(
|
||||
user_uu_id=str(found_user.uu_id)
|
||||
)["main_domain"]
|
||||
new_password_dict = {
|
||||
"password": found_user.create_hashed_password(
|
||||
domain=domain_via_user, id_=str(found_user.uu_id), password=password
|
||||
|
|
@ -167,18 +163,21 @@ class AuthModule(PasswordModule):
|
|||
@staticmethod
|
||||
def reset_password_token(found_user):
|
||||
found_user.password_expiry_begins = str(system_arrow.now())
|
||||
found_user.password_token = found_user.generate_token(127)
|
||||
found_user.password_token = found_user.generate_token(
|
||||
Auth.REFRESHER_TOKEN_LENGTH
|
||||
)
|
||||
found_user.save()
|
||||
|
||||
def generate_refresher_token(self, domain: str, remember_me=False):
|
||||
from databases import (
|
||||
UsersTokens,
|
||||
)
|
||||
|
||||
if remember_me:
|
||||
refresh_token = self.generate_token(Auth.REFRESHER_TOKEN_LENGTH)
|
||||
if already_token := UsersTokens.find_one(
|
||||
user_id=self.id, token_type="RememberMe", domain=domain
|
||||
):
|
||||
if already_token := UsersTokens.filter_by_one(
|
||||
system=True, user_id=self.id, token_type="RememberMe", domain=domain
|
||||
).data:
|
||||
already_token.update(token=refresh_token)
|
||||
already_token.expires_at = system_arrow.shift(days=3)
|
||||
already_token.save()
|
||||
|
|
@ -194,16 +193,13 @@ class AuthModule(PasswordModule):
|
|||
return None
|
||||
|
||||
def remainder_day(self):
|
||||
join_list = [
|
||||
_ for _ in str(self.password_expires_day).split(",")[0] if _.isdigit()
|
||||
]
|
||||
return float(
|
||||
timedelta(
|
||||
days=int(
|
||||
"".join(
|
||||
[
|
||||
_
|
||||
for _ in str(self.password_expires_day).split(",")[0]
|
||||
if _.isdigit()
|
||||
]
|
||||
)
|
||||
"".join(join_list)
|
||||
)
|
||||
).seconds
|
||||
)
|
||||
|
|
@ -218,13 +214,13 @@ class UserLoginModule(AuthModule):
|
|||
People,
|
||||
MongoQueryIdentity,
|
||||
)
|
||||
|
||||
found_user = Users.check_user_exits(
|
||||
access_key=data.access_key, domain=data.domain
|
||||
)
|
||||
access_token = found_user.generate_access_token()
|
||||
query_engine = MongoQueryIdentity(company_uuid=found_user.related_company)
|
||||
if found_user.check_password(password=data.password):
|
||||
print('before access_object_to_redis')
|
||||
access_object_to_redis = save_access_token_to_redis(
|
||||
request=request,
|
||||
found_user=found_user,
|
||||
|
|
@ -270,7 +266,9 @@ class UserLoginModule(AuthModule):
|
|||
no_address_validates = mongo_db.mongo_engine.get_all()[0] == 0
|
||||
record_id = uuid.uuid4().__str__()
|
||||
notice_link = ApiStatic.blacklist_login(record_id=record_id)
|
||||
found_people = People.find_one(id=found_user.person_id)
|
||||
found_people = People.filter_one(
|
||||
People.id == found_user.person_id, *People.valid_record_args(People)
|
||||
).data
|
||||
access_via_user = query_engine.update_access_history_via_user(
|
||||
AccessHistoryViaUser(
|
||||
**{
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ class MongoQueryIdentity:
|
|||
table_name=self.mongo_collection_name, database_name="mongo_database"
|
||||
)
|
||||
|
||||
|
||||
def create_domain_via_user(self, payload: DomainViaUser):
|
||||
self.use_collection("Domain")
|
||||
return self.mongo_engine.insert(
|
||||
|
|
|
|||
|
|
@ -45,9 +45,7 @@ class AccountBooks(CrudCollection):
|
|||
# )
|
||||
|
||||
__table_args__ = (
|
||||
Index(
|
||||
"account_companies_book_ndx_00", company_id, "expiry_starts"
|
||||
),
|
||||
Index("account_companies_book_ndx_00", company_id, "expiry_starts"),
|
||||
{"comment": "Account Book Information"},
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -478,6 +478,7 @@ class BuildParts(CrudCollection):
|
|||
@classmethod
|
||||
def create_action(cls, data: InsertBuildParts, token):
|
||||
from databases import ApiEnumDropdown
|
||||
|
||||
data_dict = data.dump()
|
||||
build_from_duty = Build.select_action(
|
||||
employee_id=token.selected_company.employee_id,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ from api_validations.validations_request import (
|
|||
from databases.sql_models.core_mixin import CrudCollection
|
||||
|
||||
|
||||
|
||||
class BuildDecisionBook(CrudCollection):
|
||||
"""
|
||||
Builds class based on declarative_base and BaseMixin via session
|
||||
|
|
@ -99,6 +98,7 @@ class BuildDecisionBook(CrudCollection):
|
|||
from databases import (
|
||||
Build,
|
||||
)
|
||||
|
||||
related_build = Build.find_one(id=cls.build_id)
|
||||
related_date = system_arrow.get(related_build.build_date)
|
||||
date_processed = related_date.replace(
|
||||
|
|
@ -119,7 +119,7 @@ class BuildDecisionBook(CrudCollection):
|
|||
build_id=str(related_build.uu_id),
|
||||
build_name=related_build.build_name,
|
||||
decision_type="RBM",
|
||||
)
|
||||
),
|
||||
)
|
||||
return book
|
||||
return
|
||||
|
|
@ -130,13 +130,14 @@ class BuildDecisionBook(CrudCollection):
|
|||
Build,
|
||||
Companies,
|
||||
)
|
||||
|
||||
related_companies = Companies.select_action(duty_id_list=[int(duty_id)])
|
||||
related_companies_ids = list(
|
||||
related_.id for related_ in related_companies.all()
|
||||
)
|
||||
related_building = Build.filter_all(
|
||||
Build.company_id.in_(related_companies_ids)
|
||||
*Build.valid_record_args(Build),
|
||||
* Build.valid_record_args(Build),
|
||||
)
|
||||
related_building_ids = list(related_.id for related_ in related_building.data)
|
||||
return cls.filter_all(cls.build_id.in_(related_building_ids)).query
|
||||
|
|
@ -147,6 +148,7 @@ class BuildDecisionBook(CrudCollection):
|
|||
Build,
|
||||
Companies,
|
||||
)
|
||||
|
||||
data_dict = data.model_dump()
|
||||
if building := Build.find_one(uu_id=data.build_uu_id):
|
||||
data_dict["build_id"] = building.id
|
||||
|
|
@ -217,6 +219,7 @@ class BuildDecisionBook(CrudCollection):
|
|||
from databases import (
|
||||
BuildIbans,
|
||||
)
|
||||
|
||||
if all(
|
||||
[True if letter in str(bank_date) else False for letter in ["-", " ", ":"]]
|
||||
):
|
||||
|
|
@ -493,7 +496,9 @@ class BuildDecisionBookPerson(CrudCollection):
|
|||
def get_occupant_types(self):
|
||||
if occupants := BuildDecisionBookPersonOccupants.filter_all(
|
||||
BuildDecisionBookPersonOccupants.build_decision_book_person_id == self.id,
|
||||
*BuildDecisionBookPersonOccupants.valid_record_args(BuildDecisionBookPersonOccupants)
|
||||
*BuildDecisionBookPersonOccupants.valid_record_args(
|
||||
BuildDecisionBookPersonOccupants
|
||||
),
|
||||
).data:
|
||||
return occupants
|
||||
return
|
||||
|
|
@ -606,6 +611,7 @@ class BuildDecisionBookItems(CrudCollection):
|
|||
Build,
|
||||
Companies,
|
||||
)
|
||||
|
||||
related_companies = Companies.select_action(duty_id=duty_id)
|
||||
related_companies_ids = list(
|
||||
related_.id for related_ in related_companies.all()
|
||||
|
|
@ -651,6 +657,7 @@ class BuildDecisionBookItems(CrudCollection):
|
|||
People,
|
||||
OccupantTypes,
|
||||
)
|
||||
|
||||
active_invite = (
|
||||
BuildDecisionBookInvitations.check_invites_are_ready_for_meeting(
|
||||
selected_decision_book=decision_book,
|
||||
|
|
@ -1059,18 +1066,18 @@ class BuildDecisionBookProjects(CrudCollection):
|
|||
Build,
|
||||
Companies,
|
||||
)
|
||||
|
||||
related_companies = Companies.select_action(duty_id_list=[duty_id])
|
||||
related_companies_ids = list(
|
||||
related_.id for related_ in related_companies.all()
|
||||
)
|
||||
related_building = Build.filter_all(
|
||||
Build.company_id.in_(related_companies_ids),
|
||||
*Build.valid_record_args(Build)
|
||||
Build.company_id.in_(related_companies_ids), *Build.valid_record_args(Build)
|
||||
)
|
||||
related_building_ids = list(related_.id for related_ in related_building.data)
|
||||
related_decision_books = BuildDecisionBook.filter_all(
|
||||
BuildDecisionBook.build_id.in_(related_building_ids),
|
||||
*BuildDecisionBook.valid_record_args(BuildDecisionBook)
|
||||
*BuildDecisionBook.valid_record_args(BuildDecisionBook),
|
||||
).data
|
||||
related_decision_books_ids = list(
|
||||
related_.id for related_ in related_decision_books
|
||||
|
|
@ -1079,14 +1086,14 @@ class BuildDecisionBookProjects(CrudCollection):
|
|||
BuildDecisionBookItems.build_decision_book_id.in_(
|
||||
related_decision_books_ids
|
||||
),
|
||||
*BuildDecisionBookItems.valid_record_args(BuildDecisionBookItems)
|
||||
*BuildDecisionBookItems.valid_record_args(BuildDecisionBookItems),
|
||||
).data
|
||||
related_decision_books_items_ids = list(
|
||||
related_.id for related_ in related_decision_books_items
|
||||
)
|
||||
return cls.filter_all(
|
||||
cls.build_decision_book_item_id.in_(related_decision_books_items_ids),
|
||||
*cls.valid_record_args(cls)
|
||||
*cls.valid_record_args(cls),
|
||||
).query
|
||||
|
||||
@classmethod
|
||||
|
|
@ -1095,11 +1102,14 @@ class BuildDecisionBookProjects(CrudCollection):
|
|||
People,
|
||||
Companies,
|
||||
)
|
||||
|
||||
data_dict = data.dump()
|
||||
BuildDecisionBookItems.pre_query = BuildDecisionBookItems.select_action(
|
||||
duty_id=token.duty_list["duty_id"]
|
||||
)
|
||||
People.pre_query = People.select_action(duty_id_list=[token.duty_list["duty_id"]])
|
||||
People.pre_query = People.select_action(
|
||||
duty_id_list=[token.duty_list["duty_id"]]
|
||||
)
|
||||
decision_book_project_item = BuildDecisionBookItems.find_one_or_abort(
|
||||
uu_id=data_dict.get("build_decision_book_item_uu_id")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -63,12 +63,19 @@ class RelationshipDutyCompany(CrudCollection):
|
|||
from databases import (
|
||||
Duties,
|
||||
)
|
||||
|
||||
token_duties_id, token_company_id = token.get("duty_id"), token.get(
|
||||
"company_id"
|
||||
)
|
||||
send_duties, list_match_company_id = Duties.find_one(uu_id=data.duty_uu_id), []
|
||||
send_user_duties = Duties.find_one(
|
||||
duties_id=send_duties.id, company_id=token_duties_id
|
||||
list_match_company_id = []
|
||||
send_duties = Duties.filter_one(
|
||||
Duties.uu_id==data.duty_uu_id,
|
||||
*Duties.valid_record_args(Duties),
|
||||
)
|
||||
send_user_duties = Duties.filter_one(
|
||||
Duties.duties_id==send_duties.id,
|
||||
Duties.company_id==token_duties_id,
|
||||
*Duties.valid_record_args(Duties),
|
||||
)
|
||||
if not send_user_duties:
|
||||
raise Exception(
|
||||
|
|
@ -76,11 +83,15 @@ class RelationshipDutyCompany(CrudCollection):
|
|||
)
|
||||
|
||||
for company_uu_id in list(data.match_company_uu_id):
|
||||
company = Companies.find_one(uu_id=company_uu_id)
|
||||
bulk_company = RelationshipDutyCompany.find_one(
|
||||
owner_id=token_company_id,
|
||||
relationship_type="Bulk",
|
||||
member_id=company.id,
|
||||
company = Companies.filter_one(
|
||||
Companies.uu_id==company_uu_id,
|
||||
*Companies.valid_record_args(Companies),
|
||||
)
|
||||
bulk_company = RelationshipDutyCompany.filter_one(
|
||||
RelationshipDutyCompany.owner_id==token_company_id,
|
||||
RelationshipDutyCompany.relationship_type=="Bulk",
|
||||
RelationshipDutyCompany.member_id==company.id,
|
||||
*RelationshipDutyCompany.valid_record_args(RelationshipDutyCompany),
|
||||
)
|
||||
if not bulk_company:
|
||||
raise Exception(
|
||||
|
|
@ -104,12 +115,19 @@ class RelationshipDutyCompany(CrudCollection):
|
|||
from databases import (
|
||||
Duties,
|
||||
)
|
||||
|
||||
token_duties_id, token_company_id = token.get("duty_id"), token.get(
|
||||
"company_id"
|
||||
)
|
||||
send_duties, list_match_company_id = Duties.find_one(uu_id=data.duty_uu_id), []
|
||||
send_user_duties = Duties.find_one(
|
||||
duties_id=send_duties.id, company_id=token_duties_id
|
||||
list_match_company_id = []
|
||||
send_duties = Duties.filter_one(
|
||||
Duties.uu_id==data.duty_uu_id,
|
||||
*Duties.valid_record_args(Duties),
|
||||
)
|
||||
send_user_duties = Duties.filter_one(
|
||||
Duties.duties_id==send_duties.id,
|
||||
Duties.company_id==token_duties_id,
|
||||
*Duties.valid_record_args(Duties),
|
||||
)
|
||||
if not send_user_duties:
|
||||
raise Exception(
|
||||
|
|
@ -117,11 +135,15 @@ class RelationshipDutyCompany(CrudCollection):
|
|||
)
|
||||
|
||||
for company_uu_id in list(data.match_company_uu_id):
|
||||
company = Companies.find_one(uu_id=company_uu_id)
|
||||
bulk_company = RelationshipDutyCompany.find_one(
|
||||
owner_id=token_company_id,
|
||||
relationship_type="Bulk",
|
||||
member_id=company.id,
|
||||
company = Companies.filter_one(
|
||||
Companies.uu_id==company_uu_id,
|
||||
*Companies.valid_record_args(Companies),
|
||||
)
|
||||
bulk_company = RelationshipDutyCompany.filter_one(
|
||||
RelationshipDutyCompany.owner_id==token_company_id,
|
||||
RelationshipDutyCompany.relationship_type=="Bulk",
|
||||
RelationshipDutyCompany.member_id==company.id,
|
||||
*RelationshipDutyCompany.valid_record_args(RelationshipDutyCompany),
|
||||
)
|
||||
if not bulk_company:
|
||||
raise Exception(
|
||||
|
|
@ -194,7 +216,9 @@ class Companies(CrudCollection, SelectAction):
|
|||
parent_id = mapped_column(Integer, nullable=True)
|
||||
workplace_no: Mapped[str] = mapped_column(String, nullable=True)
|
||||
|
||||
official_address_id: Mapped[int] = mapped_column(ForeignKey("addresses.id"), nullable=True)
|
||||
official_address_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("addresses.id"), nullable=True
|
||||
)
|
||||
official_address_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=True, comment="Official Address UUID"
|
||||
)
|
||||
|
|
@ -222,57 +246,45 @@ class Companies(CrudCollection, SelectAction):
|
|||
from databases import Addresses, Duties
|
||||
|
||||
data_dict = data.model_dump()
|
||||
if cls.filter_one(cls.tax_no == str(data.tax_no).strip()):
|
||||
raise Exception(
|
||||
"Company already exists. Please ask supervisor to make company visible for your duty."
|
||||
if cls.filter_one(cls.tax_no == str(data.tax_no).strip(), system=True).data:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Company already exists. Please ask supervisor to make company visible for your duty."
|
||||
)
|
||||
|
||||
official_address = Addresses.filter_one(
|
||||
Addresses.uu_id == data.official_address_uu_id
|
||||
)
|
||||
if not official_address:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Official address is not found. Please check address uuid and try again.",
|
||||
)
|
||||
Addresses.uu_id == data.official_address_uu_id,
|
||||
*Addresses.valid_record_args(Addresses),
|
||||
).data
|
||||
# if not official_address:
|
||||
# raise HTTPException(
|
||||
# status_code=400,
|
||||
# detail="Official address is not found. Please check address uuid and try again.",
|
||||
# )
|
||||
|
||||
bulk_duties = Duties.get_bulk_duties_of_a_company(
|
||||
company_id=token.selected_company.company_id
|
||||
)
|
||||
|
||||
if official_address:
|
||||
data_dict["official_address_id"] = official_address.id
|
||||
data_dict["official_address_uu_id"] = str(official_address.uu_id)
|
||||
|
||||
data_dict["parent_id"] = token.selected_company.company_id
|
||||
data_dict["official_address_id"] = official_address.id
|
||||
data_dict["official_address_uu_id"] = str(official_address.uu_id)
|
||||
data_dict["top_responsible_company_id"] = token.selected_company.company_id
|
||||
data_dict["top_responsible_company_uu_id"] = (
|
||||
token.selected_company.company_uu_id
|
||||
)
|
||||
|
||||
company_created = cls.find_or_create(**data_dict)
|
||||
if not company_created.is_found:
|
||||
RelationshipDutyCompany.find_or_create(
|
||||
owner_id=token.selected_company.company_id,
|
||||
duties_id=bulk_duties.id,
|
||||
member_id=company_created.id,
|
||||
parent_id=company_created.parent_id,
|
||||
relationship_type="Bulk",
|
||||
show_only=False,
|
||||
)
|
||||
if (
|
||||
not str(token.get("priority_code")) == "78"
|
||||
): # Company based configuration will be applied
|
||||
user_duties = Duties.find_one(
|
||||
duties_id=token.selected_company.duty_id,
|
||||
company_id=token.selected_company.company_id,
|
||||
)
|
||||
RelationshipDutyCompany.find_or_create(
|
||||
owner_id=token.selected_company.company_id,
|
||||
duties_id=user_duties.id,
|
||||
member_id=company_created.id,
|
||||
parent_id=company_created.parent_id,
|
||||
relationship_type="Commercial",
|
||||
show_only=False,
|
||||
)
|
||||
RelationshipDutyCompany.find_or_create(
|
||||
owner_id=token.selected_company.company_id,
|
||||
duties_id=bulk_duties.id,
|
||||
member_id=company_created.id,
|
||||
parent_id=company_created.parent_id,
|
||||
child_count=0,
|
||||
relationship_type="Bulk",
|
||||
show_only=False,
|
||||
)
|
||||
return company_created
|
||||
|
||||
@classmethod
|
||||
|
|
@ -280,11 +292,15 @@ class Companies(CrudCollection, SelectAction):
|
|||
from databases import (
|
||||
Addresses,
|
||||
)
|
||||
|
||||
data_dict = data.excluded_dump()
|
||||
duty_id = token.get("duty_id")
|
||||
company_id = token.get("company_id")
|
||||
if data.official_address_uu_id:
|
||||
official_address = Addresses.find_one(uu_id=data.official_address_uu_id)
|
||||
official_address = Addresses.filter_one(
|
||||
Addresses.uu_id==data.official_address_uu_id,
|
||||
*Addresses.valid_record_args(Addresses),
|
||||
).data
|
||||
data_dict["official_address_id"] = official_address.id
|
||||
del data_dict["official_address_uu_id"], data_dict["company_uu_id"]
|
||||
company_to_update = cls.select_action(
|
||||
|
|
@ -558,4 +574,3 @@ class Companies(CrudCollection, SelectAction):
|
|||
# "default_money_type": self.default_money_type,
|
||||
# "official_address_id": self.official_address_id,
|
||||
# }
|
||||
|
||||
|
|
|
|||
|
|
@ -178,12 +178,12 @@ class Duties(CrudCollection):
|
|||
list_of_created.append(duties_created_at)
|
||||
return list_of_created
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_bulk_duties_of_a_company(cls, company_id):
|
||||
if bulk_duties := Duties.find_one(
|
||||
duties_id=Duty.find_one(duty_code="BULK").id, company_id=company_id
|
||||
):
|
||||
duties_id = Duty.filter_by_one(system=True, duty_code="BULK").data
|
||||
if bulk_duties := Duties.filter_by_one(
|
||||
duties_id=getattr(duties_id,'id', None), company_id=company_id, **Duties.valid_record_dict
|
||||
).data:
|
||||
return bulk_duties
|
||||
raise Exception("Bulk Duty not found. Please contact with supervisor.")
|
||||
|
||||
|
|
|
|||
|
|
@ -90,9 +90,7 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
|||
)
|
||||
|
||||
@classmethod
|
||||
def set_user_define_properties(
|
||||
cls, token
|
||||
):
|
||||
def set_user_define_properties(cls, token):
|
||||
cls.creds = token.credentials
|
||||
cls.client_arrow = DateTimeLocal(is_client=True, timezone=token.timezone)
|
||||
|
||||
|
|
@ -126,39 +124,39 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
|||
is_primary, value_type = key in cls.primary_keys, type(val)
|
||||
row_attr = bool(getattr(getattr(cls, key), "foreign_keys", None))
|
||||
if is_primary or row_attr and key_ == Mapped[int]:
|
||||
return None
|
||||
return False, None
|
||||
|
||||
if key_:
|
||||
if key_ == Mapped[int]:
|
||||
return int(val) if val else None
|
||||
return True, int(val) if val is not None else None
|
||||
elif key_ == Mapped[bool]:
|
||||
return bool(val) if val else None
|
||||
return True, bool(val) if val is not None else None
|
||||
elif key_ == Mapped[float] or key_ == Mapped[NUMERIC]:
|
||||
return round(float(val), 3) if val else None
|
||||
return True, round(float(val), 3) if val is not None else None
|
||||
elif key_ == Mapped[int]:
|
||||
return int(val) if val else None
|
||||
return True, int(val) if val is not None else None
|
||||
elif key_ == Mapped[TIMESTAMP]:
|
||||
formatted_date = client_arrow.get(str(val)).format(
|
||||
"DD-MM-YYYY HH:mm:ss"
|
||||
)
|
||||
return str(formatted_date) if val else None
|
||||
return True, str(formatted_date) if val is not None else None
|
||||
else:
|
||||
if isinstance(val, datetime.datetime):
|
||||
formatted_date = client_arrow.get(str(val)).format(
|
||||
"DD-MM-YYYY HH:mm:ss"
|
||||
)
|
||||
return str(formatted_date) if val else None
|
||||
return True, str(formatted_date) if val is not None else None
|
||||
elif isinstance(value_type, bool):
|
||||
return bool(val) if val else None
|
||||
return True, bool(val) if val is not None else None
|
||||
elif isinstance(value_type, float) or isinstance(value_type, Decimal):
|
||||
return round(float(val), 3) if val else None
|
||||
return True, round(float(val), 3) if val is not None else None
|
||||
elif isinstance(value_type, int):
|
||||
return int(val) if val else None
|
||||
return True, int(val) if val is not None else None
|
||||
elif isinstance(value_type, str):
|
||||
return str(val) if val else None
|
||||
return True, str(val) if val is not None else None
|
||||
elif isinstance(value_type, type(None)):
|
||||
return None
|
||||
|
||||
return str(val) if val else None
|
||||
return True, None
|
||||
return False, None
|
||||
|
||||
@classmethod
|
||||
def find_or_create(cls, **kwargs):
|
||||
|
|
@ -198,9 +196,11 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
|||
created_record = cls()
|
||||
for key, value in check_kwargs.items():
|
||||
setattr(created_record, key, value)
|
||||
if getattr(cls.creds, 'person_id', None) and getattr(cls.creds, 'person_name', None):
|
||||
cls.created_by_id = cls.creds.person_id
|
||||
cls.created_by = cls.creds.person_name
|
||||
if getattr(cls.creds, "person_id", None) and getattr(
|
||||
cls.creds, "person_name", None
|
||||
):
|
||||
cls.created_by_id = cls.creds.get('person_id', "Unknown")
|
||||
cls.created_by = cls.creds.get('person_name', "Unknown")
|
||||
created_record.flush()
|
||||
return created_record
|
||||
|
||||
|
|
@ -220,13 +220,17 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
|||
setattr(self, key, value)
|
||||
|
||||
if is_confirmed_argument:
|
||||
if getattr(self.creds, 'person_id', None) and getattr(self.creds, 'person_name', None):
|
||||
self.confirmed_by_id = self.creds.person_id
|
||||
self.confirmed_by = self.creds.person_name
|
||||
if getattr(self.creds, "person_id", None) and getattr(
|
||||
self.creds, "person_name", None
|
||||
):
|
||||
self.confirmed_by_id = self.creds.get('person_id', "Unknown")
|
||||
self.confirmed_by = self.creds.get('person_name', "Unknown")
|
||||
else:
|
||||
if getattr(self.creds, 'person_id', None) and getattr(self.creds, 'person_name', None):
|
||||
self.updated_by_id = self.creds.person_id
|
||||
self.updated_by = self.creds.person_name
|
||||
if getattr(self.creds, "person_id", None) and getattr(
|
||||
self.creds, "person_name", None
|
||||
):
|
||||
self.updated_by_id = self.creds.get('person_id', "Unknown")
|
||||
self.updated_by = self.creds.get('person_id', "Unknown")
|
||||
self.flush()
|
||||
return self
|
||||
|
||||
|
|
@ -244,8 +248,8 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
|||
columns_include_list.extend(["uu_id", "active"])
|
||||
for key in list(columns_include_list):
|
||||
val = getattr(self, key)
|
||||
value_of_database = self.iterate_over_variables(val, key)
|
||||
if value_of_database is not None:
|
||||
correct, value_of_database = self.iterate_over_variables(val, key)
|
||||
if correct:
|
||||
return_dict[key] = value_of_database
|
||||
elif exclude:
|
||||
exclude.extend(
|
||||
|
|
@ -261,18 +265,19 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
|||
columns_excluded_list = set(self.columns).difference(set(exclude))
|
||||
for key in list(columns_excluded_list):
|
||||
val = getattr(self, key)
|
||||
value_of_database = self.iterate_over_variables(val, key)
|
||||
if value_of_database is not None:
|
||||
correct, value_of_database = self.iterate_over_variables(val, key)
|
||||
if correct:
|
||||
return_dict[key] = value_of_database
|
||||
else:
|
||||
exclude_list = (
|
||||
self.__exclude__fields__ or [] + self.__system_default_model__
|
||||
)
|
||||
columns_list = list(set(self.columns).difference(set(exclude_list)))
|
||||
columns_list = [columns for columns in columns_list if str(columns)[-2:] != "id" and 'uu_id' not in str(columns)]
|
||||
for key in list(columns_list):
|
||||
val = getattr(self, key)
|
||||
value_of_database = self.iterate_over_variables(val, key)
|
||||
if value_of_database is not None:
|
||||
correct, value_of_database = self.iterate_over_variables(val, key)
|
||||
if correct:
|
||||
return_dict[key] = value_of_database
|
||||
|
||||
# all_arguments = [
|
||||
|
|
|
|||
|
|
@ -69,8 +69,7 @@ class Modules(CrudCollection):
|
|||
|
||||
def retrieve_services(self):
|
||||
services = Services.filter_all(
|
||||
Services.module_id == self.id,
|
||||
*Services.valid_record_args(Services)
|
||||
Services.module_id == self.id, *Services.valid_record_args(Services)
|
||||
).data
|
||||
if not services:
|
||||
self.raise_http_exception(
|
||||
|
|
@ -151,8 +150,7 @@ class Event2Employee(CrudCollection):
|
|||
)
|
||||
active_events_id = [event.event_id for event in active_events.data]
|
||||
active_events = Events.filter_all(
|
||||
Events.id.in_(active_events_id),
|
||||
*Events.valid_record_args(Events)
|
||||
Events.id.in_(active_events_id), *Events.valid_record_args(Events)
|
||||
)
|
||||
active_events_uu_id = [str(event.uu_id) for event in active_events.data]
|
||||
return active_events_id, active_events_uu_id
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class UsersTokens(CrudCollection):
|
|||
token: Mapped[str] = mapped_column(String, server_default="")
|
||||
domain: Mapped[str] = mapped_column(String, server_default="")
|
||||
expires_at = mapped_column(
|
||||
TIMESTAMP, default=str(system_arrow.shift(date=system_arrow.now(),days=3))
|
||||
TIMESTAMP, default=str(system_arrow.shift(date=system_arrow.now(), days=3))
|
||||
)
|
||||
|
||||
# users = relationship("Users", back_populates="tokens", foreign_keys=[user_id])
|
||||
|
|
@ -162,65 +162,21 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
|
|||
return created_user
|
||||
|
||||
@classmethod
|
||||
def created_creds(cls, create_creds: bool = True):
|
||||
person_object = People.find_one(id=cls.person_id)
|
||||
if create_creds:
|
||||
return {
|
||||
"created_by_id": person_object.id,
|
||||
"created_by": str(person_object.firstname)
|
||||
+ " "
|
||||
+ str(person_object.surname),
|
||||
}
|
||||
def credentials(cls):
|
||||
person_object = People.filter_by_one(system=True, id=cls.person_id).data
|
||||
if not person_object:
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail="Person not found. Please contact the admin.",
|
||||
)
|
||||
return {
|
||||
"updated_by_id": person_object.id,
|
||||
"updated_by": str(person_object.firstname)
|
||||
+ " "
|
||||
+ str(person_object.surname),
|
||||
"person_id": person_object.id,
|
||||
"person_uu_id": str(person_object.uu_id),
|
||||
}
|
||||
|
||||
#
|
||||
# def prepare_employee_token_object(self, selected_duty_uu_id):
|
||||
# from database_sql_models import (
|
||||
# Companies,
|
||||
# Employees,
|
||||
# Duties,
|
||||
# Departments,
|
||||
# )
|
||||
# found_person = People.find_one(id=self.person_id)
|
||||
# found_employee = Employees.find_one(people_id=found_person.id)
|
||||
# found_duty = Duties.find_one(uu_id=selected_duty_uu_id)
|
||||
# found_department = Departments.find_one(id=found_duty.department_id)
|
||||
# found_company = Companies.find_one(id=found_department.company_id)
|
||||
# return {
|
||||
# "people": {
|
||||
# "people_id": found_person.id,
|
||||
# "people_uu_id": found_person.uu_id.__str__(),
|
||||
# },
|
||||
# "user": {
|
||||
# "user_id": self.id,
|
||||
# "user_uu_id": self.uu_id.__str__(),
|
||||
# },
|
||||
# "duty": {
|
||||
# "duty_id": found_duty.id,
|
||||
# "duty_uu_id": found_duty.uu_id.__str__()
|
||||
# },
|
||||
# "employee": {
|
||||
# "employee_id": found_employee.id,
|
||||
# "employee_uu_id": found_employee.uu_id.__str__(),
|
||||
# "people_id": found_employee.people_id,
|
||||
# },
|
||||
# "department": {
|
||||
# "department_id": found_department.id,
|
||||
# "department_uu_id": found_department.uu_id.__str__(),
|
||||
# },
|
||||
# "company": {
|
||||
# "company_id": found_company.id,
|
||||
# "company_uu_id": found_company.uu_id.__str__()
|
||||
# },
|
||||
# }
|
||||
|
||||
def get_employee_and_duty_details(self):
|
||||
from databases import Employees, Duties
|
||||
|
||||
found_person = People.find_one(id=self.person_id)
|
||||
found_employees = Employees.filter_by_active(
|
||||
people_id=found_person.id, is_confirmed=True
|
||||
|
|
@ -383,6 +339,7 @@ class People(CrudCollection, SelectAction):
|
|||
@classmethod
|
||||
def create_action(cls, data: InsertPerson, token):
|
||||
from databases import Employees, Duties
|
||||
|
||||
token_duties_id, token_company_id = (
|
||||
token.selected_company.duty_id,
|
||||
token.selected_company.company_id,
|
||||
|
|
@ -498,7 +455,9 @@ class Addresses(CrudCollection):
|
|||
post_code_list = RelationshipEmployee2PostCode.filter_all(
|
||||
RelationshipEmployee2PostCode.employee_id
|
||||
== token_dict.selected_company.employee_id,
|
||||
*RelationshipEmployee2PostCode.valid_record_args(RelationshipEmployee2PostCode)
|
||||
*RelationshipEmployee2PostCode.valid_record_args(
|
||||
RelationshipEmployee2PostCode
|
||||
),
|
||||
).data
|
||||
post_code_id_list = [post_code.member_id for post_code in post_code_list]
|
||||
if not post_code_id_list:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from sqlalchemy import SQLColumnExpression
|
||||
from sqlalchemy import BinaryExpression
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from api_validations.validations_request import ListOptions
|
||||
|
|
@ -94,10 +94,15 @@ class FilterAttributes:
|
|||
|
||||
@classmethod
|
||||
def add_new_arg_to_args(cls, args_list, argument, value):
|
||||
new_arg_list = list(set(
|
||||
args_ for args_ in list(args_list) if isinstance(args_, SQLColumnExpression)
|
||||
))
|
||||
arg_left = lambda arg_obj: getattr(getattr(arg_obj, "left", None), 'key', None)
|
||||
new_arg_list = list(
|
||||
set(
|
||||
args_
|
||||
for args_ in list(args_list)
|
||||
if isinstance(args_, BinaryExpression)
|
||||
)
|
||||
)
|
||||
arg_left = lambda arg_obj: getattr(getattr(arg_obj, "left", None), "key", None)
|
||||
# arg_right = lambda arg_obj: getattr(getattr(arg_obj, "right", None), "value", None)
|
||||
if not any(True for arg in new_arg_list if arg_left(arg_obj=arg) == argument):
|
||||
new_arg_list.append(value)
|
||||
return tuple(new_arg_list)
|
||||
|
|
@ -108,7 +113,7 @@ class FilterAttributes:
|
|||
from api_library.date_time_actions.date_functions import system_arrow
|
||||
|
||||
arg = cls.add_new_arg_to_args(
|
||||
arg, "expiry_ends", cls.expiry_ends >= str(system_arrow.now())
|
||||
arg, "expiry_ends", cls.expiry_ends > str(system_arrow.now())
|
||||
)
|
||||
arg = cls.add_new_arg_to_args(
|
||||
arg, "expiry_starts", cls.expiry_starts <= str(system_arrow.now())
|
||||
|
|
|
|||
|
|
@ -24,10 +24,7 @@ def exception_handler_http(request: Request, exc: HTTPException):
|
|||
err = e
|
||||
return JSONResponse(
|
||||
status_code=exc.status_code,
|
||||
content={
|
||||
"detail":str(exc_detail),
|
||||
"mesasage": f"{e}"
|
||||
},
|
||||
content={"detail": str(exc_detail), "mesasage": f"{e}"},
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,9 @@ from .address.address.router import address_router
|
|||
from .address.post_code.router import post_code_router
|
||||
from .application.enums_and_drops.router import enums_route
|
||||
from .application.occupants.router import occupant_types_route
|
||||
from .decision_book.decision_book_invitations.router import build_decision_book_invitations
|
||||
from .decision_book.decision_book_invitations.router import (
|
||||
build_decision_book_invitations,
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
|
||||
|
||||
class Config:
|
||||
IP_ADDRESS: str = "http://10.10.2.46:41575/internal/isbank/retreive"
|
||||
SERVICE_TIMING: int = 900 # 15 min
|
||||
SERVICE_TIMING: int = 900 # 15 min
|
||||
|
||||
UNREAD_PATH: str = '/home/bank/isbank/unread/'
|
||||
PARSED_PATH: str = '/home/bank/isbank/parsed/parsed_data.json'
|
||||
ARCHIVE_PATH: str = '/home/bank/isbank/archive/'
|
||||
INCOMING_PATH: str = '/home/bank/isbank/unread'
|
||||
COMPLETED_PATH: str = '/home/bank/isbank/completed'
|
||||
UNREAD_PATH: str = "/home/bank/isbank/unread/"
|
||||
PARSED_PATH: str = "/home/bank/isbank/parsed/parsed_data.json"
|
||||
ARCHIVE_PATH: str = "/home/bank/isbank/archive/"
|
||||
INCOMING_PATH: str = "/home/bank/isbank/unread"
|
||||
COMPLETED_PATH: str = "/home/bank/isbank/completed"
|
||||
|
||||
MAILBOX: str = 'bilgilendirme@ileti.isbank.com.tr'
|
||||
KARATAY: str = 'karatay.berkay@gmail.com'
|
||||
MAILBOX: str = "bilgilendirme@ileti.isbank.com.tr"
|
||||
KARATAY: str = "karatay.berkay@gmail.com"
|
||||
|
||||
EMAIL_HOST: str = '10.10.2.34'
|
||||
EMAIL_USERNAME: str = 'karatay@mehmetkaratay.com.tr'
|
||||
EMAIL_PASSWORD: str = ''
|
||||
EMAIL_HOST: str = "10.10.2.34"
|
||||
EMAIL_USERNAME: str = "karatay@mehmetkaratay.com.tr"
|
||||
EMAIL_PASSWORD: str = ""
|
||||
|
||||
INFO_MAIL = 'mehmet.karatay@hotmail.com'
|
||||
INFO_MAIL = "mehmet.karatay@hotmail.com"
|
||||
|
|
|
|||
|
|
@ -6,9 +6,10 @@ email_sender = EmailSender(
|
|||
host=Config.EMAIL_HOST,
|
||||
port=993,
|
||||
username=Config.EMAIL_USERNAME,
|
||||
password=Config.EMAIL_PASSWORD
|
||||
password=Config.EMAIL_PASSWORD,
|
||||
)
|
||||
|
||||
|
||||
def mail_sender_service(subject, list_of_read_attachment_names):
|
||||
email_sender.connect()
|
||||
try:
|
||||
|
|
@ -20,5 +21,5 @@ def mail_sender_service(subject, list_of_read_attachment_names):
|
|||
return True
|
||||
except Exception as e:
|
||||
err = e
|
||||
print('Mail send error raised : ', err)
|
||||
return False
|
||||
print("Mail send error raised : ", err)
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@ basicConfig(filename=__name__, level=INFO)
|
|||
|
||||
def read_json_file(json_file_path):
|
||||
if os.path.exists(json_file_path):
|
||||
with open(json_file_path, 'r') as json_file:
|
||||
with open(json_file_path, "r") as json_file:
|
||||
return json.load(json_file)
|
||||
return {}
|
||||
|
||||
|
||||
def write_json_file(json_file_path, data):
|
||||
with open(json_file_path, 'w') as json_file:
|
||||
with open(json_file_path, "w") as json_file:
|
||||
json.dump(data, json_file, indent=4)
|
||||
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ def parser_service():
|
|||
|
||||
excel_files = glob.glob(os.path.join(absolute_path, "*.xls*"))
|
||||
for file_path in excel_files:
|
||||
xl_name = str(file_path).split('/')[-1]
|
||||
xl_name = str(file_path).split("/")[-1]
|
||||
xl_file = pandas.read_excel(file_path)
|
||||
xl_frame = pandas.DataFrame(xl_file)
|
||||
iban = ""
|
||||
|
|
@ -68,13 +68,17 @@ def parser_service():
|
|||
)
|
||||
logger.info(f"Insert Dict: {insert_dict}")
|
||||
existing_data = read_json_file(parsed)
|
||||
if xl_name in existing_data: # Check if the key already exists
|
||||
if xl_name in existing_data: # Check if the key already exists
|
||||
if insert_dict not in existing_data[xl_name]:
|
||||
existing_data[xl_name].append(insert_dict)
|
||||
else:
|
||||
existing_data[xl_name] = [insert_dict] # Update the JSON data with the new key-value pair
|
||||
write_json_file(parsed, existing_data) # Write the updated data back to the JSON file
|
||||
|
||||
existing_data[xl_name] = [
|
||||
insert_dict
|
||||
] # Update the JSON data with the new key-value pair
|
||||
write_json_file(
|
||||
parsed, existing_data
|
||||
) # Write the updated data back to the JSON file
|
||||
|
||||
shutil.move(
|
||||
file_path,
|
||||
os.path.join(current_directory, completed, os.path.basename(file_path)),
|
||||
|
|
@ -83,8 +87,7 @@ def parser_service():
|
|||
|
||||
# if __name__ == "__main__":
|
||||
# parse_xl_files_and_copy_to_database()
|
||||
# time.sleep(int(os.getenv("PARSER_SEQUENCE", 60)))
|
||||
# while True:
|
||||
# parse_xl_files_and_copy_to_database()
|
||||
# time.sleep(int(os.getenv("PARSER_SEQUENCE", 60)))
|
||||
|
||||
# time.sleep(int(os.getenv("PARSER_SEQUENCE", 60)))
|
||||
# while True:
|
||||
# parse_xl_files_and_copy_to_database()
|
||||
# time.sleep(int(os.getenv("PARSER_SEQUENCE", 60)))
|
||||
|
|
|
|||
|
|
@ -6,19 +6,14 @@ from redbox import EmailBox
|
|||
from redbox.query import FROM, UNSEEN, OR
|
||||
|
||||
|
||||
host='10.10.2.34'
|
||||
port=993
|
||||
username='isbank@mehmetkaratay.com.tr'
|
||||
password='system'
|
||||
host = "10.10.2.34"
|
||||
port = 993
|
||||
username = "isbank@mehmetkaratay.com.tr"
|
||||
password = "system"
|
||||
authorized_iban = "4245-0093333"
|
||||
authorized_iban_cleaned = authorized_iban.replace("-", "")
|
||||
|
||||
box = EmailBox(
|
||||
host=host,
|
||||
port=port,
|
||||
username=username,
|
||||
password=password
|
||||
)
|
||||
box = EmailBox(host=host, port=port, username=username, password=password)
|
||||
|
||||
filter_mail = OR(FROM(Config.MAILBOX), FROM(Config.KARATAY))
|
||||
filter_print = f"{Config.MAILBOX} & {Config.KARATAY}"
|
||||
|
|
@ -29,29 +24,45 @@ filter_print = f"{Config.MAILBOX} & {Config.KARATAY}"
|
|||
def reader_service():
|
||||
mailbox = box.inbox
|
||||
banks_mails = mailbox.search(filter_mail & UNSEEN)
|
||||
print(f'Service is reading mailbox [{username}] with mail sender [{filter_print}] with count : {len(banks_mails)}')
|
||||
print(
|
||||
f"Service is reading mailbox [{username}] with mail sender [{filter_print}] with count : {len(banks_mails)}"
|
||||
)
|
||||
for banks_mail in banks_mails:
|
||||
message_attc = lambda fn: f"FROM: {banks_mail.from_}, SEEN: {banks_mail.seen} MSG: email_message.is_multipart Downloaded attachment: {fn}"
|
||||
message_non_attc = lambda fn: f"FROM: {banks_mail.from_}, SEEN: {banks_mail.seen} MSG: Handle non-multipart email Downloaded attachment: {fn}"
|
||||
message_attc = (
|
||||
lambda fn: f"FROM: {banks_mail.from_}, SEEN: {banks_mail.seen} MSG: email_message.is_multipart Downloaded attachment: {fn}"
|
||||
)
|
||||
message_non_attc = (
|
||||
lambda fn: f"FROM: {banks_mail.from_}, SEEN: {banks_mail.seen} MSG: Handle non-multipart email Downloaded attachment: {fn}"
|
||||
)
|
||||
# mail_subject = banks_mail.subject
|
||||
email_message = banks_mail.email
|
||||
full_path = lambda fn: str(Config.UNREAD_PATH) + str(fn)
|
||||
completed_path = lambda fn: str(Config.COMPLETED_PATH) + '/' + str(fn)
|
||||
file_exists = lambda fn: not os.path.exists(full_path(fn)) and not os.path.exists(completed_path(fn))
|
||||
if email_message.is_multipart(): # Check if email has multipart content
|
||||
completed_path = lambda fn: str(Config.COMPLETED_PATH) + "/" + str(fn)
|
||||
file_exists = lambda fn: not os.path.exists(
|
||||
full_path(fn)
|
||||
) and not os.path.exists(completed_path(fn))
|
||||
if email_message.is_multipart(): # Check if email has multipart content
|
||||
for part in email_message.walk():
|
||||
content_disposition = part.get('Content-Disposition') # Each part can be an attachment
|
||||
if content_disposition and 'attachment' in content_disposition:
|
||||
content_disposition = part.get(
|
||||
"Content-Disposition"
|
||||
) # Each part can be an attachment
|
||||
if content_disposition and "attachment" in content_disposition:
|
||||
if filename := part.get_filename():
|
||||
if authorized_iban_cleaned in str(filename) and file_exists(filename):
|
||||
with open(full_path(filename), 'wb') as f:
|
||||
if authorized_iban_cleaned in str(filename) and file_exists(
|
||||
filename
|
||||
):
|
||||
with open(full_path(filename), "wb") as f:
|
||||
print(message_attc(filename))
|
||||
f.write(part.get_payload(decode=True)) # Save attachment
|
||||
f.write(
|
||||
part.get_payload(decode=True)
|
||||
) # Save attachment
|
||||
else: # Handle non-multipart email, though this is rare for emails with attachments
|
||||
content_disposition = email_message.get('Content-Disposition')
|
||||
if content_disposition and 'attachment' in content_disposition:
|
||||
content_disposition = email_message.get("Content-Disposition")
|
||||
if content_disposition and "attachment" in content_disposition:
|
||||
if filename := email_message.get_filename():
|
||||
if authorized_iban_cleaned in str(filename) and file_exists(filename):
|
||||
with open(full_path(filename), 'wb') as f:
|
||||
if authorized_iban_cleaned in str(filename) and file_exists(
|
||||
filename
|
||||
):
|
||||
with open(full_path(filename), "wb") as f:
|
||||
print(message_non_attc(filename))
|
||||
f.write(email_message.get_payload(decode=True))
|
||||
|
|
|
|||
|
|
@ -28,19 +28,20 @@ class BankReceive(BaseModel):
|
|||
|
||||
def read_json_file(json_file_path):
|
||||
if os.path.exists(json_file_path):
|
||||
with open(json_file_path, 'r') as json_file:
|
||||
with open(json_file_path, "r") as json_file:
|
||||
return json.load(json_file)
|
||||
return {}
|
||||
|
||||
|
||||
def write_json_file(json_file_path, data):
|
||||
with open(json_file_path, 'w') as json_file:
|
||||
with open(json_file_path, "w") as json_file:
|
||||
json.dump(data, json_file, indent=4)
|
||||
|
||||
|
||||
def sender_service():
|
||||
parsed_data = read_json_file(Config.PARSED_PATH)
|
||||
if not parsed_data:
|
||||
print('Parsed data can not found')
|
||||
print("Parsed data can not found")
|
||||
return
|
||||
|
||||
if is_bank_retrieve_account_records(bank_data=json.dumps(parsed_data)):
|
||||
|
|
@ -49,14 +50,15 @@ def sender_service():
|
|||
print("is_bank_retrieve_account_records is failed")
|
||||
return
|
||||
|
||||
today_date = str(arrow.now('GMT+0'))
|
||||
archive_path = str(Config.ARCHIVE_PATH + today_date + '.json').replace(' ', '')
|
||||
today_date = str(arrow.now("GMT+0"))
|
||||
archive_path = str(Config.ARCHIVE_PATH + today_date + ".json").replace(" ", "")
|
||||
already_archived = read_json_file(archive_path)
|
||||
already_archived[today_date] = parsed_data
|
||||
write_json_file(archive_path, already_archived)
|
||||
write_json_file(Config.PARSED_PATH, {})
|
||||
return
|
||||
|
||||
|
||||
def is_bank_retrieve_account_records(bank_data):
|
||||
from databases import AccountRecords
|
||||
|
||||
|
|
@ -88,4 +90,3 @@ def is_bank_retrieve_account_records(bank_data):
|
|||
# err = e
|
||||
# print('Exception',e)
|
||||
# return False, {}, 500
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
import time
|
||||
import datetime
|
||||
from config_isbank import Config
|
||||
from config_isbank import Config
|
||||
from isbank_reader import reader_service
|
||||
from isbank_parser import parser_service
|
||||
from isbank_sender import sender_service
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print('Bank service booted...')
|
||||
print("Bank service booted...")
|
||||
while True:
|
||||
try:
|
||||
reader_service()
|
||||
|
|
@ -17,10 +16,9 @@ if __name__ == "__main__":
|
|||
time.sleep(1)
|
||||
sender_service()
|
||||
time.sleep(1)
|
||||
print(datetime.datetime.now().__str__(), ' : system completed a cycle...')
|
||||
print(datetime.datetime.now().__str__(), " : system completed a cycle...")
|
||||
except Exception as e:
|
||||
err = e
|
||||
print('Raised Error :', err)
|
||||
print("Raised Error :", err)
|
||||
time.sleep(int(Config.SERVICE_TIMING or 900))
|
||||
# time.sleep(10)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +1,27 @@
|
|||
import time
|
||||
import datetime
|
||||
from config_isbank import Config
|
||||
from config_isbank import Config
|
||||
from isbank_reader import reader_service
|
||||
from isbank_parser import parser_service
|
||||
from isbank_sender import sender_service
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print('Bank service booted...')
|
||||
print("Bank service booted...")
|
||||
# while True:
|
||||
# try:
|
||||
# try:
|
||||
reader_service()
|
||||
time.sleep(1)
|
||||
parser_service()
|
||||
time.sleep(1)
|
||||
sender_service()
|
||||
time.sleep(1)
|
||||
print(datetime.datetime.now().__str__(), ' : system completed a cycle without error...')
|
||||
# except Exception as e:
|
||||
# err = e
|
||||
# print('Raised Error :', err)
|
||||
# time.sleep(int(Config.SERVICE_TIMING or 900))
|
||||
# time.sleep(10)
|
||||
|
||||
print(
|
||||
datetime.datetime.now().__str__(),
|
||||
" : system completed a cycle without error...",
|
||||
)
|
||||
# except Exception as e:
|
||||
# err = e
|
||||
# print('Raised Error :', err)
|
||||
# time.sleep(int(Config.SERVICE_TIMING or 900))
|
||||
# time.sleep(10)
|
||||
|
|
|
|||
|
|
@ -19,9 +19,11 @@ active_confirmed = dict(
|
|||
is_notification_send=True,
|
||||
)
|
||||
|
||||
|
||||
def create_all_events_from_actions():
|
||||
import api_events.events as events
|
||||
from databases import EndpointRestriction
|
||||
|
||||
an_empty_list, duplicate_list = [], []
|
||||
|
||||
for event in events.__all__:
|
||||
|
|
@ -37,18 +39,20 @@ def create_all_events_from_actions():
|
|||
f"Endpoint not found in {event_selected.__name__} class"
|
||||
)
|
||||
endpoint_restriction = EndpointRestriction.filter_one(
|
||||
EndpointRestriction.endpoint_name.ilike(f"%{event_selected.action.endpoint}%"),
|
||||
system=True
|
||||
EndpointRestriction.endpoint_name.ilike(
|
||||
f"%{event_selected.action.endpoint}%"
|
||||
),
|
||||
system=True,
|
||||
).data
|
||||
if endpoint_restriction:
|
||||
if event_selected_function:
|
||||
selected_event = Events.filter_one(
|
||||
Events.event_type==event_selected.event_type,
|
||||
Events.function_class==event,
|
||||
Events.function_code==event_selected_key,
|
||||
Events.endpoint_id==endpoint_restriction.id,
|
||||
Events.endpoint_uu_id==str(endpoint_restriction.uu_id),
|
||||
system=True
|
||||
Events.event_type == event_selected.event_type,
|
||||
Events.function_class == event,
|
||||
Events.function_code == event_selected_key,
|
||||
Events.endpoint_id == endpoint_restriction.id,
|
||||
Events.endpoint_uu_id == str(endpoint_restriction.uu_id),
|
||||
system=True,
|
||||
).data
|
||||
if not selected_event:
|
||||
created_event = Events.find_or_create(
|
||||
|
|
@ -57,7 +61,7 @@ def create_all_events_from_actions():
|
|||
function_code=event_selected_key,
|
||||
endpoint_id=endpoint_restriction.id,
|
||||
endpoint_uu_id=str(endpoint_restriction.uu_id),
|
||||
**active_confirmed
|
||||
**active_confirmed,
|
||||
)
|
||||
Events.save()
|
||||
print(f"Event created: {created_event.uu_id}")
|
||||
|
|
@ -80,8 +84,8 @@ def add_events_all_services_and_occupant_types():
|
|||
for event_block in tasks2events.__all__:
|
||||
event_block_class = getattr(tasks2events, event_block)
|
||||
service_selected = Services.filter_one(
|
||||
Services.service_code==getattr(event_block_class, "service_code", None),
|
||||
system=True
|
||||
Services.service_code == getattr(event_block_class, "service_code", None),
|
||||
system=True,
|
||||
).data
|
||||
if not service_selected:
|
||||
raise Exception(f"{event_block_class.service_code} service is not found")
|
||||
|
|
|
|||
|
|
@ -140,7 +140,9 @@ def create_occupant_types_defaults():
|
|||
]
|
||||
|
||||
for list_occupant_type in list_occupant_types:
|
||||
created_type = OccupantTypes.find_or_create(**{"is_confirmed": True, **list_occupant_type})
|
||||
created_type = OccupantTypes.find_or_create(
|
||||
**{"is_confirmed": True, **list_occupant_type}
|
||||
)
|
||||
created_type.save()
|
||||
created_type.is_confirmed = True
|
||||
created_type.save()
|
||||
|
|
@ -401,10 +403,8 @@ def create_application_defaults():
|
|||
is_notification_send=True,
|
||||
)
|
||||
created_list.append(app_manager_user)
|
||||
app_manager_user.reset_password_token()
|
||||
mongo_engine = MongoQueryIdentity(
|
||||
company_uuid=company_management.uu_id
|
||||
)
|
||||
app_manager_user.reset_password_token(found_user=app_manager_user)
|
||||
mongo_engine = MongoQueryIdentity(company_uuid=company_management.uu_id)
|
||||
mongo_engine.create_domain_via_user(
|
||||
payload=DomainViaUser(
|
||||
user_uu_id=str(app_manager_user.uu_id),
|
||||
|
|
@ -430,7 +430,7 @@ def create_application_defaults():
|
|||
)
|
||||
created_list.append(sup_manager_employee)
|
||||
|
||||
sup_manager_employee.reset_password_token()
|
||||
sup_manager_employee.reset_password_token(found_user=sup_manager_employee)
|
||||
mongo_engine.create_domain_via_user(
|
||||
payload=DomainViaUser(
|
||||
user_uu_id=str(sup_manager_employee.uu_id),
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ from databases import (
|
|||
)
|
||||
|
||||
|
||||
|
||||
def create_endpoints_from_api_functions(routers):
|
||||
from application.create_file import create_app
|
||||
from databases import EndpointRestriction
|
||||
|
||||
api_app = create_app(routers=routers)
|
||||
|
||||
for route in api_app.routes:
|
||||
|
|
@ -290,7 +290,7 @@ def create_modules_and_services_and_actions():
|
|||
service_code=f"SRE-{duty_object.duty_code}",
|
||||
)
|
||||
created_service.save()
|
||||
created_service.is_confirmed=True
|
||||
created_service.is_confirmed = True
|
||||
created_service.save()
|
||||
|
||||
occupant_types = OccupantTypes.filter_all()
|
||||
|
|
@ -302,7 +302,7 @@ def create_modules_and_services_and_actions():
|
|||
service_code=f"SRO-{occupant_type.occupant_code}",
|
||||
)
|
||||
created_service.save()
|
||||
created_service.is_confirmed=True
|
||||
created_service.is_confirmed = True
|
||||
created_service.save()
|
||||
|
||||
create_services_authenticate(module_dict=user_module_module_dict)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,13 @@
|
|||
|
||||
|
||||
class TerminalColors:
|
||||
HEADER = '\033[95m'
|
||||
OKBLUE = '\033[94m'
|
||||
OKCYAN = '\033[96m'
|
||||
OKGREEN = '\033[92m'
|
||||
WARNING = '\033[93m'
|
||||
FAIL = '\033[91m'
|
||||
ENDC = '\033[0m'
|
||||
BOLD = '\033[1m'
|
||||
UNDERLINE = '\033[4m'
|
||||
HEADER = "\033[95m"
|
||||
OKBLUE = "\033[94m"
|
||||
OKCYAN = "\033[96m"
|
||||
OKGREEN = "\033[92m"
|
||||
WARNING = "\033[93m"
|
||||
FAIL = "\033[91m"
|
||||
ENDC = "\033[0m"
|
||||
BOLD = "\033[1m"
|
||||
UNDERLINE = "\033[4m"
|
||||
|
||||
|
||||
def do_alembic():
|
||||
|
|
@ -18,6 +16,7 @@ def do_alembic():
|
|||
|
||||
generate_alembic_with_session(text=text)
|
||||
|
||||
|
||||
def create_one_address():
|
||||
from databases import (
|
||||
AddressCity,
|
||||
|
|
@ -28,6 +27,7 @@ def create_one_address():
|
|||
AddressState,
|
||||
AddressCountry,
|
||||
)
|
||||
|
||||
address_list = []
|
||||
country = AddressCountry.find_or_create(country_name="TÜRKİYE", country_code="TR")
|
||||
address_list.append(country)
|
||||
|
|
@ -100,10 +100,14 @@ def create_application_defaults_func(create_address=False):
|
|||
create_occupant_types_defaults,
|
||||
)
|
||||
import routers
|
||||
|
||||
try:
|
||||
create_endpoints_from_api_functions(routers=routers)
|
||||
except Exception as e:
|
||||
print(f"{TerminalColors.WARNING} create_endpoints_from_api_functions Defaults Error", e)
|
||||
print(
|
||||
f"{TerminalColors.WARNING} create_endpoints_from_api_functions Defaults Error",
|
||||
e,
|
||||
)
|
||||
try:
|
||||
create_application_defaults()
|
||||
except Exception as e:
|
||||
|
|
@ -111,11 +115,16 @@ def create_application_defaults_func(create_address=False):
|
|||
try:
|
||||
create_occupant_types_defaults()
|
||||
except Exception as e:
|
||||
print(f"{TerminalColors.WARNING} create_occupant_types_defaults Defaults Error", e)
|
||||
print(
|
||||
f"{TerminalColors.WARNING} create_occupant_types_defaults Defaults Error", e
|
||||
)
|
||||
try:
|
||||
create_modules_and_services_and_actions()
|
||||
except Exception as e:
|
||||
print(f"{TerminalColors.WARNING} create_modules_and_services_and_actions Defaults Error", e)
|
||||
print(
|
||||
f"{TerminalColors.WARNING} create_modules_and_services_and_actions Defaults Error",
|
||||
e,
|
||||
)
|
||||
try:
|
||||
init_api_enums_build_types()
|
||||
except Exception as e:
|
||||
|
|
@ -123,15 +132,23 @@ def create_application_defaults_func(create_address=False):
|
|||
try:
|
||||
create_all_events_from_actions()
|
||||
except Exception as e:
|
||||
print(f"{TerminalColors.WARNING} create_all_events_from_actions Defaults Error", e)
|
||||
print(
|
||||
f"{TerminalColors.WARNING} create_all_events_from_actions Defaults Error", e
|
||||
)
|
||||
try:
|
||||
add_events_all_services_and_occupant_types()
|
||||
except Exception as e:
|
||||
print(f"{TerminalColors.WARNING} add_events_all_services_and_occupant_types Defaults Error", e)
|
||||
print(
|
||||
f"{TerminalColors.WARNING} add_events_all_services_and_occupant_types Defaults Error",
|
||||
e,
|
||||
)
|
||||
try:
|
||||
add_events_to_system_super_user()
|
||||
except Exception as e:
|
||||
print(f"{TerminalColors.WARNING} add_events_to_system_super_user Defaults Error", e)
|
||||
print(
|
||||
f"{TerminalColors.WARNING} add_events_to_system_super_user Defaults Error",
|
||||
e,
|
||||
)
|
||||
try:
|
||||
if not create_address:
|
||||
return
|
||||
|
|
@ -145,4 +162,3 @@ if __name__ == "__main__":
|
|||
do_alembic()
|
||||
create_application_defaults_func(create_address=True)
|
||||
print("Service App Initial Default Runner is completed")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
class BothAPIS:
|
||||
wag_api = None
|
||||
local_api = None
|
||||
|
||||
|
||||
class BaseAPI:
|
||||
ACCESS_TOKEN_TAG: str = "evyos-session-key"
|
||||
headers: dict = {
|
||||
|
|
|
|||
|
|
@ -76,13 +76,15 @@ class RequestToApi:
|
|||
return response
|
||||
|
||||
def login_via_email_and_password(
|
||||
self, login_data, is_password_valid=True, selection_list: list = None
|
||||
self, login_data, is_password_valid=True, selection_list: list = None
|
||||
):
|
||||
|
||||
if not is_password_valid:
|
||||
if not login_data.get("password_token"):
|
||||
raise Exception("Password token is not found")
|
||||
self.change_password_with_token(password_token=login_data.get("password_token"))
|
||||
self.change_password_with_token(
|
||||
password_token=login_data.get("password_token")
|
||||
)
|
||||
|
||||
login_dict = self.post(endpoint="authentication/login", data=login_data)
|
||||
print("login_dict", login_dict.text)
|
||||
|
|
@ -141,5 +143,5 @@ class RequestToApi:
|
|||
response = self.post(
|
||||
data=data_dict, endpoint="authentication/create_password"
|
||||
)
|
||||
print('change_password_with_token', response.text)
|
||||
print('change_password_with_token', response.json())
|
||||
print("change_password_with_token", response.text)
|
||||
print("change_password_with_token", response.json())
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
from random import randint
|
||||
from faker import Faker
|
||||
|
||||
from service_app_test.test_application.evyos.datas.company_employee_data import list_options
|
||||
from service_app_test.test_application.evyos.datas.get_building_types import list_building_types
|
||||
from service_app_test.test_application.evyos.datas.get_occupants_codes import get_occupants_types
|
||||
from service_app_test.test_application.evyos.datas.get_type_codes import get_type_codes_key_and_class
|
||||
from service_app_test.test_application.evyos.datas.company_employee_data import (
|
||||
list_options,
|
||||
)
|
||||
from service_app_test.test_application.evyos.datas.get_building_types import (
|
||||
list_building_types,
|
||||
)
|
||||
from service_app_test.test_application.evyos.datas.get_occupants_codes import (
|
||||
get_occupants_types,
|
||||
)
|
||||
from service_app_test.test_application.evyos.datas.get_type_codes import (
|
||||
get_type_codes_key_and_class,
|
||||
)
|
||||
from service_app_test.bases import active_and_confirmed
|
||||
|
||||
|
||||
|
|
@ -182,7 +190,7 @@ def list_build_living_space(requester):
|
|||
return response.json()
|
||||
|
||||
|
||||
def list_building_parts(requester,query: dict = None):
|
||||
def list_building_parts(requester, query: dict = None):
|
||||
query_dict = query
|
||||
if not query:
|
||||
query_dict = {"part_code__contains": ":"}
|
||||
|
|
@ -292,7 +300,9 @@ def assign_random_people_to_build_parts(
|
|||
uu_id_occupant_type_flat_manager = occupant_dict["occupant_type_flat_manager"]
|
||||
uu_id_occupant_type_flat_resident = occupant_dict["occupant_type_flat_resident"]
|
||||
|
||||
man_room = list_building_parts(query={"part_no": "0", "build_uu_id": build_uu_id}, requester=requester)
|
||||
man_room = list_building_parts(
|
||||
query={"part_no": "0", "build_uu_id": build_uu_id}, requester=requester
|
||||
)
|
||||
man_room_uu_id = man_room["data"][0]["uu_id"]
|
||||
|
||||
for i in range(len(list_of_random_people)):
|
||||
|
|
@ -307,7 +317,7 @@ def assign_random_people_to_build_parts(
|
|||
build_part_uu_id=selected_build_part_uu_id,
|
||||
person_uu_id=list_of_random_people[i - 1]["uu_id"],
|
||||
occupant_type_flat_owner_uu_id=uu_id_occupant_type_flat_owner,
|
||||
requester=requester
|
||||
requester=requester,
|
||||
)
|
||||
|
||||
# Property Tenant
|
||||
|
|
@ -315,7 +325,7 @@ def assign_random_people_to_build_parts(
|
|||
build_part_uu_id=selected_build_part_uu_id,
|
||||
person_uu_id=list_of_random_people[i]["uu_id"],
|
||||
occupant_type_flat_tenant_uu_id=uu_id_occupant_type_flat_tenant,
|
||||
requester=requester
|
||||
requester=requester,
|
||||
)
|
||||
|
||||
# Property Tenant Living Space Occupant
|
||||
|
|
@ -323,7 +333,7 @@ def assign_random_people_to_build_parts(
|
|||
build_part_uu_id=selected_build_part_uu_id,
|
||||
person_uu_id=list_of_random_people[i]["uu_id"],
|
||||
occupant_type_flat_resident_uu_id=uu_id_occupant_type_flat_resident,
|
||||
requester=requester
|
||||
requester=requester,
|
||||
)
|
||||
|
||||
if i == 1:
|
||||
|
|
@ -331,7 +341,7 @@ def assign_random_people_to_build_parts(
|
|||
build_part_uu_id=man_room_uu_id,
|
||||
person_uu_id=list_of_random_people[i]["uu_id"],
|
||||
occupant_type_flat_manager_uu_id=uu_id_occupant_type_flat_manager,
|
||||
requester=requester
|
||||
requester=requester,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -353,7 +363,9 @@ def run_address_to_building(requester):
|
|||
create_post_code(post_code=post_code_dict(street_uu_id), requester=requester)
|
||||
selected_post_code_uu_id = list_post_codes(requester=requester)["data"][0]["uu_id"]
|
||||
|
||||
create_addresses(address=address_dict(selected_post_code_uu_id), requester=requester)
|
||||
create_addresses(
|
||||
address=address_dict(selected_post_code_uu_id), requester=requester
|
||||
)
|
||||
selected_address_uu_id = list_addresses(requester=requester)["data"][0]["uu_id"]
|
||||
|
||||
build_type_response = list_building_types(type_code="apt")
|
||||
|
|
@ -363,7 +375,7 @@ def run_address_to_building(requester):
|
|||
address_uu_id=selected_address_uu_id,
|
||||
build_type_uu_id=build_type_uu_id_,
|
||||
),
|
||||
requester=requester
|
||||
requester=requester,
|
||||
)
|
||||
|
||||
selected_build_uu_id = list_building(requester=requester)["data"][0]["uu_id"]
|
||||
|
|
@ -378,6 +390,6 @@ def run_address_to_building(requester):
|
|||
list_of_building_parts=building_parts_list,
|
||||
occupant_dict=occupant_type_dict,
|
||||
build_uu_id=selected_build_uu_id,
|
||||
requester=requester
|
||||
requester=requester,
|
||||
)
|
||||
print("list_build_living_space", list_build_living_space(requester=requester))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
from service_app_test.test_application.evyos.people import (
|
||||
create_random_person,
|
||||
create_random_user,
|
||||
|
|
@ -176,7 +175,9 @@ def create_occupant_people_via_list(people_count: int, requester):
|
|||
def run_company_and_depends(company_uu_id, requester):
|
||||
create_department_via_list(list_of_departments=departments, requester=requester)
|
||||
create_duty_via_list(list_of_duties=duties, requester=requester)
|
||||
create_duties_via_list(list_of_duties=duties, company_uu_id=company_uu_id, requester=requester)
|
||||
create_duties_via_list(
|
||||
list_of_duties=duties, company_uu_id=company_uu_id, requester=requester
|
||||
)
|
||||
create_staff_via_list(list_of_staff=staffs, requester=requester)
|
||||
create_employee_via_list(list_of_staff=duties, requester=requester)
|
||||
create_people_via_list(people_count=10, requester=requester)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
def list_building_types(requester, lang: str = "TR", type_code: str = None):
|
||||
from service_app_test.test_application.evyos.datas.company_employee_data import list_options
|
||||
from service_app_test.test_application.evyos.datas.company_employee_data import (
|
||||
list_options,
|
||||
)
|
||||
|
||||
options_smart_query = {
|
||||
**list_options,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
def get_occupants_types(occupant_code, requester):
|
||||
response = requester.post(
|
||||
endpoint="/occupant_types/get/code",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
def get_type_codes_key_and_class(class_name, key_name, requester):
|
||||
response = requester.post(
|
||||
endpoint="/enums/get/key",
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
import arrow
|
||||
|
||||
from service_app_test.bases import active_and_confirmed
|
||||
from service_app_test.test_application.evyos.datas.company_employee_data import list_options
|
||||
from service_app_test.test_application.evyos.datas.get_type_codes import get_type_codes_key_and_class
|
||||
from service_app_test.test_application.evyos.datas.company_employee_data import (
|
||||
list_options,
|
||||
)
|
||||
from service_app_test.test_application.evyos.datas.get_type_codes import (
|
||||
get_type_codes_key_and_class,
|
||||
)
|
||||
from service_app_test.test_application.evyos.address_building import list_building
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
from service_app_test.bases import active_and_confirmed
|
||||
from service_app_test.test_application.evyos.datas.get_occupants_codes import get_occupants_types
|
||||
from service_app_test.test_application.evyos.datas.get_occupants_codes import (
|
||||
get_occupants_types,
|
||||
)
|
||||
|
||||
# from service_app_test.test_application.evyos.datas.get_type_codes import get_type_codes_key_and_class
|
||||
|
||||
|
||||
|
|
@ -45,9 +48,9 @@ def assign_people_to_pre_or_wrt(
|
|||
data={
|
||||
"token": manager_token,
|
||||
"build_living_space_uu_id": person_uu_id,
|
||||
"occupant_type_uu_id": get_occupants_types(occupant_code=occupant_code, requester=requester)[
|
||||
"data"
|
||||
]["uu_id"],
|
||||
"occupant_type_uu_id": get_occupants_types(
|
||||
occupant_code=occupant_code, requester=requester
|
||||
)["data"]["uu_id"],
|
||||
},
|
||||
)
|
||||
print("text", response.text)
|
||||
|
|
@ -99,7 +102,13 @@ def create_decision_book_items_with_occupant_user(
|
|||
|
||||
|
||||
def run_decision_book_items(
|
||||
writers_token, unit_price, info_type_uu_id, is_fixed, requester, start_date=None, end_date=None
|
||||
writers_token,
|
||||
unit_price,
|
||||
info_type_uu_id,
|
||||
is_fixed,
|
||||
requester,
|
||||
start_date=None,
|
||||
end_date=None,
|
||||
):
|
||||
if start_date and end_date:
|
||||
create_decision_book_items_with_occupant_user(
|
||||
|
|
@ -109,7 +118,7 @@ def run_decision_book_items(
|
|||
info_type_uu_id=info_type_uu_id,
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
requester=requester
|
||||
requester=requester,
|
||||
)
|
||||
else:
|
||||
create_decision_book_items_with_occupant_user(
|
||||
|
|
@ -117,5 +126,5 @@ def run_decision_book_items(
|
|||
unit_price=unit_price,
|
||||
is_fixed=is_fixed,
|
||||
info_type_uu_id=info_type_uu_id,
|
||||
requester=requester
|
||||
requester=requester,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -3,9 +3,15 @@ import arrow
|
|||
from service_app_test.bases import RequestToApi
|
||||
from service_app_test.api_configs import WagAPI, LocalAPI, BothAPIS
|
||||
|
||||
from service_app_test.test_application.evyos.company_employee import run_company_and_depends
|
||||
from service_app_test.test_application.evyos.address_building import run_address_to_building
|
||||
from service_app_test.test_application.evyos.datas.get_type_codes import get_type_codes_key_and_class
|
||||
from service_app_test.test_application.evyos.company_employee import (
|
||||
run_company_and_depends,
|
||||
)
|
||||
from service_app_test.test_application.evyos.address_building import (
|
||||
run_address_to_building,
|
||||
)
|
||||
from service_app_test.test_application.evyos.datas.get_type_codes import (
|
||||
get_type_codes_key_and_class,
|
||||
)
|
||||
from service_app_test.test_application.evyos.decision_book import (
|
||||
run_decision_book_depends,
|
||||
list_decision_books,
|
||||
|
|
@ -23,7 +29,7 @@ login_creds_employee = {
|
|||
"access_key": "karatay.berkay.sup@evyos.com.tr",
|
||||
"password": "string",
|
||||
"remember_me": False,
|
||||
"password_token": "z5nPguDu6PrY_94KlTGxGBCMcK6rZcDl5AGqO5aHWY7TcQF8LJGYikMQs9labvqdz5yM7vE_f8Zq_vqp00o3EnWwWCWhel-EsMcAujBKNRjV3jC_4xk0_1r_unIYogWAjz_spZipX6pncsch2ngvv0dpx4lHSiZ5QrDTA1RefQ"
|
||||
"password_token": "z5nPguDu6PrY_94KlTGxGBCMcK6rZcDl5AGqO5aHWY7TcQF8LJGYikMQs9labvqdz5yM7vE_f8Zq_vqp00o3EnWwWCWhel-EsMcAujBKNRjV3jC_4xk0_1r_unIYogWAjz_spZipX6pncsch2ngvv0dpx4lHSiZ5QrDTA1RefQ",
|
||||
}
|
||||
access_key_president = "bmanco@example.net"
|
||||
login_creds_occupant = {
|
||||
|
|
@ -61,17 +67,22 @@ local_api = RequestToApi()
|
|||
local_api.overwrite_base_url(base_url=LocalAPI.base_url)
|
||||
|
||||
if add_with_employee:
|
||||
print('local_api', local_api.post(endpoint="authentication/login", data=login_creds_employee).text)
|
||||
print(
|
||||
"local_api",
|
||||
local_api.post(endpoint="authentication/login", data=login_creds_employee).text,
|
||||
)
|
||||
|
||||
exit()
|
||||
local_api.selected_object = local_api.login_via_email_and_password(
|
||||
login_data=login_creds_employee, is_password_valid=False
|
||||
)
|
||||
print('local_api', local_api.headers)
|
||||
print("local_api", local_api.headers)
|
||||
|
||||
print("select_company_uu_id", local_api.selected_object)
|
||||
exit()
|
||||
run_company_and_depends(company_uu_id=local_api.selected_object, requester=local_api)
|
||||
run_company_and_depends(
|
||||
company_uu_id=local_api.selected_object, requester=local_api
|
||||
)
|
||||
run_address_to_building(requester=local_api)
|
||||
exit()
|
||||
|
||||
|
|
|
|||
|
|
@ -4,14 +4,18 @@ from service_app_test.api_configs import BothAPIS
|
|||
def migrate_build(requester: BothAPIS):
|
||||
return
|
||||
|
||||
|
||||
def migrate_build_area(requester: BothAPIS):
|
||||
return
|
||||
|
||||
|
||||
def migrate_build_part(requester: BothAPIS):
|
||||
return
|
||||
|
||||
|
||||
def migrate_build_iban(requester: BothAPIS):
|
||||
return
|
||||
|
||||
|
||||
def migrate_build_living_space(requester: BothAPIS):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -6,26 +6,25 @@ def migrate_company(requester: BothAPIS):
|
|||
filter_object = FilterObject(
|
||||
page=1,
|
||||
size=100,
|
||||
order_field="id",
|
||||
order_type="asc",
|
||||
)
|
||||
response = requester.wag_api.post(
|
||||
endpoint="/company/list",
|
||||
data=filter_object.dump(),
|
||||
)
|
||||
response_json = response.json()
|
||||
print('response_json', response_json)
|
||||
response_datas = response_json['data']
|
||||
print("response_json", response_json)
|
||||
response_datas = response_json["data"]
|
||||
for response_data in response_datas:
|
||||
print('response_data', response_data)
|
||||
response_data['active'] = True
|
||||
response_data['deleted'] = False
|
||||
response_data['is_confirmed'] = True
|
||||
response_data['expiry_starts'] = None
|
||||
response_data['expiry_ends'] = None
|
||||
new_response_data = dict()
|
||||
for key, value in dict(response_data).items():
|
||||
if value is not None and not str(value) == "None":
|
||||
new_response_data[key] = response_data[key]
|
||||
new_response_data.pop("uu_id", None)
|
||||
print("new_response_data", new_response_data)
|
||||
new_response_data["company_tag"] = response_data["formal_name"]
|
||||
response = requester.local_api.post(
|
||||
endpoint="/company/create",
|
||||
data=response_data,
|
||||
data=new_response_data,
|
||||
)
|
||||
print('response', response.text)
|
||||
print("response", response.text)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -3,4 +3,4 @@ from service_app_test.api_configs import BothAPIS
|
|||
|
||||
def migrate_people(requester: BothAPIS):
|
||||
# Migrate old data
|
||||
pass
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -12,11 +12,13 @@ system_default = dict(
|
|||
|
||||
|
||||
def read_json_file(json_directory, json_file):
|
||||
with open(f"{json_directory}/{json_file}.json", "r", encoding='utf-8') as json_file:
|
||||
with open(f"{json_directory}/{json_file}.json", "r", encoding="utf-8") as json_file:
|
||||
return loads(json_file.read())
|
||||
|
||||
|
||||
def bulk_insert_alchemy_postgresql(active_session, table, data_list, on_conflict_constraints = None):
|
||||
def bulk_insert_alchemy_postgresql(
|
||||
active_session, table, data_list, on_conflict_constraints=None
|
||||
):
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
|
||||
st = perf_counter()
|
||||
|
|
@ -29,11 +31,10 @@ def bulk_insert_alchemy_postgresql(active_session, table, data_list, on_conflict
|
|||
)
|
||||
)
|
||||
else:
|
||||
session_execute = active_session.execute(
|
||||
insert(table)
|
||||
.values(data_list)
|
||||
)
|
||||
session_execute = active_session.execute(insert(table).values(data_list))
|
||||
count_row = session_execute.rowcount
|
||||
print(f'Table : {table.__name__} count_row : {count_row} : time took : {round(perf_counter() - st, 2)} seconds')
|
||||
print(
|
||||
f"Table : {table.__name__} count_row : {count_row} : time took : {round(perf_counter() - st, 2)} seconds"
|
||||
)
|
||||
active_session.commit()
|
||||
active_session.flush()
|
||||
active_session.flush()
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@ login_data = {
|
|||
"access_key": "karatay.berkay.sup@evyos.com.tr",
|
||||
"password": "string",
|
||||
"remember_me": False,
|
||||
"password_token": "z5nPguDu6PrY_94KlTGxGBCMcK6rZcDl5AGqO5aHWY7TcQF8LJGYikMQs9labvqdz5yM7vE_f8Zq_vqp00o3EnWwWCWhel-EsMcAujBKNRjV3jC_4xk0_1r_unIYogWAjz_spZipX6pncsch2ngvv0dpx4lHSiZ5QrDTA1RefQ",
|
||||
"password_token": ""
|
||||
}
|
||||
login_data_wag = {
|
||||
"domain": "evyos.com.tr",
|
||||
"access_key": "karatay.berkay.sup@evyos.com.tr",
|
||||
"password": "string",
|
||||
"remember_me": False,
|
||||
"password_token": ""
|
||||
"password_token": "",
|
||||
}
|
||||
|
||||
wag_api = RequestToApi()
|
||||
|
|
@ -36,7 +36,7 @@ wag_api.selected_object = wag_api.login_via_email_and_password(
|
|||
local_api = RequestToApi()
|
||||
local_api.overwrite_base_url(base_url=LocalAPI.base_url)
|
||||
local_api.selected_object = local_api.login_via_email_and_password(
|
||||
login_data=login_data, is_password_valid=False
|
||||
login_data=login_data, is_password_valid=True
|
||||
)
|
||||
|
||||
both_apis = BothAPIS()
|
||||
|
|
@ -45,6 +45,7 @@ both_apis.local_api = local_api
|
|||
|
||||
migrate_company(requester=both_apis)
|
||||
migrate_people(requester=both_apis)
|
||||
exit()
|
||||
migrate_build(requester=both_apis)
|
||||
migrate_build_area(requester=both_apis)
|
||||
migrate_build_part(requester=both_apis)
|
||||
|
|
|
|||
Loading…
Reference in New Issue