super_user and services updated

This commit is contained in:
2024-12-05 18:59:46 +03:00
parent 88f94c37c2
commit 88309eb49d
20 changed files with 317 additions and 116 deletions

View File

@@ -149,8 +149,8 @@ class AuthenticationSelectEventMethods(MethodToEvent):
Employees.staff_id.in_(staff_ids),
).data
reachable_event_list_id, reachable_event_list_uu_id = (
Event2Employee.get_event_id_by_employee_id(employee_id=employee.id)
reachable_event_list_id = Event2Employee.get_event_id_by_employee_id(
employee_id=employee.id
)
staff = Staff.filter_one(
Staff.id == employee.staff_id,
@@ -183,7 +183,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
employee_id=employee.id,
employee_uu_id=employee.uu_id.__str__(),
reachable_event_list_id=reachable_event_list_id,
reachable_event_list_uu_id=reachable_event_list_uu_id,
# reachable_event_list_uu_id=reachable_event_list_uu_id,
),
)
return JSONResponse(
@@ -225,7 +225,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
BuildLivingSpace.person_id == token_dict.person_id,
BuildLivingSpace.build_parts_id == build_part.id,
).data:
reachable_event_list_id, reachable_event_list_uu_id = (
reachable_event_list_id = (
Event2Occupant.get_event_id_by_build_living_space_id(
Event2Occupant.build_living_space_id
== selected_occupant_type.id
@@ -248,7 +248,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
responsible_company_id=company_related.id,
responsible_company_uuid=company_related.uu_id.__str__(),
reachable_event_list_id=reachable_event_list_id,
reachable_event_list_uu_id=reachable_event_list_uu_id,
# reachable_event_list_uu_id=reachable_event_list_uu_id,
),
)
return JSONResponse(

View File

@@ -139,8 +139,8 @@ class AuthenticationSelectEventMethods(MethodToEvent):
Employees.people_id == token_dict.person_id,
Employees.staff_id.in_(staff_ids),
).data
reachable_event_list_id, reachable_event_list_uu_id = (
Event2Employee.get_event_id_by_employee_id(employee_id=employee.id)
reachable_event_list_id = Event2Employee.get_event_id_by_employee_id(
employee_id=employee.id
)
staff = Staff.filter_one(
Staff.id == employee.staff_id,
@@ -172,7 +172,6 @@ class AuthenticationSelectEventMethods(MethodToEvent):
employee_id=employee.id,
employee_uu_id=employee.uu_id.__str__(),
reachable_event_list_id=reachable_event_list_id,
reachable_event_list_uu_id=reachable_event_list_uu_id,
),
)
return JSONResponse(
@@ -216,7 +215,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
BuildLivingSpace.person_id == token_dict.person_id,
BuildLivingSpace.build_parts_id == build_part.id,
).data:
reachable_event_list_id, reachable_event_list_uu_id = (
reachable_event_list_id = (
Event2Occupant.get_event_id_by_build_living_space_id(
build_living_space_id=selected_occupant_type.id
)
@@ -238,7 +237,6 @@ class AuthenticationSelectEventMethods(MethodToEvent):
responsible_company_id=company_related.id,
responsible_company_uuid=company_related.uu_id.__str__(),
reachable_event_list_id=reachable_event_list_id,
reachable_event_list_uu_id=reachable_event_list_uu_id,
),
)
return JSONResponse(

View File

@@ -186,15 +186,9 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
)
last_living_space.save()
user_module = Modules.filter_one(
Modules.module_code == "USR-PUB", system=True
).data
created_living_space.save()
created_living_space.update(is_confirmed=True)
created_living_space.save()
ModulesBindOccupantEventMethods.modules_bind_occupant_system(
created_living_space.save_and_confirm()
ModulesBindOccupantEventMethods.bind_default_module_for_first_init_occupant(
build_living_space_id=created_living_space.id,
modules_id=user_module.id,
)
return created_living_space

View File

@@ -15,6 +15,8 @@ from api_events.events.events.events_bind_services import (
)
from api_library.date_time_actions.date_functions import system_arrow
from api_validations.core_response import AlchemyJsonResponse
from databases.sql_models.company.employee import Employees
from databases.sql_models.event.event import Event2Occupant, Event2Employee
class ModulesBindOccupantEventMethods(MethodToEvent):
@@ -25,34 +27,64 @@ class ModulesBindOccupantEventMethods(MethodToEvent):
}
@classmethod
def modules_bind_occupant_system(
cls, build_living_space_id: int, modules_id: int, expires_at: str = None
def bind_default_module_for_first_init_occupant(
cls, build_living_space_id: int, expires_at: str = None
):
living_space = BuildLivingSpace.filter_one(
BuildLivingSpace.id == build_living_space_id,
).data
modules = Modules.filter_one(Modules.id == modules_id).data
modules = Modules.filter_all(Modules.is_default_module == True).data
if not living_space or not modules:
print(f"Giving living Space or Modules: {modules.module_name} not found")
print(f"Giving living Space or Modules: Default not found")
return
service_build_dict = dict(build_living_space_id=living_space.id)
if expires_at:
service_build_dict["expires_at"] = str(system_arrow.get(expires_at))
else:
service_build_dict["expires_at"] = str(
system_arrow.get(living_space.expiry_ends)
)
expiry_ends = str(system_arrow.get(living_space.expiry_ends))
service_build_dict["expires_at"] = expiry_ends
for service in modules.retrieve_services():
ServiceBindOccupantEventMethods.bind_services_occupant_system(
**service_build_dict,
service_id=service.id,
)
BuildLivingSpace.save()
for module in modules:
for service in module.retrieve_services():
event_occupant = Event2Occupant.find_or_create(
event_service_id=service.id,
event_service_uu_id=str(service.uu_id),
build_living_space_id=living_space.id,
build_living_space_uu_id=str(living_space.uu_id),
)
event_occupant.save_and_confirm()
return True
# @classmethod
# def modules_bind_occupant_system(
# cls, build_living_space_id: int, modules_id: int, expires_at: str = None
# ):
#
# living_space = BuildLivingSpace.filter_one(
# BuildLivingSpace.id == build_living_space_id,
# ).data
# modules = Modules.filter_one(Modules.id == modules_id).data
#
# if not living_space or not modules:
# print(f"Giving living Space or Modules: {modules.module_name} not found")
# return
# service_build_dict = dict(build_living_space_id=living_space.id)
# if expires_at:
# service_build_dict["expires_at"] = str(system_arrow.get(expires_at))
# else:
# service_build_dict["expires_at"] = str(
# system_arrow.get(living_space.expiry_ends)
# )
#
# for service in modules.retrieve_services():
# ServiceBindOccupantEventMethods.bind_services_occupant_system(
# **service_build_dict,
# service_id=service.id,
# )
# BuildLivingSpace.save()
# return True
@classmethod
def modules_bind_occupant(
cls,
@@ -70,6 +102,37 @@ class ModulesBindEmployeeEventMethods(MethodToEvent):
"": "modules_bind_employee",
}
@classmethod
def bind_default_module_for_first_init_occupant(
cls, employee_id: int, expires_at: str = None
):
employee = Employees.filter_one(
Employees.id == employee_id,
).data
modules = Modules.filter_all(Modules.is_default_module == True).data
if not employee or not modules:
print(f"Giving living Space or Modules: Default not found")
return
service_build_dict = dict(build_living_space_id=employee.id)
if expires_at:
service_build_dict["expires_at"] = str(system_arrow.get(expires_at))
else:
expiry_ends = str(system_arrow.get(employee.expiry_ends))
service_build_dict["expires_at"] = expiry_ends
for module in modules:
for service in module.retrieve_services():
event_employee = Event2Employee.find_or_create(
event_service_id=service.id,
event_service_uu_id=str(service.uu_id),
employee_id=employee.id,
employee_uu_id=str(employee.uu_id),
)
event_employee.save_and_confirm()
return True
@classmethod
def modules_bind_employee(
cls,

View File

@@ -87,7 +87,7 @@ class UserCreateEventMethods(MethodToEvent):
company_uuid=created_user.related_company,
)
mongo_query_identity.create_domain_via_user(payload=domain_via_user)
reset_password_token = created_user.reset_password_token()
reset_password_token = created_user.reset_password_token(found_user=created_user)
send_email_completed = send_email(
subject=f"Dear {created_user.user_tag}, your password has been changed.",
receivers=[str(created_user.email)],