initializer service deployed and tested

This commit is contained in:
2025-05-12 17:42:33 +03:00
parent 834c78d814
commit 1d4f00e8b2
96 changed files with 11881 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
1. endpoint uuid must be imported from a common folder
2. authservice must be seperated from application checkers service even though it serves values from redis
3. Initial services are not functioning well enough
4. ApiResponse and SystemResponse must be seperated
5.

View File

@@ -0,0 +1,28 @@
FROM python:3.12-slim
WORKDIR /
# Install system dependencies and Poetry
RUN apt-get update && apt-get install -y --no-install-recommends gcc && rm -rf /var/lib/apt/lists/* && pip install --no-cache-dir poetry
# Copy Poetry configuration
COPY /pyproject.toml ./pyproject.toml
# Configure Poetry and install dependencies with optimizations
RUN poetry config virtualenvs.create false && poetry install --no-interaction --no-ansi --no-root --only main && pip cache purge && rm -rf ~/.cache/pypoetry
# Copy application code
COPY /api_services/api_initializer /api_initializer
COPY /api_services/api_controllers /api_controllers
COPY /api_services/schemas /schemas
COPY /api_services/api_middlewares /middlewares
COPY /api_services/api_builds/auth-service/endpoints /api_initializer/endpoints
COPY /api_services/api_builds/auth-service/events /api_initializer/events
COPY /api_services/api_builds/auth-service/validations /api_initializer/validations
# Set Python path to include app directory
ENV PYTHONPATH=/ PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
# Run the application using the configured uvicorn server
CMD ["poetry", "run", "python", "/api_initializer/app.py"]

View File

@@ -0,0 +1,3 @@
__all__ = []

View File

@@ -0,0 +1,9 @@
endpoints_index: dict = {
"Name": "d538deb4-38f4-4913-a1af-bbef14cf6873",
"Slot1": "c0f5ccb1-1e56-4653-af13-ec0bf5e6aa51",
"Slot2": "034a7eb7-0186-4f48-bb8c-165c429ad5c1",
"Slot3": "ec1f3ec3-3f28-4eaf-b89a-c463632c0b90",
"Slot4": "2cf99f10-72f0-4c2b-98be-3082d67b950d",
"Slot5": "15c24c6c-651b-4c5d-9c2b-5c6c6c6c6c6c",
}

View File

@@ -0,0 +1,15 @@
from fastapi import APIRouter
def get_routes() -> list[APIRouter]:
return []
def get_safe_endpoint_urls() -> list[tuple[str, str]]:
return [
("/", "GET"),
("/docs", "GET"),
("/redoc", "GET"),
("/openapi.json", "GET"),
("/metrics", "GET"),
]

View File

@@ -0,0 +1,3 @@
__all__ = []

View File

@@ -0,0 +1,10 @@
events_index: dict = {
"Slot1": "",
"Slot2": "",
"Slot3": "",
"Slot4": "",
"Slot5": "",
}

View File

@@ -0,0 +1,25 @@
FROM python:3.12-slim
WORKDIR /
# Install system dependencies and Poetry
RUN apt-get update && apt-get install -y --no-install-recommends gcc && rm -rf /var/lib/apt/lists/* && pip install --no-cache-dir poetry
# Copy Poetry configuration
COPY /pyproject.toml ./pyproject.toml
# Configure Poetry and install dependencies with optimizations
RUN poetry config virtualenvs.create false && poetry install --no-interaction --no-ansi --no-root --only main && pip cache purge && rm -rf ~/.cache/pypoetry
# Copy application code
COPY /api_services/api_controllers /api_controllers
COPY /api_services/schemas /schemas
COPY /api_services/api_builds/initial-service /initial-service
COPY /api_services/api_builds/initial-service /
# Set Python path to include app directory
ENV PYTHONPATH=/ PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
# Run the application using the configured uvicorn server
CMD ["poetry", "run", "python", "initial-service/app.py"]

View File

@@ -0,0 +1,119 @@
# A generic, single database configuration.
[alembic]
# path to migration scripts
# Use forward slashes (/) also on windows to provide an os agnostic path
script_location = alembic
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
# for all available tokens
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
# sys.path path, will be prepended to sys.path if present.
# defaults to the current working directory.
prepend_sys_path = .
# timezone to use when rendering the date within the migration file
# as well as the filename.
# If specified, requires the python>=3.9 or backports.zoneinfo library and tzdata library.
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
# string value is passed to ZoneInfo()
# leave blank for localtime
# timezone =
# max length of characters to apply to the "slug" field
# truncate_slug_length = 40
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false
# version location specification; This defaults
# to alembic/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "version_path_separator" below.
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions
# version path separator; As mentioned above, this is the character used to split
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
# Valid values for version_path_separator are:
#
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
# version_path_separator = newline
#
# Use os.pathsep. Default configuration used for new projects.
version_path_separator = os
# set to 'true' to search source files recursively
# in each "version_locations" directory
# new in Alembic version 1.10
# recursive_version_locations = false
# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8
sqlalchemy.url = postgresql+psycopg2://postgres:password@10.10.2.14:5432/postgres
[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples
# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks = black
# black.type = console_scripts
# black.entrypoint = black
# black.options = -l 79 REVISION_SCRIPT_FILENAME
# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
# hooks = ruff
# ruff.type = exec
# ruff.executable = %(here)s/.venv/bin/ruff
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARNING
handlers = console
qualname =
[logger_sqlalchemy]
level = WARNING
handlers =
qualname = sqlalchemy.engine
[logger_alembic]
level = INFO
handlers =
qualname = alembic
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S

View File

@@ -0,0 +1 @@
Generic single-database configuration.

View File

@@ -0,0 +1,89 @@
import os
from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from sqlalchemy import create_engine
from alembic import context
from schemas import *
from api_controllers.postgres.engine import Base
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Override sqlalchemy.url with environment variables if they exist
db_host = os.getenv("POSTGRES_HOST", None)
db_port = os.getenv("POSTGRES_PORT", None)
db_user = os.getenv("POSTGRES_USER", None)
db_password = os.getenv("POSTGRES_PASSWORD", None)
db_name = os.getenv("POSTGRES_DB", None)
# Build the connection URL from environment variables
db_url = f"postgresql+psycopg2://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}"
# Override the sqlalchemy.url in the alembic.ini file
config.set_main_option("sqlalchemy.url", db_url)
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
target_metadata = Base.metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online() -> None:
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

View File

@@ -0,0 +1,28 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision: str = ${repr(up_revision)}
down_revision: Union[str, None] = ${repr(down_revision)}
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
def upgrade() -> None:
"""Upgrade schema."""
${upgrades if upgrades else "pass"}
def downgrade() -> None:
"""Downgrade schema."""
${downgrades if downgrades else "pass"}

View File

@@ -0,0 +1,43 @@
import os
from api_controllers.postgres.engine import get_db
from init_app_defaults import create_application_defaults
from init_enums import init_api_enums_build_types
from init_alembic import generate_alembic
from init_occupant_types import create_occupant_types_defaults
from init_services import create_modules_and_services_and_actions
from init_address import create_one_address
from init_occ_defaults import create_occupant_defaults
set_alembic = bool(int(os.getenv("SET_ALEMBIC"), 0))
if __name__ == "__main__":
print(f"Set alembic: {set_alembic}")
with get_db() as db_session:
if set_alembic:
generate_alembic(session=db_session)
try:
create_one_address(db_session=db_session)
except Exception as e:
print(f"Error creating address: {e}")
try:
init_api_enums_build_types(db_session=db_session)
except Exception as e:
print(f"Error creating enums: {e}")
try:
create_application_defaults(db_session=db_session)
except Exception as e:
print(f"Error creating application defaults: {e}")
try:
create_occupant_types_defaults(db_session=db_session)
except Exception as e:
print(f"Error creating occupant types defaults: {e}")
try:
create_modules_and_services_and_actions(db_session=db_session)
except Exception as e:
print(f"Error creating modules and services and actions: {e}")
try:
create_occupant_defaults(db_session=db_session)
except Exception as e:
print(f"Error creating occupant defaults: {e}")

View File

@@ -0,0 +1,144 @@
from schemas import (
Addresses,
AddressCity,
AddressStreet,
AddressLocality,
AddressDistrict,
AddressNeighborhood,
AddressState,
AddressCountry,
)
def create_one_address(db_session):
address_list = []
AddressCountry.set_session(db_session)
country = AddressCountry.query.filter_by(country_name="TÜRKİYE", country_code="TR").first()
if not country:
country = AddressCountry.create(
country_name="TÜRKİYE", country_code="TR", is_confirmed=True
)
country.save()
address_list.append(country)
else:
print(f"Country already exists {country.to_dict()}")
AddressState.set_session(db_session)
state = AddressState.query.filter_by(state_name="TÜRKİYE", state_code="TR").first()
if not state:
state = AddressState.create(
state_name="TÜRKİYE",
state_code="TR",
phone_code="90",
country_id=country.id,
country_uu_id=str(country.uu_id),
is_confirmed=True,
)
state.save()
address_list.append(state)
else:
print(f"State already exists {state.to_dict()}")
AddressCity.set_session(db_session)
city = AddressCity.query.filter_by(city_name="ANKARA", city_code="6").first()
if not city:
city = AddressCity.create(
city_name="ANKARA",
city_code="6",
licence_plate="06",
state_id=state.id,
state_uu_id=str(state.uu_id),
is_confirmed=True,
)
city.save()
address_list.append(city)
else:
print(f"City already exists {city.to_dict()}")
AddressDistrict.set_session(db_session)
district = AddressDistrict.query.filter_by(district_name="ÇANKAYA", district_code="1231").first()
if not district:
district = AddressDistrict.create(
district_name="ÇANKAYA",
district_code="1231",
city_id=city.id,
city_uu_id=str(city.uu_id),
is_confirmed=True,
)
district.save()
address_list.append(district)
else:
print(f"District already exists {district.to_dict()}")
AddressLocality.set_session(db_session)
locality = AddressLocality.query.filter_by(locality_name="MERKEZ", locality_code="2431").first()
if not locality:
locality = AddressLocality.create(
locality_name="MERKEZ",
locality_code="2431",
type_code="3",
type_description=None,
district_id=district.id,
district_uu_id=str(district.uu_id),
is_confirmed=True,
)
locality.save()
address_list.append(locality)
else:
print(f"Locality already exists {locality.to_dict()}")
AddressNeighborhood.set_session(db_session)
neighborhood = AddressNeighborhood.query.filter_by(neighborhood_name="AYRANCI MAHALLESİ", neighborhood_code="1522").first()
if not neighborhood:
neighborhood = AddressNeighborhood.create(
neighborhood_name="AYRANCI MAHALLESİ",
neighborhood_code="1522",
type_code="1",
type_description="MAHALLESİ",
locality_id=locality.id,
locality_uu_id=str(locality.uu_id),
is_confirmed=True,
)
neighborhood.save()
address_list.append(neighborhood)
else:
print(f"Neighborhood already exists {neighborhood.to_dict()}")
AddressStreet.set_session(db_session)
street = AddressStreet.query.filter_by(street_name="REŞAT NURİ CADDESİ", street_code="52270").first()
if not street:
street = AddressStreet.create(
street_name="REŞAT NURİ CADDESİ",
type_description="CADDESİ",
type_code="3",
street_code="52270",
neighborhood_id=neighborhood.id,
neighborhood_uu_id=str(neighborhood.uu_id),
is_confirmed=True,
)
street.save()
address_list.append(street)
else:
print(f"Street already exists {street.to_dict()}")
Addresses.set_session(db_session)
address = Addresses.query.filter_by(street_id=street.id, street_uu_id=str(street.uu_id)).first()
if not address:
address = Addresses.create(
street_id=street.id,
street_uu_id=str(street.uu_id),
build_number="Ex1",
door_number="1",
floor_number="1",
comment_address="Example Address",
letter_address="Example Address",
short_letter_address="Example Address",
latitude=0,
longitude=0,
is_confirmed=True,
)
address.save()
address_list.append(address)
else:
print(f"Address already exists {address.to_dict()}")

View File

@@ -0,0 +1,23 @@
import os
from sqlalchemy import text
def generate_alembic(session):
try:
result = session.execute(
text(
"SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = "
"'alembic_version') AS table_existence;"
)
)
if result.first()[0]:
session.execute(text("delete from alembic_version;"))
session.commit()
except Exception as e:
print(e)
finally:
run_command = "python -m alembic stamp head;"
run_command += (
"python -m alembic revision --autogenerate;python -m alembic upgrade head;"
)
os.system(run_command)

View File

@@ -0,0 +1,660 @@
import arrow
from modules.Token.password_module import PasswordModule
from api_controllers.mongo.database import mongo_handler
from schemas import (
Companies,
Departments,
Duty,
Duties,
Employees,
People,
Users,
Staff,
RelationshipDutyCompany,
)
def create_application_defaults(db_session):
created_list, created_by, confirmed_by = [], "System", "System"
active_row = dict(is_confirmed=True, active=True, deleted=False, is_notification_send=True)
Companies.set_session(db_session)
Departments.set_session(db_session)
Duties.set_session(db_session)
Duty.set_session(db_session)
Staff.set_session(db_session)
People.set_session(db_session)
Users.set_session(db_session)
Employees.set_session(db_session)
RelationshipDutyCompany.set_session(db_session)
company_management = Companies.query.filter_by(company_tag="Evyos",).first()
if not company_management:
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,
}
)
created_list.append(company_management)
else:
print(f"Company Management Found {company_management.to_dict()}")
company_id, company_uu_id = company_management.id, str(company_management.uu_id)
execution = Departments.query.filter_by(department_code="EO001", company_id=company_id).first()
if not execution:
execution = Departments.create(
department_name="Execution Office",
department_code="EO001",
company_id=company_id,
company_uu_id=str(company_uu_id),
**active_row,
)
created_list.append(execution)
else:
print(f"Execution Found {execution.to_dict()}")
gen_man = Departments.query.filter_by(department_code="GM001", company_id=company_id).first()
if not gen_man:
gen_man = Departments.create(
department_name="General Manager Example",
department_code="GM001",
company_id=company_id,
company_uu_id=str(company_uu_id),
**active_row,
)
created_list.append(gen_man)
else:
print(f"General Manager Found {gen_man.to_dict()}")
it_dept = Departments.query.filter_by(department_code="ITD001", company_id=company_id).first()
if not it_dept:
it_dept = Departments.create(
department_name="IT Department",
department_code="ITD001",
company_id=company_id,
company_uu_id=str(company_uu_id),
**active_row,
)
created_list.append(it_dept)
else:
print(f"IT Department Found {it_dept.to_dict()}")
gen_duty = Duty.query.filter_by(duty_code="GM0001").first()
if not gen_duty:
gen_duty = Duty.create(
duty_name="General Manager",
duty_code="GM0001",
duty_description="General Manager",
**active_row,
)
created_list.append(gen_duty)
else:
print(f"General Manager Found {gen_duty.to_dict()}")
bm_duty = Duty.query.filter_by(duty_code="BM0001").first()
if not bm_duty:
bm_duty = Duty.create(
duty_name="Business Manager",
duty_code="BM0001",
duty_description="Business Manager",
**active_row,
)
created_list.append(bm_duty)
else:
print(f"Business Manager Found {bm_duty.to_dict()}")
it_duty = Duty.query.filter_by(duty_code="IT0001").first()
if not it_duty:
it_duty = Duty.create(
duty_name="IT Manager",
duty_code="IT0001",
duty_description="IT Manager",
**active_row,
)
created_list.append(it_duty)
else:
print(f"IT Manager Found {it_duty.to_dict()}")
bulk_duty = Duty.query.filter_by(duty_code="BULK").first()
if not bulk_duty:
bulk_duty = Duty.create(
duty_name="BULK",
duty_code="BULK",
duty_description="BULK RECORDS OF THE COMPANY",
**active_row,
)
created_list.append(bulk_duty)
else:
print(f"Bulk Duty Found {bulk_duty.to_dict()}")
occu_duty = Duty.query.filter_by(duty_code="OCCUPANT").first()
if not occu_duty:
occu_duty = Duty.create(
duty_name="OCCUPANT",
duty_code="OCCUPANT",
duty_description="OCCUPANT RECORDS OF THE COMPANY",
**active_row,
)
created_list.append(occu_duty)
else:
print(f"Occupant Duty Found {occu_duty.to_dict()}")
duties_gen_man = Duties.query.filter_by(company_id=company_id, duties_id=gen_duty.id, department_id=gen_man.id).first()
if not duties_gen_man:
duties_gen_man = Duties.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,
)
created_list.append(duties_gen_man)
else:
print(f"Duties General Manager Found {duties_gen_man.to_dict()}")
duties_created_bm = Duties.query.filter_by(company_id=company_id, duties_id=bm_duty.id, department_id=execution.id).first()
if not duties_created_bm:
duties_created_bm = Duties.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,
)
created_list.append(duties_created_bm)
else:
print(f"Duties Business Manager Found {duties_created_bm.to_dict()}")
duties_created_it = Duties.query.filter_by(company_id=company_id, duties_id=bulk_duty.id, department_id=execution.id).first()
if not duties_created_it:
duties_created_it = Duties.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,
)
created_list.append(duties_created_it)
else:
print(f"Duties Bulk Found {duties_created_it.to_dict()}")
duties_created_occupant = Duties.query.filter_by(company_id=company_id, duties_id=occu_duty.id, department_id=execution.id).first()
if not duties_created_occupant:
duties_created_occupant = Duties.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,
)
created_list.append(duties_created_occupant)
else:
print(f"Duties Occupant Found {duties_created_occupant.to_dict()}")
bulk_duty = Duty.query.filter_by(duty_code="BULK").first()
if not bulk_duty:
bulk_duty = Duty.create(
duty_name="BULK",
duty_code="BULK",
duty_description="BULK RECORDS OF THE COMPANY",
**active_row,
)
created_list.append(bulk_duty)
else:
print(f"Bulk Duty Found {bulk_duty.to_dict()}")
it_dept = Departments.query.filter_by(department_code="ITD001", company_id=company_id).first()
if not it_dept:
it_dept = Departments.create(
department_name="IT Department",
department_code="ITD001",
company_id=company_id,
company_uu_id=str(company_uu_id),
**active_row,
)
created_list.append(it_dept)
else:
print(f"IT Department Found {it_dept.to_dict()}")
created_duty = Duty.query.filter_by(duty_code="DM").first()
if not created_duty:
created_duty = Duty.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,
)
created_list.append(created_duty)
created_duty = Duty.query.filter_by(duty_code="NM").first()
if not created_duty:
created_duty = Duty.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,
)
created_list.append(created_duty)
application_manager_duty = Duty.query.filter_by(duty_code="AM").first()
if not application_manager_duty:
application_manager_duty = Duty.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,
)
created_list.append(application_manager_duty)
application_super_user_duty = Duty.query.filter_by(duty_code="SUE").first()
if not application_super_user_duty:
application_super_user_duty = Duty.create(
duty_name="Super User",
duty_code="SUE",
duty_description="Super User",
created_by=created_by,
confirmed_by=confirmed_by,
**active_row,
)
created_list.append(application_super_user_duty)
application_manager_duties = Duties.query.filter_by(
department_id=it_dept.id,
duties_id=application_manager_duty.id,
company_id=company_id,
).first()
if not application_manager_duties:
application_manager_duties = Duties.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_id,
company_uu_id=str(company_uu_id),
**active_row,
)
created_list.append(application_manager_duties)
else:
print(f"Application Manager Duties Found {application_manager_duties.to_dict()}")
super_user_duties = Duties.query.filter_by(
department_id=it_dept.id,
duties_id=application_super_user_duty.id,
company_id=company_id,
).first()
if not super_user_duties:
super_user_duties = Duties.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_id,
company_uu_id=str(company_uu_id),
**active_row,
)
created_list.append(super_user_duties)
else:
print(f"Super User Duties Found {super_user_duties.to_dict()}")
relation_super_user_duties = RelationshipDutyCompany.query.filter_by(
duties_id=super_user_duties.id,
owner_id=company_id,
member_id=company_id,
).first()
if not relation_super_user_duties:
relation_super_user_duties = RelationshipDutyCompany.create(
duties_id=super_user_duties.id,
owner_id=company_id,
member_id=company_id,
parent_id=None,
child_count=0,
**active_row,
)
created_list.append(super_user_duties)
relation_application_manager_duties = RelationshipDutyCompany.query.filter_by(
duties_id=application_manager_duties.id,
owner_id=company_id,
member_id=company_id,
).first()
if not relation_application_manager_duties:
relation_application_manager_duties = RelationshipDutyCompany.create(
duties_id=application_manager_duties.id,
owner_id=company_id,
member_id=company_id,
parent_id=None,
child_count=0,
**active_row,
)
created_list.append(relation_application_manager_duties)
app_manager = People.query.filter_by(
person_tag="BAM-System",
).first()
if not app_manager:
app_manager = People.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",
**active_row,
},
)
created_list.append(app_manager)
else:
print(f"Application Manager Found {app_manager.to_dict()}")
sup_manager = People.query.filter_by(person_tag="BSU-System").first()
if not sup_manager:
sup_manager = People.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",
**active_row,
},
)
created_list.append(sup_manager)
else:
print(f"Super User Found {sup_manager.to_dict()}")
gen_manager_people = People.query.filter_by(person_tag="BM-System").first()
if not gen_manager_people:
gen_manager_people = People.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",
**active_row,
},
)
created_list.append(gen_manager_people)
else:
print(f"General Manager Found {gen_manager_people.to_dict()}")
application_manager_staff = Staff.query.filter_by(staff_code="AME", duties_id=application_manager_duties.id).first()
if not application_manager_staff:
application_manager_staff = Staff.create(
**{
"staff_code": "AME",
"staff_name": "Application Manager Employee",
"staff_description": "Application Manager Employee",
"duties_id": application_manager_duties.id,
"duties_uu_id": str(application_manager_duty.uu_id),
**active_row,
},
)
created_list.append(application_manager_staff)
else:
print(f"Application Manager Found {application_manager_staff.to_dict()}")
super_user_staff = Staff.query.filter_by(staff_code="SUE", duties_id=super_user_duties.id).first()
if not super_user_staff:
super_user_staff = Staff.create(
**{
"staff_code": "SUE",
"staff_name": "Super User Employee",
"staff_description": "Super User Employee",
"duties_id": super_user_duties.id,
"duties_uu_id": str(super_user_duties.uu_id),
**active_row,
},
)
created_list.append(super_user_staff)
else:
print(f"Super User Found {super_user_staff.to_dict()}")
gen_manager_staff = Staff.query.filter_by(staff_code="GME", duties_id=duties_gen_man.id).first()
if not gen_manager_staff:
gen_manager_staff = Staff.create(
**{
"staff_code": "GME",
"staff_name": "General Manager Employee",
"staff_description": "General Manager Employee",
"duties_id": duties_gen_man.id,
"duties_uu_id": str(duties_gen_man.uu_id),
**active_row,
},
)
created_list.append(gen_manager_staff)
else:
print(f"General Manager Found {gen_manager_staff.to_dict()}")
application_manager_staff = Staff.query.filter_by(staff_code="AME", duties_id=application_manager_duty.id).first()
if not application_manager_staff:
application_manager_staff = Staff.create(
**{
"staff_code": "AME",
"staff_name": "Application Manager Employee",
"staff_description": "Application Manager Employee",
"duties_id": application_manager_duty.id,
"duties_uu_id": str(application_manager_duty.uu_id),
**active_row,
},
)
created_list.append(application_manager_staff)
gen_man_staff = Staff.query.filter_by(staff_code="GME", duties_id=duties_gen_man.id).first()
if not gen_man_staff:
gen_man_staff = Staff.create(
**{
"staff_code": "GME",
"staff_name": "General Manager Employee",
"staff_description": "General Manager Employee",
"duties_id": duties_gen_man.id,
"duties_uu_id": str(gen_duty.uu_id),
**active_row,
},
)
created_list.append(gen_man_staff)
gen_man_employee = Employees.query.filter_by(staff_id=gen_man_staff.id, people_id=gen_manager_people.id).first()
if not gen_man_employee:
gen_man_employee = Employees.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),
**active_row,
)
created_list.append(gen_man_employee)
app_manager_employee = Employees.query.filter_by(staff_id=application_manager_staff.id, people_id=app_manager.id).first()
if not app_manager_employee:
app_manager_employee = Employees.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),
**active_row,
)
created_list.append(app_manager_employee)
super_user_employee = Employees.query.filter_by(staff_id=super_user_staff.id, people_id=sup_manager.id).first()
if not super_user_employee:
super_user_employee = Employees.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),
**active_row,
)
created_list.append(super_user_employee)
gen_manager_user = Users.query.filter_by(person_id=gen_manager_people.id, user_tag=gen_manager_people.person_tag).first()
if not gen_manager_user:
gen_manager_user = Users.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),
**active_row,
)
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:
existing_record = mongo_engine.find_one(
{"user_uu_id": str(gen_manager_user.uu_id)}
)
if not existing_record:
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(),
}
)
else:
mongo_engine.update_one(
{"user_uu_id": str(gen_manager_user.uu_id)},
{
"$set": {
"other_domains_list": [main_domain],
"main_domain": main_domain,
"modified_at": arrow.now().timestamp(),
}
},
)
app_manager_user = Users.query.filter_by(person_id=app_manager.id, user_tag=app_manager.person_tag).first()
if not app_manager_user:
app_manager_user = Users.create(
person_id=app_manager.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),
**active_row,
)
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:
existing_record = mongo_engine.find_one(
{"user_uu_id": str(app_manager_user.uu_id)}
)
if not existing_record:
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(),
}
)
else:
mongo_engine.update_one(
{"user_uu_id": str(app_manager_user.uu_id)},
{
"$set": {
"other_domains_list": [main_domain],
"main_domain": main_domain,
"modified_at": arrow.now().timestamp(),
}
},
)
sup_manager_user = Users.query.filter_by(person_id=sup_manager.id, user_tag=sup_manager.person_tag).first()
if not sup_manager_user:
sup_manager_user = Users.create(
person_id=sup_manager.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),
**active_row,
)
created_list.append(sup_manager_user)
sup_manager_user.password_expiry_begins = str(arrow.now())
sup_manager_user.password_token = PasswordModule.generate_refresher_token()
with mongo_handler.collection(collection_name) as mongo_engine:
existing_record = mongo_engine.find_one(
{"user_uu_id": str(sup_manager_employee.uu_id)}
)
if not existing_record:
print("insert sup existing record", existing_record)
mongo_engine.insert_one(
document={
"user_uu_id": str(sup_manager_employee.uu_id),
"other_domains_list": [main_domain, "management.com.tr"],
"main_domain": main_domain,
"modified_at": arrow.now().timestamp(),
}
)
else:
print("update sup existing record", existing_record)
# Optionally update the existing record if needed
mongo_engine.update_one(
{"user_uu_id": str(sup_manager_employee.uu_id)},
{
"$set": {
"other_domains_list": [main_domain, "management.com.tr"],
"main_domain": main_domain,
"modified_at": arrow.now().timestamp(),
}
},
)
db_session.commit()
print("All Defaults Create is now completed")

View File

@@ -0,0 +1,266 @@
from pydantic import BaseModel
from schemas import BuildTypes, ApiEnumDropdown
class InsertBuildTypes(BaseModel):
function_code: str
type_code: str
lang: str
type_name: str
def init_api_enums_build_types(db_session):
BuildTypes.set_session(db_session)
ApiEnumDropdown.set_session(db_session)
insert_types = [
{
"function_code": "EVYOS",
"type_code": "APT_KZN",
"type_name": "Apartman Kazan Dairesi",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "APT_GRJ",
"type_name": "Apartman Garaj",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "APT_DP",
"type_name": "Apartman Depo",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "DAIRE",
"type_name": "Apartman Dairesi",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "APT",
"type_name": "Apartman Binası",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "APT_YNT",
"type_name": "Apartman Yönetimi",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "APT_PRK",
"type_name": "Apartman Açık Park Alanı",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "APT_YSL",
"type_name": "Apartman Yeşil Alan",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "APT_YOL",
"type_name": "Apartman Ara Yol",
"lang": "TR",
},
]
for insert_type in insert_types:
build_types = InsertBuildTypes(
function_code="EVYOS",
lang=insert_type["lang"],
type_code=str(insert_type["type_code"]).upper(),
type_name=insert_type["type_name"],
)
created_build_type = BuildTypes.query.filter_by(
function_code=build_types.function_code,
type_code=build_types.type_code,
).first()
if not created_build_type:
created_build_type = BuildTypes.find_or_create(
**build_types.model_dump(), is_confirmed=True, db=db_session
)
created_build_type.save()
insert_enums = [
{"enum_class": "BuildDuesTypes", "type_code": "BDT-D", "type_name": "Debit"},
{
"enum_class": "BuildDuesTypes",
"type_code": "BDT-A",
"type_name": "Add Debit",
},
{
"enum_class": "BuildDuesTypes",
"type_code": "BDT-R",
"type_name": "Renovation",
},
{
"enum_class": "BuildDuesTypes",
"type_code": "BDT-L",
"type_name": "Lawyer expence",
},
{
"enum_class": "BuildDuesTypes",
"type_code": "BDT-S",
"type_name": "Service fee",
},
{
"enum_class": "BuildDuesTypes",
"type_code": "BDT-I",
"type_name": "Information",
},
{
"enum_class": "AccountingReceiptTypes",
"type_code": "ART-A",
"type_name": "Kasa Tahsil Fişi",
},
{
"enum_class": "AccountingReceiptTypes",
"type_code": "ART-E",
"type_name": "Kasa Tediye Fişi",
},
{
"enum_class": "AccountingReceiptTypes",
"type_code": "ART-M",
"type_name": "Mahsup Fişi",
},
{
"enum_class": "AccountingReceiptTypes",
"type_code": "ART-O",
"type_name": "ılış Fişi",
},
{
"enum_class": "AccountingReceiptTypes",
"type_code": "ART-C",
"type_name": "Kapanış Fişi",
},
{"enum_class": "IbanBudgetType", "type_code": "IBT-I", "type_name": "Iban"},
{"enum_class": "IbanBudgetType", "type_code": "IBT-B", "type_name": "Budget"},
{
"enum_class": "IbanBudgetType",
"type_code": "IBT-TR",
"type_name": "Transaction records",
},
{"enum_class": "ProjectTypes", "type_code": "R", "type_name": "Tadilat"},
{
"enum_class": "ProjectTypes",
"type_code": "PT-C",
"type_name": "Mahkeme süreçleri",
},
{
"enum_class": "ProjectTypes",
"type_code": "PT-Z",
"type_name": "Sıfır Bakiye",
},
{
"enum_class": "EdmBudgetType",
"type_code": "PT-B",
"type_name": "Banka records",
},
{
"enum_class": "EdmBudgetType",
"type_code": "PT-S",
"type_name": "Sistem kaydı",
},
{
"enum_class": "EdmBudgetType",
"type_code": "EBT-C",
"type_name": "Build, Flat or Site records",
},
{"enum_class": "ExpireType", "type_code": "1", "type_name": "daily"},
{"enum_class": "ExpireType", "type_code": "7", "type_name": "weekly"},
{"enum_class": "ExpireType", "type_code": "30", "type_name": "monthly"},
{"enum_class": "ExpireType", "type_code": "90", "type_name": "quarter"},
{"enum_class": "ExpireType", "type_code": "180", "type_name": "six_month"},
{"enum_class": "ExpireType", "type_code": "365", "type_name": "yearly"},
{"enum_class": "PhoneType", "type_code": "M", "type_name": "cep tel"},
{"enum_class": "PhoneType", "type_code": "L", "type_name": "sabit telefon"},
{"enum_class": "PhoneType", "type_code": "F", "type_name": "fax"},
{"enum_class": "PhoneType", "type_code": "C", "type_name": "santral"},
{
"enum_class": "PhoneType",
"type_code": "G",
"type_name": "ülke genelindeki hatlar 444",
},
{"enum_class": "PerComType", "type_code": "1", "type_name": "Person"},
{"enum_class": "PerComType", "type_code": "2", "type_name": "Company"},
{"enum_class": "Directions", "type_code": "NN", "type_name": "North"},
{"enum_class": "Directions", "type_code": "EE", "type_name": "East"},
{"enum_class": "Directions", "type_code": "SS", "type_name": "South"},
{"enum_class": "Directions", "type_code": "WW", "type_name": "West"},
{"enum_class": "Directions", "type_code": "NE", "type_name": "North East"},
{"enum_class": "Directions", "type_code": "NW", "type_name": "North West"},
{"enum_class": "Directions", "type_code": "SE", "type_name": "South East"},
{"enum_class": "Directions", "type_code": "SW", "type_name": "South West"},
{
"enum_class": "MeetingTypes",
"type_code": "MT-RBM",
"type_name": "Regular Building Meeting",
},
{
"enum_class": "MeetingTypes",
"type_code": "MT-DBM",
"type_name": "Disaster Building Meeting",
},
{
"enum_class": "MeetingTypes",
"type_code": "MT-EBM",
"type_name": "Emergency Building Meeting",
},
{
"enum_class": "DebitTypes",
"type_code": "DT-D",
"type_name": "Debit Sender",
},
{
"enum_class": "DebitTypes",
"type_code": "DT-R",
"type_name": "Credit Receiver",
},
{
"enum_class": "DebitTypes",
"type_code": "DT-Z",
"type_name": "Zero Balance",
},
{
"enum_class": "TimePeriod",
"type_code": "TP-W",
"type_name": "Weekly",
},
{
"enum_class": "TimePeriod",
"type_code": "TP-M",
"type_name": "Monthly",
},
{
"enum_class": "TimePeriod",
"type_code": "TP-Q",
"type_name": "Quarterly",
},
{
"enum_class": "TimePeriod",
"type_code": "TP-Y",
"type_name": "Yearly",
},
]
for insert_enum in insert_enums:
created_api_enum = ApiEnumDropdown.query.filter_by(
enum_class=insert_enum["enum_class"],
key=str(insert_enum["type_code"]).upper(),
).first()
if not created_api_enum:
created_api_enum = ApiEnumDropdown.create(
enum_class=insert_enum["enum_class"],
value=insert_enum["type_name"],
key=str(insert_enum["type_code"]).upper(),
description=insert_enum["type_name"],
is_confirmed=True,
)
created_api_enum.save()

View File

@@ -0,0 +1,299 @@
import arrow
from modules.Token.password_module import PasswordModule
from api_controllers.mongo.database import mongo_handler
from schemas import (
Addresses,
BuildLivingSpace,
Users,
People,
Build,
BuildParts,
BuildTypes,
ApiEnumDropdown,
Companies,
OccupantTypes,
)
def create_occupant_defaults(db_session):
created_list = []
Addresses.set_session(db_session)
BuildLivingSpace.set_session(db_session)
Users.set_session(db_session)
People.set_session(db_session)
Build.set_session(db_session)
BuildParts.set_session(db_session)
BuildTypes.set_session(db_session)
ApiEnumDropdown.set_session(db_session)
Companies.set_session(db_session)
OccupantTypes.set_session(db_session)
company_management = Companies.query.filter_by(formal_name = "Evyos LTD",).first()
if not company_management:
raise Exception("Company not found")
company_id, company_uu_id = company_management.id, str(company_management.uu_id)
active_row = dict(is_confirmed=True, active=True, deleted=False, is_notification_send=True)
build_type = BuildTypes.query.filter_by(type_code = "APT").first()
address = Addresses.query.filter_by(letter_address = "Example Address").first()
created_build = Build.query.filter_by(build_name = "Build Example").first()
if not created_build:
created_build = Build.create(
build_name="Build Example",
build_code="B001",
build_no="B001",
build_date="01.07.1980",
address_id=address.id,
address_uu_id=str(address.uu_id),
build_types_id=build_type.id,
build_types_uu_id=str(build_type.uu_id),
**active_row
)
created_list.append(created_build)
build_type_created = BuildTypes.query.filter_by(type_code = "APT").first()
build_type_flat = BuildTypes.query.filter_by(type_code = "DAIRE").first()
enum_dropdown = ApiEnumDropdown.query.filter_by(key = "NE", enum_class = "Directions").first()
occupant_type_prs = OccupantTypes.query.filter_by(occupant_code = "MT-PRS").first()
occupant_type_owner = OccupantTypes.query.filter_by(occupant_code = "FL-OWN").first()
occupant_type_tenant = OccupantTypes.query.filter_by(occupant_code = "FL-TEN").first()
created_managment_room = BuildParts.query.filter_by(part_code = "MR001").first()
if not created_managment_room:
created_managment_room = BuildParts.create(
address_gov_code="123123123123",
build_id=created_build.id,
build_uu_id=str(created_build.uu_id),
part_code="MR001",
part_net_size=100,
part_no=0,
part_level=0,
part_type_id=build_type_created.id,
part_type_uu_id=str(build_type_created.uu_id),
part_direction_id=enum_dropdown.id,
part_direction_uu_id=str(enum_dropdown.uu_id),
human_livable=True,
due_part_key="Example",
**active_row,
)
created_list.append(created_managment_room)
created_flat = BuildParts.query.filter_by(part_code = "MF001").first()
if not created_flat:
created_flat = BuildParts.create(
address_gov_code="123123123124",
build_id=created_build.id,
build_uu_id=str(created_build.uu_id),
part_code="MF001",
part_net_size=100,
part_no=1,
part_level=1,
part_type_id=build_type_flat.id,
part_type_uu_id=str(build_type_flat.uu_id),
part_direction_id=enum_dropdown.id,
part_direction_uu_id=str(enum_dropdown.uu_id),
human_livable=True,
due_part_key="Example",
**active_row,
)
created_list.append(created_flat)
build_manager_people = People.query.filter_by(person_tag = "Build Manager Example").first()
if not build_manager_people:
build_manager_people = People.create(
**{
"person_tag": "Build Manager Example",
"firstname": "Example Build Manager",
"surname": "Example",
"sex_code": "M",
"middle_name": "",
"father_name": "Father",
"mother_name": "Mother",
"country_code": "TR",
"national_identity_id": "12312312315",
"birth_place": "Ankara",
"birth_date": "01.07.1990",
"tax_no": "1231231234",
}
)
created_list.append(build_manager_people)
owner_people = People.query.filter_by(person_tag = "Owner Example").first()
if not owner_people:
owner_people = People.create(
**{
"person_tag": "Owner Example",
"firstname": "Example Owner",
"surname": "Example",
"sex_code": "M",
"middle_name": "",
"father_name": "Father",
"mother_name": "Mother",
"country_code": "TR",
"national_identity_id": "12312312316",
"birth_place": "Ankara",
"birth_date": "01.07.1990",
"tax_no": "1231231234",
}
)
created_list.append(owner_people)
tenant_people = People.query.filter_by(person_tag = "Tenant Example").first()
if not tenant_people:
tenant_people = People.create(
**{
"person_tag": "Tenant Example",
"firstname": "Example Tenant",
"surname": "Example",
"sex_code": "M",
"middle_name": "",
"father_name": "Father",
"mother_name": "Mother",
"country_code": "TR",
"national_identity_id": "12312312317",
"birth_place": "Ankara",
"birth_date": "01.07.1990",
"tax_no": "1231231234",
}
)
created_list.append(tenant_people)
main_domain, collection_name = "evyos.com.tr", f"{str(company_management.uu_id)}*Domain"
user_build_manager = Users.query.filter_by(user_tag = "Build Manager Example").first()
if not user_build_manager:
user_build_manager = Users.create(
person_id=build_manager_people.id,
person_uu_id=str(build_manager_people.uu_id),
user_tag=build_manager_people.person_tag,
email="example.build.manager@gmail.com",
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),
**active_row,
)
created_list.append(user_build_manager)
user_build_manager.password_expiry_begins = str(arrow.now())
user_build_manager.password_token = PasswordModule.generate_refresher_token()
user_owner = Users.query.filter_by(user_tag = "Owner Example").first()
if not user_owner:
user_owner = Users.create(
person_id=owner_people.id,
person_uu_id=str(owner_people.uu_id),
user_tag=owner_people.person_tag,
email="example.owner@gmail.com",
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),
**active_row,
)
created_list.append(user_owner)
user_owner.password_expiry_begins = str(arrow.now())
user_owner.password_token = PasswordModule.generate_refresher_token()
user_tenant = Users.query.filter_by(user_tag = "Tenant Example").first()
if not user_tenant:
user_tenant = Users.create(
person_id=tenant_people.id,
person_uu_id=str(tenant_people.uu_id),
user_tag=tenant_people.person_tag,
email="example.tenant@gmail.com",
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),
**active_row,
)
created_list.append(user_tenant)
user_tenant.password_expiry_begins = str(arrow.now())
user_tenant.password_token = PasswordModule.generate_refresher_token()
with mongo_handler.collection(collection_name) as mongo_engine:
existing_record = mongo_engine.find_one({"user_uu_id": str(user_build_manager.uu_id)})
if not existing_record:
mongo_engine.insert_one(
document={"user_uu_id": str(user_build_manager.uu_id), "other_domains_list": [main_domain], "main_domain": main_domain, "modified_at": arrow.now().timestamp()}
)
else:
mongo_engine.update_one(
{"user_uu_id": str(user_build_manager.uu_id)},
{"$set": {"other_domains_list": [main_domain], "main_domain": main_domain, "modified_at": arrow.now().timestamp()}}
)
with mongo_handler.collection(collection_name) as mongo_engine:
existing_record = mongo_engine.find_one({"user_uu_id": str(user_owner.uu_id)})
if not existing_record:
mongo_engine.insert_one(
document={"user_uu_id": str(user_owner.uu_id), "other_domains_list": [main_domain], "main_domain": main_domain, "modified_at": arrow.now().timestamp()}
)
else:
mongo_engine.update_one(
{"user_uu_id": str(user_owner.uu_id)},
{"$set": {"other_domains_list": [main_domain], "main_domain": main_domain, "modified_at": arrow.now().timestamp()}}
)
with mongo_handler.collection(collection_name) as mongo_engine:
existing_record = mongo_engine.find_one({"user_uu_id": str(user_tenant.uu_id)})
if not existing_record:
mongo_engine.insert_one(
document={"user_uu_id": str(user_tenant.uu_id), "other_domains_list": [main_domain], "main_domain": main_domain, "modified_at": arrow.now().timestamp()}
)
else:
mongo_engine.update_one(
{"user_uu_id": str(user_tenant.uu_id)},
{"$set": {"other_domains_list": [main_domain], "main_domain": main_domain, "modified_at": arrow.now().timestamp()}})
created_build_living_space_prs = BuildLivingSpace.query.filter_by(
build_id=created_build.id, build_parts_id=created_managment_room.id, person_id=build_manager_people.id
).first()
if not created_build_living_space_prs:
created_build_living_space_prs = BuildLivingSpace.create(
build_id=created_build.id,
build_uu_id=str(created_build.uu_id),
build_parts_id=created_managment_room.id,
build_parts_uu_id=str(created_managment_room.uu_id),
person_id=build_manager_people.id,
person_uu_id=str(build_manager_people.uu_id),
occupant_type_id=occupant_type_prs.id,
occupant_type_uu_id=str(occupant_type_prs.uu_id),
**active_row,
)
created_list.append(created_build_living_space_prs)
created_build_living_space_owner = BuildLivingSpace.query.filter_by(
build_id=created_build.id, build_parts_id=created_flat.id, person_id=owner_people.id
).first()
if not created_build_living_space_owner:
created_build_living_space_owner = BuildLivingSpace.create(
build_id=created_build.id,
build_uu_id=str(created_build.uu_id),
build_parts_id=created_flat.id,
build_parts_uu_id=str(created_flat.uu_id),
person_id=owner_people.id,
person_uu_id=str(owner_people.uu_id),
occupant_type_id=occupant_type_owner.id,
occupant_type_uu_id=str(occupant_type_owner.uu_id),
**active_row,
)
created_list.append(created_build_living_space_owner)
created_build_living_space_tenant = BuildLivingSpace.query.filter_by(
build_id=created_build.id, build_parts_id=created_flat.id, person_id=tenant_people.id
).first()
if not created_build_living_space_tenant:
created_build_living_space_tenant = BuildLivingSpace.create(
build_id=created_build.id,
build_uu_id=str(created_build.uu_id),
build_parts_id=created_flat.id,
build_parts_uu_id=str(created_flat.uu_id),
person_id=tenant_people.id,
person_uu_id=str(tenant_people.uu_id),
occupant_type_id=occupant_type_tenant.id,
occupant_type_uu_id=str(occupant_type_tenant.uu_id),
**active_row,
)
created_list.append(created_build_living_space_tenant)
db_session.commit()
print("Occupant Defaults Create is now completed")

View File

@@ -0,0 +1,225 @@
from schemas import OccupantTypes
def create_occupant_types_defaults(db_session):
"""
occupant_category = mapped_column(String, server_default="")
occupant_category_type = mapped_column(String, server_default="")
occupant_is_unique = mapped_column(Boolean, server_default="0")
"""
OccupantTypes.set_session(db_session)
list_occupant_types = [
{
"occupant_type": "Toplantı Başkanı",
"occupant_description": "Toplantı Başkanı",
"occupant_code": "MT-PRS",
"occupant_category": "Toplantı",
"occupant_category_type": "MT",
"occupant_is_unique": True,
},
{
"occupant_type": "Toplantı Katip",
"occupant_description": "Toplantıda tutanak tutan kişi",
"occupant_code": "MT-WRT",
"occupant_category": "Toplantı",
"occupant_category_type": "MT",
"occupant_is_unique": True,
},
{
"occupant_type": "Toplantı Katılımcısı",
"occupant_description": "Toplantıda sadece katılan kişi",
"occupant_code": "MT-ATT",
"occupant_category": "Toplantı",
"occupant_category_type": "MT",
"occupant_is_unique": False,
},
{
"occupant_type": "Toplantı Danışman",
"occupant_description": "Toplantıda danışmanlık yapan kişi",
"occupant_code": "MT-ADV",
"occupant_category": "Toplantı",
"occupant_category_type": "MT",
"occupant_is_unique": False,
},
{
"occupant_type": "Toplantı Seçilmiş Başkanı",
"occupant_description": "Toplantı Seçilmiş Başkanı",
"occupant_code": "MT-VPR",
"occupant_category": "Toplantı",
"occupant_category_type": "MT",
"occupant_is_unique": True,
},
{
"occupant_type": "Daire Sahibi",
"occupant_description": "Daire Sahibi",
"occupant_code": "FL-OWN",
"occupant_category": "Daire",
"occupant_category_type": "FL",
"occupant_is_unique": True,
},
{
"occupant_type": "Daire Kiracısı",
"occupant_description": "Daire Kiracısı",
"occupant_code": "FL-TEN",
"occupant_category": "Daire",
"occupant_category_type": "FL",
"occupant_is_unique": True,
},
{
"occupant_type": "Daire Sakini",
"occupant_description": "Daire Sakini",
"occupant_code": "FL-RES",
"occupant_category": "Daire",
"occupant_category_type": "FL",
"occupant_is_unique": False,
},
{
"occupant_type": "Daire Sakini Vekili",
"occupant_description": "Daire Sakini Vekili",
"occupant_code": "FL-REP",
"occupant_category": "Daire",
"occupant_category_type": "FL",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Avukatı",
"occupant_description": "Bina Avukatı",
"occupant_code": "BU-ATT",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Avukatı Yardımcısı",
"occupant_description": "Bina Avukatı Yardımcısı",
"occupant_code": "BU-ATA",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Denetmen Yardımcısı",
"occupant_description": "Bina Denetmen Yardımcısı",
"occupant_code": "BU-SPA",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Denetmeni",
"occupant_description": "Bina Denetmeni",
"occupant_code": "BU-SPV",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Yönetici Yardımcısı",
"occupant_description": "Bina Yönetici Yardımcısı",
"occupant_code": "BU-MNA",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Yöneticisi",
"occupant_description": "Bina Yöneticisi",
"occupant_code": "BU-MNG",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": True,
},
{
"occupant_type": "Bina Muhasabecisi",
"occupant_description": "Bina Muhasabecisi",
"occupant_code": "BU-ACC",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
{
"occupant_type": "Proje Lideri",
"occupant_description": "Proje Lideri",
"occupant_code": "PRJ-LDR",
"occupant_category": "Proje",
"occupant_category_type": "PRJ",
"occupant_is_unique": False,
},
{
"occupant_type": "Proje Sorumlusu",
"occupant_description": "Proje Sorumlusu",
"occupant_code": "PRJ-RES",
"occupant_category": "Proje",
"occupant_category_type": "PRJ",
"occupant_is_unique": False,
},
{
"occupant_type": "Proje Ekibi",
"occupant_description": "Proje Ekibi",
"occupant_code": "PRJ-EMP",
"occupant_category": "Proje",
"occupant_category_type": "PRJ",
"occupant_is_unique": False,
},
{
"occupant_type": "Proje Finans Sorumlusu",
"occupant_description": "Proje Finans Sorumlusu",
"occupant_code": "PRJ-FIN",
"occupant_category": "Proje",
"occupant_category_type": "PRJ",
"occupant_is_unique": False,
},
{
"occupant_type": "Proje Teknik Sorumlusu",
"occupant_description": "Proje Teknik Sorumlusu",
"occupant_code": "PRJ-TEC",
"occupant_category": "Proje",
"occupant_category_type": "PRJ",
"occupant_is_unique": False,
},
{
"occupant_type": "Daire Mülkiyet Vekili",
"occupant_description": "Daire Mülkiyet Vekili",
"occupant_code": "FL-DEP", # deputy
"occupant_category": "Daire",
"occupant_category_type": "FL",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Teknik Sorumlusu",
"occupant_description": "Bina Teknik Sorumlusu",
"occupant_code": "BU-TEC",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Teknik Elemanı",
"occupant_description": "Bina Teknik Elemanı",
"occupant_code": "BU-EMP",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Teknik Freelancer",
"occupant_description": "Bina Teknik Freelancer",
"occupant_code": "BU-FLC",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
]
for list_occupant_type in list_occupant_types:
try:
created_type = OccupantTypes.query.filter_by(
occupant_code=list_occupant_type["occupant_code"],
occupant_category=list_occupant_type["occupant_category_type"],
).first()
if not created_type:
created_type = OccupantTypes.create(**list_occupant_type, is_confirmed=True)
created_type.save()
except Exception as e:
print(f"Error: {e}")

View File

@@ -0,0 +1,78 @@
from schemas import (
Duty,
OccupantTypes,
Modules,
Services,
)
def create_modules_and_services_and_actions(db_session):
Duty.set_session(db_session)
Services.set_session(db_session)
Modules.set_session(db_session)
OccupantTypes.set_session(db_session)
erp_module = Modules.query.filter_by(module_code = "EVYOS-ERP").first()
if not erp_module:
erp_module = Modules.create(
**{
"module_name": "EVYOS ERP", "module_description": "EVYOS Enterprise Resource Planning", "module_code": "EVYOS-ERP",
"module_layer": 1, "is_default_module": False, "is_confirmed": True,
}
)
erp_module.save()
build_module = Modules.query.filter_by(module_code = "BLD-MNG").first()
if not build_module:
build_module = Modules.create(
**{
"module_name": "Bina Yönetim Modülü", "module_description": "Building Management Module", "module_code": "BLD-MNG",
"module_layer": 1, "is_default_module": False, "is_confirmed": True,
}
)
build_module.save()
user_module = Modules.query.filter_by(module_code = "USR-PUB").first()
if not user_module:
user_module = Modules.create(
**{
"module_name": "Kullancı Modülü", "module_description": "Kullanıcı Genel Modülü", "module_code": "USR-PUB", "module_layer": 1,
"is_default_module": True, "is_confirmed": True
}
)
user_module.save()
erp_module_module_dict = dict(module_id=erp_module.id, module_uu_id=str(erp_module.uu_id))
build_module_module_dict = dict(module_id=build_module.id, module_uu_id=str(build_module.uu_id))
duty_objects = Duty.query.filter(Duty.module_id == erp_module.id).all()
if not duty_objects:
raise Exception("Duty objects not found")
for duty_object in duty_objects:
created_service = Services.query.filter(Services.service_code == f"SRE-{duty_object.duty_code}").first()
if not created_service:
created_service = Services.create(
**erp_module_module_dict,
service_name=duty_object.duty_name,
service_description=duty_object.duty_description,
service_code=f"SRE-{duty_object.duty_code}",
related_responsibility=duty_object.duty_code,
is_confirmed=True,
)
created_service.save()
occupant_types = OccupantTypes.query.filter(OccupantTypes.module_id == build_module.id).all()
if not occupant_types:
raise Exception("Occupant types not found")
for occupant_type in occupant_types:
created_service = Services.query.filter(Services.service_code == f"SRO-{occupant_type.occupant_code}").first()
if not created_service:
created_service = Services.create(
**build_module_module_dict,
service_name=occupant_type.occupant_type,
service_description=occupant_type.occupant_description,
service_code=f"SRO-{occupant_type.occupant_code}",
related_responsibility=occupant_type.occupant_code,
is_confirmed=True,
)
created_service.save()

View File

@@ -0,0 +1,15 @@
from pydantic_settings import BaseSettings, SettingsConfigDict
class Configs(BaseSettings):
"""
ApiTemplate configuration settings.
"""
ACCESS_TOKEN_LENGTH: int = 90
REFRESHER_TOKEN_LENGTH: int = 144
model_config = SettingsConfigDict(env_prefix="API_")
token_config = Configs()

View File

@@ -0,0 +1,44 @@
import hashlib
import uuid
import secrets
import random
from .config import token_config
class PasswordModule:
@staticmethod
def generate_random_uu_id(str_std: bool = True):
return str(uuid.uuid4()) if str_std else uuid.uuid4()
@staticmethod
def generate_token(length=32) -> str:
letters = "abcdefghijklmnopqrstuvwxyz"
merged_letters = [letter for letter in letters] + [
letter.upper() for letter in letters
]
token_generated = secrets.token_urlsafe(length)
for i in str(token_generated):
if i not in merged_letters:
token_generated = token_generated.replace(
i, random.choice(merged_letters), 1
)
return token_generated
raise ValueError("EYS_0004")
@classmethod
def generate_access_token(cls) -> str:
return cls.generate_token(int(token_config.ACCESS_TOKEN_LENGTH))
@classmethod
def generate_refresher_token(cls) -> str:
return cls.generate_token(int(token_config.REFRESHER_TOKEN_LENGTH))
@staticmethod
def create_hashed_password(domain: str, id_: str, password: str) -> str:
return hashlib.sha256(f"{domain}:{id_}:{password}".encode("utf-8")).hexdigest()
@classmethod
def check_password(cls, domain, id_, password, password_hashed) -> bool:
return cls.create_hashed_password(domain, id_, password) == password_hashed