import arrow from Modules.Token.password_module import PasswordModule from Controllers.Mongo.database import mongo_handler def create_application_defaults(db_session): from Schemas import ( Companies, Departments, Duty, Duties, Employees, People, Users, Staff, RelationshipDutyCompany, ) created_list = [] created_by, confirmed_by = "System", "System" company_management = Companies.find_or_create( **{ "formal_name": "Evyos LTD", "public_name": "Evyos Verimlilik Sistemleri", "company_type": "LTD", "commercial_type": "Commercial", "tax_no": "123132123132", "company_tag": "Evyos", "default_lang_type": "TR", "default_money_type": "TL", "is_commercial": True, "is_confirmed": True, }, db=db_session, ) created_list.append(company_management) active_row = dict( is_confirmed=True, active=True, deleted=False, is_notification_send=True ) company_id, company_uu_id = company_management.id, str(company_management.uu_id) created_list = [] execution = Departments.find_or_create( department_name="Execution Office", department_code="EO001", company_id=company_id, company_uu_id=str(company_uu_id), **active_row, db=db_session, ) created_list.append(execution) gen_man = Departments.find_or_create( department_name="General Manager Example", department_code="GM001", company_id=company_id, company_uu_id=str(company_uu_id), **active_row, db=db_session, ) created_list.append(gen_man) it_dept = Departments.find_or_create( department_name="IT Department", department_code="ITD001", company_id=company_id, company_uu_id=str(company_uu_id), **active_row, db=db_session, ) created_list.append(it_dept) gen_duty = Duty.find_or_create( duty_name="General Manager", duty_code="GM0001", duty_description="General Manager", **active_row, db=db_session, ) created_list.append(gen_duty) bm_duty = Duty.find_or_create( duty_name="Business Manager", duty_code="BM0001", duty_description="Business Manager", **active_row, db=db_session, ) created_list.append(bm_duty) it_duty = Duty.find_or_create( duty_name="IT Manager", duty_code="IT0001", duty_description="IT Manager", **active_row, db=db_session, ) created_list.append(it_duty) bulk_duty = Duty.find_or_create( duty_name="BULK", duty_code="BULK", duty_description="BULK RECORDS OF THE COMPANY", **active_row, db=db_session, ) created_list.append(bulk_duty) occu_duty = Duty.find_or_create( duty_name="OCCUPANT", duty_code="OCCUPANT", duty_description="OCCUPANT RECORDS OF THE COMPANY", **active_row, db=db_session, ) created_list.append(occu_duty) duties_gen_man = Duties.find_or_create( company_id=company_id, company_uu_id=str(company_uu_id), duties_id=gen_duty.id, duties_uu_id=str(gen_duty.uu_id), department_id=gen_man.id, department_uu_id=str(gen_man.uu_id), **active_row, db=db_session, ) created_list.append(duties_gen_man) duties_created_bm = Duties.find_or_create( company_id=company_id, company_uu_id=str(company_uu_id), duties_id=bm_duty.id, duties_uu_id=str(bm_duty.uu_id), department_id=execution.id, department_uu_id=str(execution.uu_id), **active_row, db=db_session, ) created_list.append(duties_created_bm) duties_created_it = Duties.find_or_create( company_id=company_id, company_uu_id=str(company_uu_id), duties_id=it_duty.id, duties_uu_id=str(it_duty.uu_id), department_id=it_dept.id, department_uu_id=str(it_dept.uu_id), **active_row, db=db_session, ) created_list.append(duties_created_it) duties_created__ex = Duties.find_or_create( company_id=company_id, company_uu_id=str(company_uu_id), duties_id=bulk_duty.id, duties_uu_id=str(bulk_duty.uu_id), department_id=execution.id, department_uu_id=str(execution.uu_id), **active_row, db=db_session, ) created_list.append(duties_created__ex) duties_created_at = Duties.find_or_create( company_id=company_id, company_uu_id=str(company_uu_id), duties_id=occu_duty.id, duties_uu_id=str(occu_duty.uu_id), department_id=execution.id, department_uu_id=str(execution.uu_id), **active_row, db=db_session, ) created_list.append(duties_created_at) bulk_duty = Duty.filter_by_one(system=True, duty_code="BULK", db=db_session).data it_dept = Departments.filter_by_one( system=True, department_name="IT Department", department_code="ITD001", company_id=company_management.id, company_uu_id=str(company_management.uu_id), db=db_session, ).data created_duty = Duty.find_or_create( duty_name="Database Manager", duty_code="DM", duty_description="Database Manager", created_by=created_by, confirmed_by=confirmed_by, is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(created_duty) created_duty = Duty.find_or_create( duty_name="Network Manager", duty_code="NM", duty_description="Network Manager", created_by=created_by, confirmed_by=confirmed_by, is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(created_duty) application_manager_duty = Duty.find_or_create( duty_name="Application Manager", duty_code="AM", duty_description="Application Manager", created_by=created_by, confirmed_by=confirmed_by, is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(application_manager_duty) application_super_user_duty = Duty.find_or_create( duty_name="Super User", duty_code="SUE", duty_description="Super User", created_by=created_by, confirmed_by=confirmed_by, is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(application_super_user_duty) application_manager_duties = Duties.find_or_create( department_id=it_dept.id, department_uu_id=str(it_dept.uu_id), duties_id=application_manager_duty.id, duties_uu_id=str(application_manager_duty.uu_id), company_id=company_management.id, company_uu_id=str(company_management.uu_id), is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(application_manager_duties) super_user_duties = Duties.find_or_create( department_id=it_dept.id, department_uu_id=str(it_dept.uu_id), duties_id=application_super_user_duty.id, duties_uu_id=str(application_manager_duty.uu_id), company_id=company_management.id, company_uu_id=str(company_management.uu_id), is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(super_user_duties) RelationshipDutyCompany.find_or_create( duties_id=application_manager_duties.id, owner_id=company_management.id, member_id=company_management.id, parent_id=None, child_count=0, is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(application_manager_duties) RelationshipDutyCompany.find_or_create( duties_id=super_user_duties.id, owner_id=company_management.id, member_id=company_management.id, parent_id=None, child_count=0, is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(super_user_duties) app_manager = People.find_or_create( **{ "person_tag": "BAM-System", "firstname": "Berkay Application Manager", "surname": "Karatay", "sex_code": "M", "middle_name": "", "father_name": "Father", "mother_name": "Mother", "country_code": "TR", "national_identity_id": "12312312312", "birth_place": "Ankara", "birth_date": "01.07.1990", "tax_no": "1231231231", "is_confirmed": True, }, db=db_session, ) created_list.append(app_manager) sup_manager = People.find_or_create( **{ "person_tag": "BSU-System", "firstname": "Berkay Super User", "surname": "Karatay", "sex_code": "M", "middle_name": "", "father_name": "Father", "mother_name": "Mother", "country_code": "TR", "national_identity_id": "12312312313", "birth_place": "Ankara", "birth_date": "01.07.1990", "tax_no": "1231231232", }, db=db_session, ) created_list.append(sup_manager) gen_manager_people = People.find_or_create( **{ "person_tag": "BM-System", "firstname": "Example General Manager", "surname": "Example", "sex_code": "M", "middle_name": "", "father_name": "Father", "mother_name": "Mother", "country_code": "TR", "national_identity_id": "12312312314", "birth_place": "Ankara", "birth_date": "01.07.1990", "tax_no": "1231231233", }, db=db_session, ) created_list.append(gen_manager_people) application_manager_staff = Staff.find_or_create( staff_description="Application Manager", staff_name="Application Manager Employee", staff_code="AME", duties_id=application_manager_duties.id, duties_uu_id=str(application_manager_duty.uu_id), is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(application_manager_staff) super_user_staff = Staff.find_or_create( staff_description="Super User", staff_name="Super User Employee", staff_code="SUE", duties_id=super_user_duties.id, duties_uu_id=str(application_manager_duty.uu_id), is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(super_user_staff) gen_man_staff = Staff.find_or_create( staff_description="General Manager", staff_name="General Manager Employee", staff_code="GME", duties_id=duties_gen_man.id, duties_uu_id=str(gen_duty.uu_id), is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(gen_man_staff) gen_man_employee = Employees.find_or_create( staff_id=gen_man_staff.id, staff_uu_id=str(gen_man_staff.uu_id), people_id=gen_manager_people.id, people_uu_id=str(gen_manager_people.uu_id), is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(gen_man_employee) app_manager_employee = Employees.find_or_create( staff_id=application_manager_staff.id, staff_uu_id=str(application_manager_staff.uu_id), people_id=app_manager.id, people_uu_id=str(app_manager.uu_id), is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(app_manager_employee) super_user_employee = Employees.find_or_create( staff_id=super_user_staff.id, staff_uu_id=str(super_user_staff.uu_id), people_id=sup_manager.id, people_uu_id=str(sup_manager.uu_id), is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(super_user_employee) gen_manager_user = Users.find_or_create( person_id=gen_manager_people.id, person_uu_id=str(gen_manager_people.uu_id), user_tag=gen_manager_people.person_tag, email="example.general@evyos.com.tr", phone_number="+901111111111", avatar="https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg", related_company=str(company_management.uu_id), is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(gen_manager_user) gen_manager_user.password_expiry_begins = str(arrow.now()) gen_manager_user.password_token = PasswordModule.generate_refresher_token() main_domain, collection_name = ( "evyos.com.tr", f"{str(company_management.uu_id)}*Domain", ) with mongo_handler.collection(collection_name) as mongo_engine: mongo_engine.insert_one( document={ "user_uu_id": str(gen_manager_user.uu_id), "other_domains_list": [main_domain], "main_domain": main_domain, "modified_at": arrow.now().timestamp(), } ) app_manager_user = Users.find_or_create( person_id=app_manager.id, person_uu_id=str(app_manager.uu_id), user_tag=app_manager.person_tag, email="karatay.berkay.man@evyos.com.tr", phone_number="+901111111111", avatar="https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg", related_company=str(company_management.uu_id), is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(app_manager_user) app_manager_user.password_expiry_begins = str(arrow.now()) app_manager_user.password_token = PasswordModule.generate_refresher_token() with mongo_handler.collection(collection_name) as mongo_engine: mongo_engine.insert_one( document={ "user_uu_id": str(app_manager_user.uu_id), "other_domains_list": [main_domain], "main_domain": main_domain, "modified_at": arrow.now().timestamp(), } ) sup_manager_employee = Users.find_or_create( person_id=sup_manager.id, person_uu_id=str(sup_manager.uu_id), user_tag=sup_manager.person_tag, email="karatay.berkay.sup@evyos.com.tr", phone_number="+901111111112", avatar="https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg", created_by=created_by, confirmed_by=confirmed_by, related_company=str(company_management.uu_id), is_confirmed=True, active=True, deleted=False, is_notification_send=True, db=db_session, ) created_list.append(sup_manager_employee) sup_manager_employee.password_expiry_begins = str(arrow.now()) sup_manager_employee.password_token = PasswordModule.generate_refresher_token() with mongo_handler.collection(collection_name) as mongo_engine: mongo_engine.insert_one( document={ "user_uu_id": str(sup_manager_employee.uu_id), "other_domains_list": [main_domain], "main_domain": main_domain, "modified_at": arrow.now().timestamp(), } ) db_session.commit() print("All Defaults Create is now completed")