auth api tested
This commit is contained in:
118
ApiLayers/AllConfigs/Api/config.py
Normal file
118
ApiLayers/AllConfigs/Api/config.py
Normal file
@@ -0,0 +1,118 @@
|
||||
import datetime
|
||||
|
||||
|
||||
class DefaultApiConfig:
|
||||
app: str
|
||||
host: str
|
||||
port: int
|
||||
log_level: str
|
||||
reload: bool
|
||||
|
||||
@classmethod
|
||||
def as_dict(cls):
|
||||
return {
|
||||
"app": cls.app,
|
||||
"host": cls.host,
|
||||
"port": int(cls.port),
|
||||
"log_level": cls.log_level,
|
||||
"reload": bool(cls.reload),
|
||||
}
|
||||
|
||||
|
||||
class ApiConfigs:
|
||||
"""Base class for all configurations."""
|
||||
|
||||
SECRET: str = (
|
||||
"59f871a2d2194e96adb36b279d2cc21059f871a2d2194e96adb36b279d2cc21059f871a2d2194e96adb36b279d2cc210s"
|
||||
)
|
||||
ACCESS_TIME: int = 432000
|
||||
REFRESH_TIME: int = 864000
|
||||
DEFAULT_SIZE: int = 10
|
||||
MIN_SIZE: int = 5
|
||||
MAX_SIZE: int = 50
|
||||
ACCESS_TOKEN_TAG: str = "Authorization"
|
||||
REFRESH_TOKEN_TAG: str = "Refresher"
|
||||
ACCESS_TOKEN_LENGTH: int = 72
|
||||
REFRESH_TOKEN_LENGTH: int = 128
|
||||
|
||||
|
||||
class ApiStatic:
|
||||
PLACEHOLDER = "https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg"
|
||||
FORGOT_LINK = "https://www.evyos.com.tr/password/create?tokenUrl="
|
||||
BLACKLIST_LINK = "https://www.evyos.com.tr/support/unknown-login-notice/"
|
||||
APP_DIR = "/home/berkay/git-evyos/api-managment-backend/"
|
||||
|
||||
@classmethod
|
||||
def forgot_link(cls, forgot_key):
|
||||
return cls.FORGOT_LINK + forgot_key
|
||||
|
||||
@classmethod
|
||||
def blacklist_login(cls, record_id):
|
||||
return cls.BLACKLIST_LINK + record_id
|
||||
|
||||
|
||||
class MainConfig:
|
||||
|
||||
# Date and Time Configuration
|
||||
DATETIME_FORMAT = "YYYY-MM-DD HH:mm:ss Z"
|
||||
DATETIME_FORMAT_JS = "YYYY-MM-DD HH:mm:ss +0"
|
||||
|
||||
# Timezone Configuration
|
||||
DEFAULT_TIMEZONE = "GMT+3" # Default timezone for the application
|
||||
SYSTEM_TIMEZONE = "GMT+0" # System timezone (used for internal operations)
|
||||
SUPPORTED_TIMEZONES = ["GMT+0", "GMT+3"] # List of supported timezones
|
||||
|
||||
|
||||
class LanguageConfig:
|
||||
|
||||
SUPPORTED_LANGUAGES = ["en", "tr"]
|
||||
DEFAULT_LANGUAGE = "tr"
|
||||
|
||||
|
||||
class ValidationsConfig:
|
||||
|
||||
SUPPORTED_VALIDATIONS = ["header", "validation", "all"]
|
||||
DEFAULT_VALIDATION = "all"
|
||||
|
||||
|
||||
class ApiConfig(DefaultApiConfig):
|
||||
# Application Information
|
||||
APP_NAME = "evyos-auth-api-gateway"
|
||||
TITLE = "WAG API Auth Api Gateway"
|
||||
DESCRIPTION = (
|
||||
"This api is serves as web auth api gateway only to evyos web services."
|
||||
)
|
||||
APP_URL = "https://www.auth.eys.gen.tr"
|
||||
|
||||
# Server Configuration
|
||||
app = "app:app"
|
||||
host = "0.0.0.0"
|
||||
port = 41575
|
||||
log_level = "info"
|
||||
reload = True
|
||||
|
||||
|
||||
class Auth:
|
||||
ACCESS_EMAIL_EXT = "evyos.com.tr"
|
||||
ACCESS_TOKEN_TAG = "evyos-session-key"
|
||||
REFRESHER_TOKEN_TAG = "eys-session-refresher"
|
||||
SECRET_KEY_72 = (
|
||||
"t3sUAmjTGeTgDc6dAUrB41u2SNg0ZHzj4HTjem95y3fRH1nZXOHIBj163kib6iLybT0gLaxq"
|
||||
)
|
||||
SECRET_KEY_96 = "7ct8VpiwaP1hR2bVSet4dEEAgepuTZUOnO1QxOgKyDqBR2PkqNhcubSrbUUigQKoQA1PBoeeQn5ZCo24pESmVtKs76nA4EKq"
|
||||
SECRET_KEY_144 = (
|
||||
"R2p5Rq6KCr6PCfjFYUeH1keF2VWHFEuqINVjBGGnvRA2m10pYUKqfOtIGBcaj2v5wZmElDndzSHGOS7roQsoTelPSok0"
|
||||
+ "qqMucurMWE0FGexGpFuJkfPEm9tH2OjMOqegvEetpSVywH0W4Kh4"
|
||||
)
|
||||
|
||||
ALGORITHM = "HS256"
|
||||
ACCESS_TOKEN_LENGTH: int = 90
|
||||
REFRESHER_TOKEN_LENGTH: int = 144
|
||||
PASSWORD_EXPIRE_DAY = datetime.timedelta(days=30)
|
||||
TOKEN_EXPIRE_MINUTES_1 = datetime.timedelta(minutes=1)
|
||||
TOKEN_EXPIRE_MINUTES_15 = datetime.timedelta(minutes=15)
|
||||
TOKEN_EXPIRE_MINUTES_30 = datetime.timedelta(minutes=30)
|
||||
TOKEN_EXPIRE_DAY_1 = datetime.timedelta(days=1)
|
||||
TOKEN_EXPIRE_DAY_5 = datetime.timedelta(days=5)
|
||||
TOKEN_EXPIRE_DAY_15 = datetime.timedelta(days=15)
|
||||
TOKEN_EXPIRE_DAY_30 = datetime.timedelta(days=30)
|
||||
@@ -5,19 +5,21 @@ from ApiLayers.AllConfigs import HostConfig
|
||||
|
||||
class Config:
|
||||
|
||||
MAILBOX: str = os.getenv('MAILBOX', "bilgilendirme@ileti.isbank.com.tr")
|
||||
MAIN_MAIL: str = os.getenv('MAIN_MAIL', "karatay.berkay@gmail.com")
|
||||
INFO_MAIL: str = os.getenv('INFO_MAIL', "mehmet.karatay@hotmail.com")
|
||||
EMAIL_HOST: str = os.getenv('EMAIL_HOST', "10.10.2.34")
|
||||
EMAIL_SENDER_USERNAME: str = os.getenv('EMAIL_SENDER_USERNAME', "karatay@mehmetkaratay.com.tr")
|
||||
EMAIL_USERNAME: str = os.getenv('EMAIL_USERNAME', "isbank@mehmetkaratay.com.tr")
|
||||
EMAIL_PASSWORD: str = os.getenv('EMAIL_PASSWORD', "system")
|
||||
AUTHORIZE_IBAN: str = os.getenv('AUTHORIZE_IBAN', "4245-0093333")
|
||||
SERVICE_TIMING: int = int(os.getenv('SERVICE_TIMING', 900))
|
||||
EMAIL_PORT: int = int(os.getenv('EMAIL_PORT', 993))
|
||||
EMAIL_SEND_PORT: int = int(os.getenv('EMAIL_SEND_PORT', 587))
|
||||
EMAIL_SLEEP: int = int(os.getenv('EMAIL_SLEEP', 60))
|
||||
EMAIL_SEND: bool = bool(os.getenv('EMAIL_SEND', False))
|
||||
MAILBOX: str = os.getenv("MAILBOX", "bilgilendirme@ileti.isbank.com.tr")
|
||||
MAIN_MAIL: str = os.getenv("MAIN_MAIL", "karatay.berkay@gmail.com")
|
||||
INFO_MAIL: str = os.getenv("INFO_MAIL", "mehmet.karatay@hotmail.com")
|
||||
EMAIL_HOST: str = os.getenv("EMAIL_HOST", "10.10.2.34")
|
||||
EMAIL_SENDER_USERNAME: str = os.getenv(
|
||||
"EMAIL_SENDER_USERNAME", "karatay@mehmetkaratay.com.tr"
|
||||
)
|
||||
EMAIL_USERNAME: str = os.getenv("EMAIL_USERNAME", "isbank@mehmetkaratay.com.tr")
|
||||
EMAIL_PASSWORD: str = os.getenv("EMAIL_PASSWORD", "system")
|
||||
AUTHORIZE_IBAN: str = os.getenv("AUTHORIZE_IBAN", "4245-0093333")
|
||||
SERVICE_TIMING: int = int(os.getenv("SERVICE_TIMING", 900))
|
||||
EMAIL_PORT: int = int(os.getenv("EMAIL_PORT", 993))
|
||||
EMAIL_SEND_PORT: int = int(os.getenv("EMAIL_SEND_PORT", 587))
|
||||
EMAIL_SLEEP: int = int(os.getenv("EMAIL_SLEEP", 60))
|
||||
EMAIL_SEND: bool = bool(os.getenv("EMAIL_SEND", False))
|
||||
|
||||
|
||||
class EmailConfig:
|
||||
|
||||
@@ -3,7 +3,7 @@ from ApiLayers.AllConfigs import HostConfig
|
||||
|
||||
class WagDatabase:
|
||||
HOST: str = HostConfig.MAIN_HOST
|
||||
PORT: int = 5434
|
||||
PORT: int = 5444
|
||||
SQL: str = "postgresql+psycopg2"
|
||||
USERNAME: str = "berkay_wag_user"
|
||||
PASSWORD: str = "berkay_wag_user_password"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
class HostConfig:
|
||||
|
||||
MAIN_HOST = "10.10.2.36" # http://10.10.2.36 Database and other services
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from fastapi import APIRouter
|
||||
import uuid
|
||||
from Events.Engine.abstract_class import CategoryCluster, MethodToEvent
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
from Services.Redis import RedisActions, AccessToken
|
||||
from Services.Redis.Models.cluster import RedisList
|
||||
from Services.RedisService.Actions.actions import RedisActions
|
||||
from Services.RedisService.Models.access import AccessToken
|
||||
from Services.RedisService.Models.cluster import RedisList
|
||||
|
||||
|
||||
redis_list = RedisList(redis_key="test")
|
||||
|
||||
@@ -23,13 +23,12 @@ class UserLoginModule:
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def check_user_exists(access_key: str):
|
||||
def check_user_exists(access_key: str, db_session):
|
||||
from ApiLayers.Schemas import Users
|
||||
|
||||
"""
|
||||
Check if the user exists in the database.
|
||||
"""
|
||||
db_session = Users.new_session() # Check if user exists.
|
||||
if "@" in access_key:
|
||||
found_user: Users = Users.filter_one(
|
||||
Users.email == access_key.lower(), db=db_session
|
||||
@@ -54,42 +53,46 @@ class UserLoginModule:
|
||||
"""
|
||||
Login the user via the credentials.
|
||||
"""
|
||||
|
||||
# Get the actual data from the BaseRequestModel if needed
|
||||
found_user: Users = self.check_user_exists(access_key=access_data.access_key)
|
||||
if len(found_user.hash_password) < 5:
|
||||
with Users.new_session() as db_session: # Check if user exists.
|
||||
# Get the actual data from the BaseRequestModel if needed
|
||||
found_user: Users = self.check_user_exists(
|
||||
access_key=access_data.access_key, db_session=db_session
|
||||
)
|
||||
if len(found_user.hash_password) < 5:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
lang=found_user.lang,
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg="login_user_via_credentials: Invalid password create a password to user first",
|
||||
)
|
||||
# Check if the password is correct
|
||||
if PasswordModule.check_password(
|
||||
domain=access_data.domain,
|
||||
id_=found_user.uu_id,
|
||||
password=access_data.password,
|
||||
password_hashed=found_user.hash_password,
|
||||
):
|
||||
found_user_dict = found_user.get_dict()
|
||||
# Set the access token to the redis
|
||||
token_response = TokenService.set_access_token_to_redis(
|
||||
request=self.request,
|
||||
user=found_user,
|
||||
domain=access_data.domain,
|
||||
remember=access_data.remember_me,
|
||||
db_session=db_session
|
||||
)
|
||||
# Set the user and token information to the instance
|
||||
self.user = found_user_dict
|
||||
self.access_token = token_response.get("access_token")
|
||||
self.refresh_token = token_response.get("refresh_token")
|
||||
self.access_object = {
|
||||
"user_type": token_response.get("user_type", None),
|
||||
"selection_list": token_response.get("selection_list", {}),
|
||||
}
|
||||
return None
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
lang=found_user.lang,
|
||||
lang="tr",
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg="login_user_via_credentials: Invalid password create a password to user first",
|
||||
sys_msg="login_user_via_credentials: raised an unknown error",
|
||||
)
|
||||
# Check if the password is correct
|
||||
if PasswordModule.check_password(
|
||||
domain=access_data.domain,
|
||||
id_=found_user.uu_id,
|
||||
password=access_data.password,
|
||||
password_hashed=found_user.hash_password,
|
||||
):
|
||||
# Set the access token to the redis
|
||||
token_response = TokenService.set_access_token_to_redis(
|
||||
request=self.request,
|
||||
user=found_user,
|
||||
domain=access_data.domain,
|
||||
remember=access_data.remember_me,
|
||||
)
|
||||
# Set the user and token information to the instance
|
||||
self.user = found_user.get_dict()
|
||||
self.access_token = token_response.get("access_token")
|
||||
self.refresh_token = token_response.get("refresh_token")
|
||||
self.access_object = {
|
||||
"user_type": token_response.get("user_type", None),
|
||||
"selection_list": token_response.get("selection_list", {}),
|
||||
}
|
||||
return None
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
lang="tr",
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg="login_user_via_credentials: raised an unknown error",
|
||||
)
|
||||
|
||||
@@ -30,8 +30,9 @@ from ApiLayers.Schemas import (
|
||||
Departments,
|
||||
OccupantTypes,
|
||||
)
|
||||
from Services.Redis.Models.response import RedisResponse
|
||||
from Services.Redis import RedisActions, AccessToken
|
||||
from Services.RedisService.Models.response import RedisResponse
|
||||
from Services.RedisService.Actions.actions import RedisActions
|
||||
from Services.RedisService.Models.access import AccessToken
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -63,78 +64,78 @@ class TokenService:
|
||||
"""Handle employee login process and return login information."""
|
||||
from ApiLayers.Schemas.identity.identity import UsersTokens, People
|
||||
|
||||
db_session = Employees.new_session()
|
||||
list_employee = Employees.filter_all(
|
||||
Employees.people_id == user.person_id, db=db_session
|
||||
).data
|
||||
|
||||
companies_uu_id_list: List[str] = []
|
||||
companies_id_list: List[int] = []
|
||||
companies_list: List[Dict[str, Any]] = []
|
||||
duty_uu_id_list: List[str] = []
|
||||
duty_id_list: List[int] = []
|
||||
|
||||
for employee in list_employee:
|
||||
staff = Staff.filter_one(Staff.id == employee.staff_id, db=db_session).data
|
||||
if duties := Duties.filter_one(
|
||||
Duties.id == staff.duties_id, db=db_session
|
||||
).data:
|
||||
if duty_found := Duty.filter_by_one(
|
||||
id=duties.duties_id, db=db_session
|
||||
).data:
|
||||
duty_uu_id_list.append(str(duty_found.uu_id))
|
||||
duty_id_list.append(duty_found.id)
|
||||
|
||||
department = Departments.filter_one(
|
||||
Departments.id == duties.department_id, db=db_session
|
||||
with Employees.new_session() as db_session:
|
||||
list_employee = Employees.filter_all(
|
||||
Employees.people_id == user.person_id, db=db_session
|
||||
).data
|
||||
|
||||
if company := Companies.filter_one(
|
||||
Companies.id == department.company_id, db=db_session
|
||||
).data:
|
||||
companies_uu_id_list.append(str(company.uu_id))
|
||||
companies_id_list.append(company.id)
|
||||
company_address = Addresses.filter_by_one(
|
||||
id=company.official_address_id, db=db_session
|
||||
companies_uu_id_list: List[str] = []
|
||||
companies_id_list: List[int] = []
|
||||
companies_list: List[Dict[str, Any]] = []
|
||||
duty_uu_id_list: List[str] = []
|
||||
duty_id_list: List[int] = []
|
||||
|
||||
for employee in list_employee:
|
||||
staff = Staff.filter_one(Staff.id == employee.staff_id, db=db_session).data
|
||||
if duties := Duties.filter_one(
|
||||
Duties.id == staff.duties_id, db=db_session
|
||||
).data:
|
||||
if duty_found := Duty.filter_by_one(
|
||||
id=duties.duties_id, db=db_session
|
||||
).data:
|
||||
duty_uu_id_list.append(str(duty_found.uu_id))
|
||||
duty_id_list.append(duty_found.id)
|
||||
|
||||
department = Departments.filter_one(
|
||||
Departments.id == duties.department_id, db=db_session
|
||||
).data
|
||||
companies_list.append(
|
||||
{
|
||||
"uu_id": str(company.uu_id),
|
||||
"public_name": company.public_name,
|
||||
"company_type": company.company_type,
|
||||
"company_address": company_address,
|
||||
}
|
||||
)
|
||||
person = People.filter_one(People.id == user.person_id, db=db_session).data
|
||||
model_value = EmployeeTokenObject(
|
||||
domain=domain,
|
||||
user_type=UserType.employee.value,
|
||||
user_uu_id=str(user.uu_id),
|
||||
credentials=user.credentials(),
|
||||
user_id=user.id,
|
||||
person_id=person.id,
|
||||
person_uu_id=str(person.uu_id),
|
||||
full_name=person.full_name,
|
||||
request=dict(request.headers),
|
||||
companies_uu_id_list=companies_uu_id_list,
|
||||
companies_id_list=companies_id_list,
|
||||
duty_uu_id_list=duty_uu_id_list,
|
||||
duty_id_list=duty_id_list,
|
||||
timezone=user.local_timezone or "GMT+0",
|
||||
lang="tr",
|
||||
).model_dump()
|
||||
if access_token := cls.set_object_to_redis(user, model_value):
|
||||
return {
|
||||
"access_token": access_token,
|
||||
"user_type": UserType.employee.name,
|
||||
"selection_list": companies_list,
|
||||
}
|
||||
raise HTTPExceptionApi(
|
||||
error_code="",
|
||||
lang="en",
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg="Creating Token failed...",
|
||||
)
|
||||
|
||||
if company := Companies.filter_one(
|
||||
Companies.id == department.company_id, db=db_session
|
||||
).data:
|
||||
companies_uu_id_list.append(str(company.uu_id))
|
||||
companies_id_list.append(company.id)
|
||||
company_address = Addresses.filter_by_one(
|
||||
id=company.official_address_id, db=db_session
|
||||
).data
|
||||
companies_list.append(
|
||||
{
|
||||
"uu_id": str(company.uu_id),
|
||||
"public_name": company.public_name,
|
||||
"company_type": company.company_type,
|
||||
"company_address": company_address,
|
||||
}
|
||||
)
|
||||
person = People.filter_one(People.id == user.person_id, db=db_session).data
|
||||
model_value = EmployeeTokenObject(
|
||||
domain=domain,
|
||||
user_type=UserType.employee.value,
|
||||
user_uu_id=str(user.uu_id),
|
||||
credentials=user.credentials(db_session=db_session),
|
||||
user_id=user.id,
|
||||
person_id=person.id,
|
||||
person_uu_id=str(person.uu_id),
|
||||
full_name=person.full_name,
|
||||
request=dict(request.headers),
|
||||
companies_uu_id_list=companies_uu_id_list,
|
||||
companies_id_list=companies_id_list,
|
||||
duty_uu_id_list=duty_uu_id_list,
|
||||
duty_id_list=duty_id_list,
|
||||
timezone=user.local_timezone or "GMT+0",
|
||||
lang="tr",
|
||||
).model_dump()
|
||||
if access_token := cls.set_object_to_redis(user, model_value):
|
||||
return {
|
||||
"access_token": access_token,
|
||||
"user_type": UserType.employee.name,
|
||||
"selection_list": companies_list,
|
||||
}
|
||||
raise HTTPExceptionApi(
|
||||
error_code="",
|
||||
lang="en",
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg="Creating Token failed...",
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def do_occupant_login(
|
||||
@@ -285,14 +286,15 @@ class TokenService:
|
||||
user: Users,
|
||||
domain: str,
|
||||
remember: bool,
|
||||
db_session
|
||||
) -> Dict[str, Any]:
|
||||
"""Set access token to redis and handle user session."""
|
||||
from ApiLayers.AllConfigs.Token.config import Auth
|
||||
from ApiLayers.Schemas.identity.identity import UsersTokens, People
|
||||
|
||||
user_id, user_dict = user.id, user.get_dict()
|
||||
cls.remove_token_with_domain(user=user, domain=domain)
|
||||
# Users.client_arrow = DateTimeLocal(is_client=True, timezone=user.local_timezone)
|
||||
login_dict, db_session = {}, UsersTokens.new_session()
|
||||
login_dict = {}
|
||||
|
||||
if user.is_occupant: # Handle login based on user type
|
||||
login_dict = cls.do_occupant_login(
|
||||
request=request, user=user, domain=domain
|
||||
@@ -309,7 +311,7 @@ class TokenService:
|
||||
login_dict["refresh_token"] = users_token_created
|
||||
users_token = UsersTokens.find_or_create(
|
||||
db=db_session,
|
||||
user_id=user.id,
|
||||
user_id=user_id,
|
||||
token_type="RememberMe",
|
||||
domain=domain,
|
||||
)
|
||||
@@ -329,15 +331,15 @@ class TokenService:
|
||||
login_dict["refresh_token"] = users_token.token
|
||||
else:
|
||||
already_refresher = UsersTokens.filter_all(
|
||||
UsersTokens.user_id == user.id,
|
||||
UsersTokens.user_id == user_id,
|
||||
UsersTokens.token_type == "RememberMe",
|
||||
UsersTokens.domain == domain,
|
||||
db=db_session,
|
||||
)
|
||||
if already_refresher.count:
|
||||
already_refresher.query.delete(synchronize_session=False)
|
||||
already_refresher.core_query.delete(synchronize_session=False)
|
||||
user.save(db=db_session)
|
||||
return {**login_dict, "user": user.get_dict()}
|
||||
return {**login_dict, "user": user_dict}
|
||||
|
||||
@classmethod
|
||||
def update_token_at_redis(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import json
|
||||
from typing import Any, Union, Awaitable
|
||||
from pydantic import ValidationError
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from Services.Redis.Actions.actions import RedisActions
|
||||
from Services.RedisService.Actions.actions import RedisActions
|
||||
from ApiLayers.AllConfigs.Redis.configs import RedisValidationKeys
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from ApiLayers.AllConfigs.Redis.configs import (
|
||||
)
|
||||
from ApiLayers.AllConfigs.main import LanguageConfig
|
||||
from Events.Engine.set_defaults.category_cluster_models import CategoryClusterController
|
||||
from Services.Redis.Actions.actions import RedisActions
|
||||
from Services.RedisService.Actions.actions import RedisActions
|
||||
|
||||
|
||||
class SetDefaultLanguageModelsRedis:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from typing import Optional
|
||||
from Services.Redis import RedisActions
|
||||
from Services.RedisService.Actions.actions import RedisActions
|
||||
from ApiLayers.AllConfigs.Redis.configs import RedisValidationKeysAction
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from ApiLayers.ErrorHandlers.Exceptions.api_exc import HTTPExceptionApi
|
||||
from ApiLayers.Schemas import Events, EndpointRestriction
|
||||
from ApiLayers.AllConfigs.Redis.configs import RedisCategoryKeys
|
||||
|
||||
from Services.Redis.Actions.actions import RedisActions
|
||||
from Services.RedisService.Actions.actions import RedisActions
|
||||
|
||||
from .auth_middleware import MiddlewareModule
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from sqlalchemy import (
|
||||
SmallInteger,
|
||||
)
|
||||
|
||||
from Services.PostgresDb import CrudCollection
|
||||
from Services.PostgresService.controllers.mixin_controllers import CrudCollection
|
||||
from ApiLayers.LanguageModels.Database.account.account import (
|
||||
AccountBooksLanguageModel,
|
||||
AccountCodesLanguageModel,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from sqlalchemy import String, ForeignKey, Index, TIMESTAMP, SmallInteger, Identity
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
|
||||
from Services.PostgresDb import CrudCollection
|
||||
from Services.PostgresService.controllers.mixin_controllers import CrudCollection
|
||||
|
||||
|
||||
class BuildIbans(CrudCollection):
|
||||
|
||||
@@ -6,7 +6,7 @@ from sqlalchemy import String
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
|
||||
from cryptography.fernet import Fernet, MultiFernet
|
||||
from Services.PostgresDb import CrudCollection
|
||||
from Services.PostgresService.controllers.mixin_controllers import CrudCollection
|
||||
|
||||
|
||||
class CrypterEngine(CrudCollection):
|
||||
|
||||
@@ -9,7 +9,7 @@ from sqlalchemy import (
|
||||
Integer,
|
||||
)
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from Services.PostgresDb import CrudCollection
|
||||
from Services.PostgresService.controllers.mixin_controllers import CrudCollection
|
||||
|
||||
|
||||
class DecisionBookBudgetBooks(CrudCollection):
|
||||
|
||||
@@ -16,7 +16,7 @@ from sqlalchemy import (
|
||||
)
|
||||
|
||||
from ApiLayers.ApiLibrary import system_arrow, SelectActionWithEmployee
|
||||
from Services.PostgresDb import CrudCollection
|
||||
from Services.PostgresService.controllers.mixin_controllers import CrudCollection
|
||||
from ApiLayers.ApiValidations.Request import (
|
||||
InsertBuild,
|
||||
InsertBuildParts,
|
||||
|
||||
@@ -25,7 +25,7 @@ from ApiLayers.ApiValidations.Request import (
|
||||
InsertBuildDecisionBookItemDebits,
|
||||
InsertBuildDecisionBookProjects,
|
||||
)
|
||||
from Services.PostgresDb import CrudCollection
|
||||
from Services.PostgresService.controllers.mixin_controllers import CrudCollection
|
||||
from ApiLayers.LanguageModels.Database.building.decision_book import (
|
||||
BuildDecisionBookLanguageModel,
|
||||
BuildDecisionBookInvitationsLanguageModel,
|
||||
|
||||
@@ -23,7 +23,7 @@ from ApiLayers.LanguageModels.Database.company.company import (
|
||||
CompaniesLanguageModel,
|
||||
# CompanyDutiesLanguageModel,
|
||||
)
|
||||
from Services.PostgresDb import CrudCollection
|
||||
from Services.PostgresService.controllers.mixin_controllers import CrudCollection
|
||||
|
||||
|
||||
class RelationshipDutyCompany(CrudCollection):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from sqlalchemy import String, Integer, ForeignKey, Index, Boolean, Identity
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
|
||||
from Services.PostgresDb import CrudCollection
|
||||
from Services.PostgresService.controllers.mixin_controllers import CrudCollection
|
||||
|
||||
|
||||
class Departments(CrudCollection):
|
||||
|
||||
@@ -12,7 +12,7 @@ from ApiLayers.LanguageModels.Database.company.employee import (
|
||||
EmployeeHistoryLanguageModel,
|
||||
EmployeesSalariesLanguageModel,
|
||||
)
|
||||
from Services.PostgresDb import CrudCollection
|
||||
from Services.PostgresService.controllers.mixin_controllers import CrudCollection
|
||||
|
||||
from ApiLayers.ApiValidations.Request import InsertCompanyEmployees
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from Services.PostgresDb import CrudCollection
|
||||
from Services.PostgresService.controllers.mixin_controllers import CrudCollection
|
||||
from ApiLayers.LanguageModels.Database.event.event import (
|
||||
EventsLanguageModel,
|
||||
ModulesLanguageModel,
|
||||
@@ -250,29 +250,28 @@ class Event2Employee(CrudCollection):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_event_codes(cls, employee_id: int) -> list:
|
||||
db = cls.new_session()
|
||||
def get_event_codes(cls, employee_id: int, db_session) -> list:
|
||||
employee_events = cls.filter_all(
|
||||
cls.employee_id == employee_id,
|
||||
db=db,
|
||||
db=db_session,
|
||||
).data
|
||||
active_event_ids = Service2Events.filter_all_system(
|
||||
Service2Events.service_id.in_(
|
||||
[event.event_service_id for event in employee_events]
|
||||
),
|
||||
db=db,
|
||||
db=db_session,
|
||||
).data
|
||||
active_events = Events.filter_all(
|
||||
Events.id.in_([event.event_id for event in active_event_ids]),
|
||||
db=db,
|
||||
db=db_session,
|
||||
).data
|
||||
if extra_events := Event2EmployeeExtra.filter_all(
|
||||
Event2EmployeeExtra.employee_id == employee_id,
|
||||
db=db,
|
||||
db=db_session,
|
||||
).data:
|
||||
events_extra = Events.filter_all(
|
||||
Events.id.in_([event.event_id for event in extra_events]),
|
||||
db=db,
|
||||
db=db_session,
|
||||
).data
|
||||
active_events.extend(events_extra)
|
||||
return [event.function_code for event in active_events]
|
||||
|
||||
@@ -15,7 +15,7 @@ from sqlalchemy import (
|
||||
)
|
||||
from sqlalchemy.orm import mapped_column, relationship, Mapped
|
||||
|
||||
from Services.PostgresDb import CrudCollection
|
||||
from Services.PostgresService.controllers.mixin_controllers import CrudCollection
|
||||
from config import ApiStatic
|
||||
|
||||
from ApiLayers.ApiLibrary.date_time_actions.date_functions import system_arrow
|
||||
@@ -144,8 +144,7 @@ class Users(CrudCollection, SelectAction):
|
||||
return "Occupant" if self.is_occupant else "Employee"
|
||||
|
||||
@classmethod
|
||||
def credentials(cls):
|
||||
db_session = cls.new_session()
|
||||
def credentials(cls, db_session):
|
||||
person_object: People = People.filter_by_one(
|
||||
db=db_session, system=True, id=cls.person_id
|
||||
).data
|
||||
|
||||
@@ -9,7 +9,7 @@ from sqlalchemy.orm import (
|
||||
Mapped,
|
||||
mapped_column,
|
||||
)
|
||||
from Services.PostgresDb import CrudCollection
|
||||
from Services.PostgresService.controllers.mixin_controllers import CrudCollection
|
||||
|
||||
|
||||
class ApiEnumDropdown(CrudCollection):
|
||||
|
||||
@@ -4,7 +4,7 @@ from sqlalchemy.orm import mapped_column, Mapped
|
||||
from ApiLayers.LanguageModels.Database.rules.rules import (
|
||||
EndpointRestrictionLanguageModel,
|
||||
)
|
||||
from Services.PostgresDb import CrudCollection
|
||||
from Services.PostgresService.controllers.mixin_controllers import CrudCollection
|
||||
|
||||
|
||||
class EndpointRestriction(CrudCollection):
|
||||
|
||||
Reference in New Issue
Block a user