updated app reachable codes
This commit is contained in:
@@ -342,7 +342,6 @@ def authentication_token_refresh_post(
|
||||
status_code=status.HTTP_406_NOT_ACCEPTABLE,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
return JSONResponse(
|
||||
content={},
|
||||
status_code=status.HTTP_202_ACCEPTED,
|
||||
@@ -374,7 +373,6 @@ def authentication_password_verify_otp(
|
||||
"tz": tz or "GMT+3",
|
||||
"token": token,
|
||||
}
|
||||
print("Token&OTP : ", data.otp, data.token)
|
||||
if not domain or not language:
|
||||
return JSONResponse(
|
||||
content={"error": "EYS_0003"},
|
||||
@@ -419,8 +417,17 @@ def authentication_page_valid(
|
||||
status_code=status.HTTP_406_NOT_ACCEPTABLE,
|
||||
headers=headers,
|
||||
)
|
||||
result = AuthHandlers.PageHandlers.retrieve_valid_page_via_token(
|
||||
page_url=data.page_url, access_token=token
|
||||
)
|
||||
if not result:
|
||||
return JSONResponse(
|
||||
content={"error": "EYS_0004"},
|
||||
status_code=status.HTTP_406_NOT_ACCEPTABLE,
|
||||
headers=headers,
|
||||
)
|
||||
return JSONResponse(
|
||||
content={},
|
||||
content={"application": result},
|
||||
status_code=status.HTTP_202_ACCEPTED,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@@ -29,14 +29,16 @@ from Schemas import (
|
||||
)
|
||||
from Modules.Token.password_module import PasswordModule
|
||||
from Schemas.building.build import RelationshipEmployee2Build
|
||||
from Schemas.event.event import Event2Occupant
|
||||
from Schemas.event.event import Event2Occupant, Application2Employee
|
||||
from Controllers.Redis.database import RedisActions
|
||||
from Controllers.Mongo.database import mongo_handler
|
||||
|
||||
|
||||
TokenDictType = Union[EmployeeTokenObject, OccupantTokenObject]
|
||||
|
||||
|
||||
class RedisHandlers:
|
||||
|
||||
AUTH_TOKEN: str = "AUTH_TOKEN"
|
||||
|
||||
@classmethod
|
||||
@@ -79,9 +81,7 @@ class RedisHandlers:
|
||||
return generated_access_token
|
||||
|
||||
@classmethod
|
||||
def update_token_at_redis(
|
||||
cls, token: str, add_payload: Union[CompanyToken, OccupantToken]
|
||||
):
|
||||
def update_token_at_redis(cls, token: str, add_payload: Union[CompanyToken, OccupantToken]):
|
||||
if already_token_data := RedisActions.get_json(
|
||||
list_keys=[RedisHandlers.AUTH_TOKEN, token, "*"]
|
||||
).first:
|
||||
@@ -124,9 +124,7 @@ class UserHandlers:
|
||||
return found_user
|
||||
|
||||
@staticmethod
|
||||
def check_password_valid(
|
||||
domain: str, id_: str, password: str, password_hashed: str
|
||||
) -> bool:
|
||||
def check_password_valid(domain: str, id_: str, password: str, password_hashed: str) -> bool:
|
||||
"""
|
||||
Check if the password is valid.
|
||||
"""
|
||||
@@ -144,6 +142,10 @@ class UserHandlers:
|
||||
return True
|
||||
raise ValueError("EYS_0004")
|
||||
|
||||
@staticmethod
|
||||
def update_password():
|
||||
return
|
||||
|
||||
|
||||
class LoginHandler:
|
||||
|
||||
@@ -156,9 +158,7 @@ class LoginHandler:
|
||||
return str(email).split("@")[1] == api_config.ACCESS_EMAIL_EXT
|
||||
|
||||
@classmethod
|
||||
def do_employee_login(
|
||||
cls, request: Any, data: Any, extra_dict: Optional[Dict[str, Any]] = None
|
||||
):
|
||||
def do_employee_login(cls, request: Any, data: Any, extra_dict: Optional[Dict[str, Any]] = None):
|
||||
"""
|
||||
Handle employee login.
|
||||
"""
|
||||
@@ -268,9 +268,7 @@ class LoginHandler:
|
||||
raise ValueError("Something went wrong")
|
||||
|
||||
@classmethod
|
||||
def do_employee_occupant(
|
||||
cls, request: Any, data: Any, extra_dict: Optional[Dict[str, Any]] = None
|
||||
):
|
||||
def do_employee_occupant(cls, request: Any, data: Any, extra_dict: Optional[Dict[str, Any]] = None):
|
||||
"""
|
||||
Handle occupant login.
|
||||
"""
|
||||
@@ -421,9 +419,7 @@ class LoginHandler:
|
||||
return request.headers.get(api_config.ACCESS_TOKEN_TAG)
|
||||
|
||||
@classmethod
|
||||
def handle_employee_selection(
|
||||
cls, access_token: str, data: Any, token_dict: TokenDictType
|
||||
):
|
||||
def handle_employee_selection(cls, access_token: str, data: Any, token_dict: TokenDictType):
|
||||
with Users.new_session() as db:
|
||||
if data.company_uu_id not in token_dict.companies_uu_id_list:
|
||||
ValueError("EYS_0011")
|
||||
@@ -479,6 +475,10 @@ class LoginHandler:
|
||||
db=db,
|
||||
).data
|
||||
|
||||
reachable_app_codes = Application2Employee.get_application_codes(
|
||||
employee_id=employee.id, db=db
|
||||
)
|
||||
|
||||
# Create company token
|
||||
company_token = CompanyToken(
|
||||
company_uu_id=selected_company.uu_id.__str__(),
|
||||
@@ -493,6 +493,7 @@ class LoginHandler:
|
||||
employee_id=employee.id,
|
||||
employee_uu_id=employee.uu_id.__str__(),
|
||||
reachable_event_codes=reachable_event_codes,
|
||||
reachable_app_codes=reachable_app_codes
|
||||
)
|
||||
redis_handler = RedisHandlers()
|
||||
redis_result = redis_handler.update_token_at_redis(
|
||||
@@ -503,9 +504,7 @@ class LoginHandler:
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def handle_occupant_selection(
|
||||
cls, access_token: str, data: Any, token_dict: TokenDictType
|
||||
):
|
||||
def handle_occupant_selection(cls, access_token: str, data: Any, token_dict: TokenDictType):
|
||||
"""Handle occupant type selection"""
|
||||
with BuildLivingSpace.new_session() as db:
|
||||
# Get selected occupant type
|
||||
@@ -707,6 +706,22 @@ class PasswordHandler:
|
||||
return found_user
|
||||
|
||||
|
||||
class PageHandlers:
|
||||
|
||||
@classmethod
|
||||
def retrieve_valid_page_via_token(cls, access_token: str, page_url: str):
|
||||
if result := RedisHandlers.get_object_from_redis(access_token=access_token):
|
||||
if result.is_employee:
|
||||
if application := result.selected_company.reachable_app_codes.get(page_url, None):
|
||||
return application
|
||||
elif result.is_occupant:
|
||||
if application := result.selected_company.reachable_app_codes.get(page_url, None):
|
||||
return application
|
||||
raise ValueError("EYS_0013")
|
||||
|
||||
|
||||
class AuthHandlers:
|
||||
|
||||
LoginHandler: LoginHandler = LoginHandler()
|
||||
PasswordHandler: PasswordHandler = PasswordHandler()
|
||||
PageHandlers: PageHandlers = PageHandlers()
|
||||
|
||||
@@ -59,8 +59,8 @@ class OccupantToken(BaseModel):
|
||||
responsible_employee_id: Optional[int] = None
|
||||
responsible_employee_uuid: Optional[str] = None
|
||||
|
||||
reachable_event_codes: Optional[list[str]] = None # ID list of reachable modules
|
||||
reachable_app_codes: Optional[list[str]] = None # ID list of reachable modules
|
||||
reachable_event_codes: Optional[dict[str, str]] = None # ID list of reachable modules
|
||||
reachable_app_codes: Optional[dict[str, str]] = None # ID list of reachable modules
|
||||
|
||||
|
||||
class CompanyToken(BaseModel):
|
||||
@@ -83,8 +83,8 @@ class CompanyToken(BaseModel):
|
||||
|
||||
bulk_duties_id: int
|
||||
|
||||
reachable_event_codes: Optional[list[str]] = None # ID list of reachable modules
|
||||
reachable_app_codes: Optional[list[str]] = None # ID list of reachable modules
|
||||
reachable_event_codes: Optional[dict[str, str]] = None # ID list of reachable modules
|
||||
reachable_app_codes: Optional[dict[str, str]] = None # ID list of reachable modules
|
||||
|
||||
|
||||
class OccupantTokenObject(ApplicationToken):
|
||||
|
||||
@@ -15,7 +15,7 @@ class RequestVerifyOTP(BaseModel):
|
||||
|
||||
|
||||
class RequestApplication(BaseModel):
|
||||
page: str # /building/create
|
||||
page_url: str # /building/create
|
||||
|
||||
|
||||
class RequestSelectEmployee(BaseModel):
|
||||
|
||||
36
ApiServices/CompanyService/init_applications.py
Normal file
36
ApiServices/CompanyService/init_applications.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from Schemas import (
|
||||
Applications,
|
||||
Application2Employee,
|
||||
Application2Occupant,
|
||||
)
|
||||
|
||||
|
||||
"""
|
||||
|
||||
name=Building Create
|
||||
site_url=/buildings/create
|
||||
application_type=CreateFrom
|
||||
application_code=APP003
|
||||
|
||||
name=Building Create
|
||||
site_url=/buildings/create
|
||||
application_type=CreateFrom
|
||||
application_code=APP004
|
||||
|
||||
name=Building Create
|
||||
site_url=/buildings/create
|
||||
application_type=CreateFrom
|
||||
application_code=APP005
|
||||
|
||||
name=Building Update
|
||||
site_url=/buildings/update
|
||||
application_type=/building/update
|
||||
application_code=APP002
|
||||
|
||||
name=Building List
|
||||
site_url=/buildings
|
||||
application_type=ListFrom
|
||||
application_code=APP001
|
||||
|
||||
"""
|
||||
|
||||
28
ApiServices/DealerService/Dockerfile
Normal file
28
ApiServices/DealerService/Dockerfile
Normal 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 /ApiServices/DealerService /ApiServices/DealerService
|
||||
COPY /ApiServices/DealerService /
|
||||
COPY /Controllers /Controllers
|
||||
COPY /Modules /Modules
|
||||
COPY /Schemas /Schemas
|
||||
|
||||
# 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", "ApiServices/DealerService/app.py"]
|
||||
24
ApiServices/DealerService/app.py
Normal file
24
ApiServices/DealerService/app.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from Controllers.Postgres.database import get_db
|
||||
from Schemas import (
|
||||
Users,
|
||||
Employees,
|
||||
)
|
||||
from init_service_to_events import init_service_to_event_matches_for_super_user
|
||||
from init_applications import init_applications_for_super_user
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
"""
|
||||
Create Applications to serve on Next.js | Create Events to add to Service
|
||||
Set Events to service | Set Service to employee
|
||||
"""
|
||||
with get_db() as db_session:
|
||||
if super_man := Users.filter_one(
|
||||
Users.email == "karatay.berkay.sup@evyos.com.tr", db=db_session
|
||||
).data:
|
||||
super_employee = Employees.filter_one(
|
||||
Employees.people_id == super_man.person_id, db=db_session
|
||||
).data
|
||||
|
||||
init_service_to_event_matches_for_super_user(super_user=super_employee, db_session=db_session)
|
||||
init_applications_for_super_user(super_user=super_employee, db_session=db_session)
|
||||
40
ApiServices/DealerService/init_applications.py
Normal file
40
ApiServices/DealerService/init_applications.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from Schemas import (
|
||||
Applications,
|
||||
Application2Employee,
|
||||
Employees
|
||||
)
|
||||
|
||||
def init_applications_for_super_user(super_user: Employees, db_session=None) -> None:
|
||||
list_of_created_apps = [
|
||||
dict(
|
||||
name="Dashboard1",
|
||||
application_code = "app000001",
|
||||
site_url = "/dashboard",
|
||||
application_type = "info",
|
||||
description = "Dashboard Page"
|
||||
),
|
||||
dict(
|
||||
name="Dashboard2",
|
||||
application_code = "app000002",
|
||||
site_url = "/buildings/list",
|
||||
application_type = "CreateFrom",
|
||||
description = "Dashboard Page"
|
||||
),
|
||||
]
|
||||
|
||||
for list_of_created_app in list_of_created_apps:
|
||||
dashboard_page = Applications.find_or_create(
|
||||
**list_of_created_app, db=db_session,
|
||||
)
|
||||
print('dashboard_page', dashboard_page)
|
||||
if dashboard_page.meta_data.created:
|
||||
dashboard_page.save(db=db_session)
|
||||
Application2Employee.find_or_create(
|
||||
employee_id=super_user.id,
|
||||
employee_uu_id=str(super_user.uu_id),
|
||||
site_url=dashboard_page.site_url,
|
||||
application_code=dashboard_page.application_code,
|
||||
application_id=dashboard_page.id,
|
||||
application_uu_id=str(dashboard_page.uu_id),
|
||||
db=db_session,
|
||||
)
|
||||
47
ApiServices/DealerService/init_service_to_events.py
Normal file
47
ApiServices/DealerService/init_service_to_events.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from Schemas import (
|
||||
Users,
|
||||
Services,
|
||||
Service2Events,
|
||||
Applications,
|
||||
Application2Employee,
|
||||
Application2Occupant,
|
||||
Employees,
|
||||
Event2Employee,
|
||||
)
|
||||
|
||||
|
||||
list_of_event_codes = []
|
||||
|
||||
|
||||
def init_service_to_event_matches_for_super_user(super_user, db_session=None) -> None:
|
||||
service_match = Services.filter_one(
|
||||
Services.service_name == "Super User", db=db_session,
|
||||
).data
|
||||
for list_of_event_code in list_of_event_codes:
|
||||
created_service = Service2Events.find_or_create(
|
||||
service_id=service_match.id,
|
||||
service_uu_id=str(service_match.uu_id),
|
||||
event_id=list_of_event_code.id,
|
||||
event_uu_id=str(list_of_event_code.uu_id),
|
||||
is_confirmed=True,
|
||||
active=True,
|
||||
db=db_session,
|
||||
)
|
||||
if created_service.meta_data.created:
|
||||
created_service.save(db=db_session)
|
||||
print(
|
||||
f"UUID: {created_service.uu_id} event is saved to {service_match.uu_id}"
|
||||
)
|
||||
employee_added_service = Event2Employee.find_or_create(
|
||||
event_service_id=created_service.id,
|
||||
event_service_uu_id=str(created_service.uu_id),
|
||||
employee_id=super_user.id,
|
||||
employee_uu_id=str(super_user.uu_id),
|
||||
is_confirmed=True,
|
||||
db=db_session
|
||||
)
|
||||
if employee_added_service.meta_data.created:
|
||||
employee_added_service.save(db=db_session)
|
||||
print(
|
||||
f"UUID: {employee_added_service.uu_id} event is saved to {super_user.uu_id}"
|
||||
)
|
||||
@@ -1,9 +1,11 @@
|
||||
import uuid
|
||||
|
||||
from fastapi import APIRouter, Request, Response, Header
|
||||
|
||||
from ApiServices.TemplateService.config import api_config
|
||||
from ApiServices.TemplateService.events.template.event import template_event_cluster
|
||||
|
||||
|
||||
test_template_route = APIRouter(prefix="/test", tags=["Test"])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user