140 lines
4.9 KiB
Python
140 lines
4.9 KiB
Python
def create_all_events_from_actions():
|
|
import api_events
|
|
from databases.sql_models import Events
|
|
|
|
active_confirmed = dict(
|
|
created_by="System",
|
|
confirmed_by="System",
|
|
is_confirmed=True,
|
|
active=True,
|
|
deleted=False,
|
|
is_notification_send=True,
|
|
)
|
|
an_empty_list, duplicate_list = [], []
|
|
|
|
for event in events.__all__:
|
|
event_selected = getattr(events, event)
|
|
for (
|
|
event_selected_key,
|
|
event_selected_one,
|
|
) in event_selected.__event_keys__.items():
|
|
an_empty_list.append(event_selected_key)
|
|
event_selected_function = getattr(event_selected, event_selected_one, None)
|
|
|
|
if endpoint_match := event_selected.action_match:
|
|
if event_selected_function:
|
|
selected_event = Events.find_one(
|
|
event_type=event_selected.event_type,
|
|
function_class=event,
|
|
function_code=event_selected_key,
|
|
endpoint_id=endpoint_match.id,
|
|
endpoint_uu_id=str(endpoint_match.uu_id),
|
|
**active_confirmed,
|
|
)
|
|
if not selected_event:
|
|
created_event = Events.create(
|
|
event_type=event_selected.event_type,
|
|
function_class=event,
|
|
function_code=event_selected_key,
|
|
endpoint_id=endpoint_match.id,
|
|
endpoint_uu_id=str(endpoint_match.uu_id),
|
|
**active_confirmed,
|
|
)
|
|
print(f"Event created: {created_event.uu_id}")
|
|
|
|
for item in an_empty_list:
|
|
if an_empty_list.count(item) > 1:
|
|
if item not in duplicate_list:
|
|
duplicate_list.append(item)
|
|
|
|
if duplicate_list:
|
|
raise Exception(
|
|
f"Duplicate events found: {duplicate_list}. Check events folder look for given uu-ids."
|
|
)
|
|
|
|
return True
|
|
|
|
|
|
def add_events_all_services_and_occupant_types():
|
|
from database_sql_models import Services, Service2Events
|
|
import tasks2events
|
|
|
|
active_confirmed = dict(
|
|
created_by="System",
|
|
confirmed_by="System",
|
|
is_confirmed=True,
|
|
active=True,
|
|
deleted=False,
|
|
is_notification_send=True,
|
|
)
|
|
for event_block in tasks2events.__all__:
|
|
event_block_class = getattr(tasks2events, event_block)
|
|
service_selected = Services.find_one(
|
|
service_code=getattr(event_block_class, "service_code", None),
|
|
)
|
|
if not service_selected:
|
|
raise Exception(f"{event_block_class.service_code} service is not found")
|
|
|
|
service_selected.update(
|
|
related_responsibility=getattr(event_block_class, "related_code", None)
|
|
)
|
|
for block in event_block_class():
|
|
event_id, event_uu_id = block
|
|
Service2Events.find_or_create(
|
|
service_id=service_selected.id,
|
|
service_uu_id=str(service_selected.uu_id),
|
|
event_id=event_id,
|
|
event_uu_id=event_uu_id,
|
|
**active_confirmed,
|
|
)
|
|
|
|
|
|
def add_events_to_system_super_user():
|
|
from events.events_bind_services import ServiceBindEmployeeEventMethods
|
|
from database_sql_models import Services, Employees, Staff
|
|
|
|
add_service = Services.find_one(service_code="SRE-SUE")
|
|
if not add_service:
|
|
raise Exception("Service not found")
|
|
|
|
find_staff = Staff.find_one(staff_code="SUE")
|
|
if not find_staff:
|
|
raise Exception("Super User not found")
|
|
|
|
add_employee = Employees.find_one(staff_id=find_staff.id)
|
|
if not add_employee:
|
|
raise Exception("Super User Employee not found")
|
|
|
|
ServiceBindEmployeeEventMethods.bind_services_employee(
|
|
service_id=add_service.id,
|
|
employee_id=add_employee.id,
|
|
)
|
|
|
|
# super_user_service = Services.find_or_create(service_code="SRE-SU")
|
|
# if not super_user_service:
|
|
# raise Exception("Super user is service not found")
|
|
#
|
|
# user_default_service = Services.find_or_create(service_code="AUTH")
|
|
# if not user_default_service:
|
|
# raise Exception("AUTH service is not found")
|
|
#
|
|
# for item in SuperUserEventBlock():
|
|
# event_id, event_uu_id = item
|
|
# Service2Events.find_or_create(
|
|
# service_id=super_user_service.id,
|
|
# service_uu_id=str(super_user_service.uu_id),
|
|
# event_id=event_id,
|
|
# event_uu_id=event_uu_id,
|
|
# **active_confirmed,
|
|
# )
|
|
#
|
|
# for event_block in AuthDefaultEventBlock():
|
|
# event_id, event_uu_id = event_block
|
|
# Service2Events.find_or_create(
|
|
# service_id=user_default_service.id,
|
|
# service_uu_id=str(user_default_service.uu_id),
|
|
# event_id=event_id,
|
|
# event_uu_id=event_uu_id,
|
|
# **active_confirmed,
|
|
# )
|