appender events and applications are updated

This commit is contained in:
2025-05-06 12:03:58 +03:00
parent dd707b2463
commit e0ae1ee80a
53 changed files with 2358 additions and 829 deletions

View File

@@ -1,12 +1,12 @@
from Controllers.Postgres.database import get_db
from Schemas import Users, Employees, BuildLivingSpace
from Schemas import Users, Employees, BuildLivingSpace, Services
from init_service_to_events import init_service_to_event_matches_for_super_user
from init_applications import (
init_applications_for_super_user,
init_applications_for_general_manager,
init_applications_for_build_manager,
init_applications_for_owner,
init_applications_for_tenant,
# init_applications_for_general_manager,
# init_applications_for_build_manager,
# init_applications_for_owner,
# init_applications_for_tenant,
)
@@ -16,62 +16,59 @@ if __name__ == "__main__":
Set Events to service | Set Service to employee
"""
with get_db() as db_session:
if super_man := Users.filter_one(
Users.email == "karatay.berkay.sup@evyos.com.tr", db=db_session
).data:
super_employee = Employees.filter_one(
Employees.people_id == super_man.person_id, db=db_session
).data
service_super_user = Services.filter_one(Services.service_code == "SRE-SUE", db=db_session).data
user_super_user = Users.filter_one(Users.email == "karatay.berkay.sup@evyos.com.tr", db=db_session).data
employee_super_user = Employees.filter_one(Employees.people_id == user_super_user.person_id, db=db_session).data
if service_super_user and user_super_user and employee_super_user:
init_service_to_event_matches_for_super_user(
super_user=super_employee, db_session=db_session
service_match=service_super_user, employee_match=employee_super_user, db_session=db_session
)
init_applications_for_super_user(
super_user=super_employee, db_session=db_session
service_match=service_super_user, employee_match=employee_super_user, db_session=db_session
)
with get_db() as db_session:
print("Createing GM")
if gen_man := Users.filter_one(
Users.email == "example.general@evyos.com.tr", db=db_session
).data:
gen_man_employee = Employees.filter_one(
Employees.people_id == gen_man.person_id, db=db_session
).data
print("General Manager : ", gen_man_employee)
init_applications_for_general_manager(
super_user=gen_man_employee, db_session=db_session
)
# with get_db() as db_session:
# print("Createing GM")
# if gen_man := Users.filter_one(
# Users.email == "example.general@evyos.com.tr", db=db_session
# ).data:
# gen_man_employee = Employees.filter_one(
# Employees.people_id == gen_man.person_id, db=db_session
# ).data
# print("General Manager : ", gen_man_employee)
# init_applications_for_general_manager(
# super_user=gen_man_employee, db_session=db_session
# )
with get_db() as db_session:
if build_man := Users.filter_one(
Users.email == "example.build.manager@gmail.com", db=db_session
).data:
build_man_employee = BuildLivingSpace.filter_one(
BuildLivingSpace.person_id == build_man.person_id, db=db_session
).data
init_applications_for_build_manager(
super_user=build_man_employee, db_session=db_session
)
# with get_db() as db_session:
# if build_man := Users.filter_one(
# Users.email == "example.build.manager@gmail.com", db=db_session
# ).data:
# build_man_employee = BuildLivingSpace.filter_one(
# BuildLivingSpace.person_id == build_man.person_id, db=db_session
# ).data
# init_applications_for_build_manager(
# super_user=build_man_employee, db_session=db_session
# )
with get_db() as db_session:
if own_flt := Users.filter_one(
Users.email == "example.owner@gmail.com", db=db_session
).data:
own_flt_employee = BuildLivingSpace.filter_one(
BuildLivingSpace.person_id == own_flt.person_id, db=db_session
).data
init_applications_for_owner(
super_user=own_flt_employee, db_session=db_session
)
# with get_db() as db_session:
# if own_flt := Users.filter_one(
# Users.email == "example.owner@gmail.com", db=db_session
# ).data:
# own_flt_employee = BuildLivingSpace.filter_one(
# BuildLivingSpace.person_id == own_flt.person_id, db=db_session
# ).data
# init_applications_for_owner(
# super_user=own_flt_employee, db_session=db_session
# )
with get_db() as db_session:
if ten_flt := Users.filter_one(
Users.email == "example.tenant@gmail.com", db=db_session
).data:
ten_flt_employee = BuildLivingSpace.filter_one(
BuildLivingSpace.person_id == ten_flt.person_id, db=db_session
).data
init_applications_for_tenant(
super_user=ten_flt_employee, db_session=db_session
)
# with get_db() as db_session:
# if ten_flt := Users.filter_one(
# Users.email == "example.tenant@gmail.com", db=db_session
# ).data:
# ten_flt_employee = BuildLivingSpace.filter_one(
# BuildLivingSpace.person_id == ten_flt.person_id, db=db_session
# ).data
# init_applications_for_tenant(
# super_user=ten_flt_employee, db_session=db_session
# )

View File

@@ -4,222 +4,193 @@ from Schemas import (
Application2Occupant,
Employees,
BuildLivingSpace,
Services,
Service2Application,
)
def init_applications_for_super_user(super_user: Employees, db_session=None) -> None:
list_of_created_apps = [
dict(
name="Dashboard1",
application_code="app000001",
site_url="/dashboard",
application_type="info",
description="Dashboard Page",
),
dict(
name="Individual",
application_code="app000003",
site_url="/individual",
application_type="Dash",
description="Individual Page for people",
),
dict(
name="User",
application_code="app000004",
site_url="/user",
application_type="Dash",
description="Individual Page for user",
),
dict(
name="Build",
application_code="app000005",
site_url="/build",
application_type="Dash",
description="Individual Page for build",
),
dict(
name="BuildParts",
application_code="app000006",
site_url="/build/parts",
application_type="Dash",
description="Individual Page for build parts",
),
dict(
name="BuildArea",
application_code="app000007",
site_url="/build/area",
application_type="Dash",
description="Individual Page for build area",
),
dict(
name="ManagementAccounting",
application_code="app000008",
site_url="/management/accounting",
application_type="Dash",
description="Individual Page for management accounting",
),
dict(
name="ManagementBudget",
application_code="app000009",
site_url="/management/budget",
application_type="Dash",
description="Individual Page for management accounting2",
),
dict(
name="ManagementMeetingClose",
application_code="app000010",
site_url="/annual/meeting/close",
application_type="Dash",
description="Individual Page for management accounting3",
),
dict(
name="EmergencyMeeting",
application_code="app000011",
site_url="/emergency/meeting",
application_type="Dash",
description="Individual Page for management accounting4",
),
dict(
name="EmergencyMeetingClose",
application_code="app000012",
site_url="/emergency/meeting/close",
application_type="Dash",
description="Individual Page for management accounting5",
),
dict(
name="MeetingParticipation",
application_code="app000013",
site_url="/meeting/participation",
application_type="Dash",
description="Individual Page for management accounting6",
),
]
for list_of_created_app in list_of_created_apps:
created_page = Applications.find_or_create(
**list_of_created_app,
def init_applications_for_super_user(service_match: Services, employee_match: Employees, db_session=None) -> None:
list_of_all_events = Applications.filter_all(db=db_session).data
Service2Application.filter_all(db=db_session).query.delete()
Service2Application.save(db=db_session)
for list_of_event_code in list_of_all_events:
service_to_event_found = Service2Application.filter_one_system(
Service2Application.application_id == list_of_event_code.id,
Service2Application.service_id == service_match.id,
db=db_session,
)
if service_to_event_found.data:
service_to_event_found.destroy(db=db_session)
print(
f"UUID: {service_to_event_found.uu_id} application is deleted from {service_match.service_description}"
)
employee_added_application = Service2Application.find_or_create(
service_id=service_match.id,
service_uu_id=str(service_match.uu_id),
application_id=list_of_event_code.id,
application_uu_id=str(list_of_event_code.uu_id),
application_code=list_of_event_code.application_code,
site_url=list_of_event_code.site_url,
is_confirmed=True,
)
if created_page.meta_data.created:
created_page.save(db=db_session)
application_employee_created = Application2Employee.find_or_create(
employee_id=super_user.id,
employee_uu_id=str(super_user.uu_id),
site_url=created_page.site_url,
application_code=created_page.application_code,
application_id=created_page.id,
application_uu_id=str(created_page.uu_id),
is_confirmed=True,
active=True,
db=db_session,
)
if application_employee_created.meta_data.created:
application_employee_created.save(db=db_session)
if employee_added_application.meta_data.created:
employee_added_application.save(db=db_session)
print(
f"UUID: {employee_added_application.uu_id} application is saved to {service_match.service_description}"
)
def init_applications_for_general_manager(
super_user: Employees, db_session=None
) -> None:
list_of_created_apps = [
dict(
name="Dashboard1",
application_code="app000001",
site_url="/dashboard",
application_type="info",
description="Dashboard Page",
),
dict(
name="ManagementAccounting",
application_code="app000008",
site_url="/management/accounting",
application_type="Dash",
description="Individual Page for management accounting",
),
]
for list_of_created_app in list_of_created_apps:
created_page = Applications.find_or_create(
**list_of_created_app,
db=db_session,
employee_added_service = Application2Employee.find_or_create(
service_id=service_match.id,
service_uu_id=str(service_match.uu_id),
employee_id=employee_match.id,
employee_uu_id=str(employee_match.uu_id),
is_confirmed=True,
db=db_session,
)
if employee_added_service.meta_data.created:
employee_added_service.save(db=db_session)
print(
f"UUID: {employee_added_service.uu_id} service is saved to {employee_match.uu_id}"
)
print("Application : ", created_page)
if created_page.meta_data.created:
created_page.save(db=db_session)
application_employee_created = Application2Employee.find_or_create(
employee_id=super_user.id,
employee_uu_id=str(super_user.uu_id),
site_url=created_page.site_url,
application_code=created_page.application_code,
application_id=created_page.id,
application_uu_id=str(created_page.uu_id),
is_confirmed=True,
db=db_session,
)
print("Application Employee : ", application_employee_created)
if application_employee_created.meta_data.created:
application_employee_created.save(db=db_session)
def init_applications_for_build_manager(
super_user: BuildLivingSpace, db_session=None
) -> None:
list_of_created_apps = []
# def init_applications_for_general_manager(
# super_user: Employees, db_session=None
# ) -> None:
# list_of_created_apps = Applications.filter_all_system(db=db_session).data
# if not list_of_created_apps:
# raise Exception("No applications found")
# for list_of_created_app in list_of_created_apps:
# application_employee_created = Application2Employee.find_or_create(
# employee_id=super_user.id,
# employee_uu_id=str(super_user.uu_id),
# site_url=list_of_created_app.site_url,
# application_code=list_of_created_app.application_code,
# application_id=list_of_created_app.id,
# application_uu_id=str(list_of_created_app.uu_id),
# is_confirmed=True,
# db=db_session,
# )
# if application_employee_created.meta_data.created:
# application_employee_created.save(db=db_session)
def init_applications_for_owner(super_user: BuildLivingSpace, db_session=None) -> None:
pass
# def init_applications_for_build_manager(
# super_user: BuildLivingSpace, db_session=None
# ) -> None:
# list_of_created_apps = Applications.filter_all_system(db=db_session).data
# if not list_of_created_apps:
# raise Exception("No applications found")
# for list_of_created_app in list_of_created_apps:
# application_employee_created = Application2Employee.find_or_create(
# employee_id=super_user.id,
# employee_uu_id=str(super_user.uu_id),
# site_url=list_of_created_app.site_url,
# application_code=list_of_created_app.application_code,
# application_id=list_of_created_app.id,
# application_uu_id=str(list_of_created_app.uu_id),
# is_confirmed=True,
# db=db_session,
# )
# if application_employee_created.meta_data.created:
# application_employee_created.save(db=db_session)
def init_applications_for_tenant(super_user: BuildLivingSpace, db_session=None) -> None:
list_of_created_apps = [
dict(
name="Dashboard1",
application_code="app000001",
site_url="/dashboard",
application_type="info",
description="Dashboard Page",
),
dict(
name="TenantSendMessageToBuildManager",
application_code="app000022",
site_url="/tenant/messageToBM",
application_type="Dash",
description="Individual Page for tenant send message to build manager",
),
dict(
name="TenantSendMessageToOwner",
application_code="app000018",
site_url="/tenant/messageToOwner",
application_type="Dash",
description="Individual Page for tenant send message to owner",
),
dict(
name="TenantAccountView",
application_code="app000019",
site_url="/tenant/accounting",
application_type="Dash",
description="Individual Page for tenant account view",
),
]
# def init_applications_for_owner(super_user: BuildLivingSpace, db_session=None) -> None:
# list_of_created_apps = Applications.filter_all_system(db=db_session).data
# if not list_of_created_apps:
# raise Exception("No applications found")
for list_of_created_app in list_of_created_apps:
created_page = Applications.find_or_create(
**list_of_created_app,
db=db_session,
is_confirmed=True,
)
if created_page.meta_data.created:
created_page.save(db=db_session)
# for list_of_created_app in list_of_created_apps:
# application_employee_created = Application2Employee.find_or_create(
# employee_id=super_user.id,
# employee_uu_id=str(super_user.uu_id),
# site_url=list_of_created_app.site_url,
# application_code=list_of_created_app.application_code,
# application_id=list_of_created_app.id,
# application_uu_id=str(list_of_created_app.uu_id),
# is_confirmed=True,
# db=db_session,
# )
# if application_employee_created.meta_data.created:
# application_employee_created.save(db=db_session)
application_occupant_created = Application2Occupant.find_or_create(
build_living_space_id=super_user.id,
build_living_space_uu_id=str(super_user.uu_id),
site_url=created_page.site_url,
application_code=created_page.application_code,
application_id=created_page.id,
application_uu_id=str(created_page.uu_id),
is_confirmed=True,
db=db_session,
)
if application_occupant_created.meta_data.created:
application_occupant_created.save(db=db_session)
# def init_applications_for_tenant(super_user: BuildLivingSpace, db_session=None) -> None:
# list_of_created_apps = Applications.filter_all_system(db=db_session).data
# if not list_of_created_apps:
# raise Exception("No applications found")
# for list_of_created_app in list_of_created_apps:
# application_employee_created = Application2Employee.find_or_create(
# employee_id=super_user.id,
# employee_uu_id=str(super_user.uu_id),
# site_url=list_of_created_app.site_url,
# application_code=list_of_created_app.application_code,
# application_id=list_of_created_app.id,
# application_uu_id=str(list_of_created_app.uu_id),
# is_confirmed=True,
# db=db_session,
# )
# if application_employee_created.meta_data.created:
# application_employee_created.save(db=db_session)
# list_of_created_apps = [
# dict(
# name="Dashboard1",
# application_code="app000001",
# site_url="/dashboard",
# application_type="info",
# description="Dashboard Page",
# ),
# dict(
# name="TenantSendMessageToBuildManager",
# application_code="app000022",
# site_url="/tenant/messageToBM",
# application_type="Dash",
# description="Individual Page for tenant send message to build manager",
# ),
# dict(
# name="TenantSendMessageToOwner",
# application_code="app000018",
# site_url="/tenant/messageToOwner",
# application_type="Dash",
# description="Individual Page for tenant send message to owner",
# ),
# dict(
# name="TenantAccountView",
# application_code="app000019",
# site_url="/tenant/accounting",
# application_type="Dash",
# description="Individual Page for tenant account view",
# ),
# ]
# for list_of_created_app in list_of_created_apps:
# created_page = Applications.find_or_create(
# **list_of_created_app,
# db=db_session,
# is_confirmed=True,
# )
# if created_page.meta_data.created:
# created_page.save(db=db_session)
# application_occupant_created = Application2Occupant.find_or_create(
# build_living_space_id=super_user.id,
# build_living_space_uu_id=str(super_user.uu_id),
# site_url=created_page.site_url,
# application_code=created_page.application_code,
# application_id=created_page.id,
# application_uu_id=str(created_page.uu_id),
# is_confirmed=True,
# db=db_session,
# )
# if application_occupant_created.meta_data.created:
# application_occupant_created.save(db=db_session)

View File

@@ -11,11 +11,7 @@ from Schemas import (
)
def init_service_to_event_matches_for_super_user(super_user, db_session=None) -> None:
service_match = Services.filter_one(
Services.service_name == "Super User",
db=db_session,
).data
def init_service_to_event_matches_for_super_user(service_match: Services, employee_match: Employees, db_session=None) -> None:
list_of_all_events = Events.filter_all(db=db_session).data
Service2Events.filter_all(db=db_session).query.delete()
Service2Events.save(db=db_session)
@@ -29,10 +25,9 @@ def init_service_to_event_matches_for_super_user(super_user, db_session=None) ->
if service_to_event_found.data:
service_to_event_found.destroy(db=db_session)
print(
f"UUID: {service_to_event_found.uu_id} event is deleted from {service_match.uu_id}"
f"UUID: {service_to_event_found.uu_id} event is deleted from {service_match.service_description}"
)
created_service = Service2Events.find_or_create(
added_service = Service2Events.find_or_create(
service_id=service_match.id,
service_uu_id=str(service_match.uu_id),
event_id=list_of_event_code.id,
@@ -41,23 +36,22 @@ def init_service_to_event_matches_for_super_user(super_user, db_session=None) ->
active=True,
db=db_session,
)
if created_service.meta_data.created:
created_service.save(db=db_session)
if added_service.meta_data.created:
added_service.save(db=db_session)
print(
f"UUID: {created_service.uu_id} event is saved to {service_match.uu_id}"
f"UUID: {added_service.uu_id} event is saved to {service_match.service_description}"
)
employee_added_service = Event2Employee.find_or_create(
event_service_id=service_match.id,
event_service_uu_id=str(service_match.uu_id),
employee_id=super_user.id,
employee_uu_id=str(super_user.uu_id),
is_confirmed=True,
db=db_session,
employee_added_service = Event2Employee.find_or_create(
event_service_id=service_match.id,
event_service_uu_id=str(service_match.uu_id),
employee_id=employee_match.id,
employee_uu_id=str(employee_match.uu_id),
is_confirmed=True,
db=db_session,
)
if employee_added_service.meta_data.created:
employee_added_service.save(db=db_session)
print(
f"UUID: {employee_added_service.uu_id} event is saved to employee {employee_match.uu_id}"
)
if employee_added_service.meta_data.created:
employee_added_service.save(db=db_session)
print(
f"UUID: {employee_added_service.uu_id} event is saved to {super_user.uu_id}"
)