added apps
This commit is contained in:
@@ -446,7 +446,6 @@ def authentication_page_valid(
|
||||
):
|
||||
"""
|
||||
Verify if page is valid returns application that can user reach
|
||||
page: { url = /building/create}
|
||||
result: { "sites": ['/dashboard', '/building/create'] }
|
||||
"""
|
||||
token = request.headers.get(api_config.ACCESS_TOKEN_TAG, None)
|
||||
@@ -463,7 +462,9 @@ def authentication_page_valid(
|
||||
status_code=status.HTTP_406_NOT_ACCEPTABLE,
|
||||
headers=headers,
|
||||
)
|
||||
result = AuthHandlers.PageHandlers.retrieve_valid_sites_via_token(access_token=token)
|
||||
result = AuthHandlers.PageHandlers.retrieve_valid_sites_via_token(
|
||||
access_token=token
|
||||
)
|
||||
if not result:
|
||||
return JSONResponse(
|
||||
content={"error": "EYS_0004"},
|
||||
@@ -471,8 +472,7 @@ def authentication_page_valid(
|
||||
headers=headers,
|
||||
)
|
||||
return JSONResponse(
|
||||
content={"sites": result},
|
||||
content={"sites": list(set(result))},
|
||||
status_code=status.HTTP_202_ACCEPTED,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
|
||||
@@ -13,8 +13,6 @@ from ApiServices.AuthService.config import api_config
|
||||
from Schemas import (
|
||||
Users,
|
||||
People,
|
||||
UsersTokens,
|
||||
Credentials,
|
||||
BuildLivingSpace,
|
||||
BuildParts,
|
||||
OccupantTypes,
|
||||
@@ -70,7 +68,6 @@ class RedisHandlers:
|
||||
result_delete = RedisActions.delete(
|
||||
list_keys=[RedisHandlers.AUTH_TOKEN, "*", str(user.uu_id)]
|
||||
)
|
||||
print("result_delete", result_delete)
|
||||
generated_access_token = PasswordModule.generate_access_token()
|
||||
keys = [RedisHandlers.AUTH_TOKEN, generated_access_token, str(user.uu_id)]
|
||||
RedisActions.set_json(
|
||||
@@ -81,7 +78,9 @@ 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:
|
||||
@@ -99,7 +98,6 @@ class RedisHandlers:
|
||||
value=already_token.model_dump(),
|
||||
expires={"hours": 1, "minutes": 30},
|
||||
)
|
||||
print("result.first", result.first)
|
||||
return result.first
|
||||
raise ValueError("Something went wrong")
|
||||
|
||||
@@ -124,18 +122,12 @@ 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.
|
||||
"""
|
||||
print(
|
||||
dict(
|
||||
domain=domain,
|
||||
id_=id_,
|
||||
password=password,
|
||||
password_hashed=password_hashed,
|
||||
)
|
||||
)
|
||||
if PasswordModule.check_password(
|
||||
domain=domain, id_=id_, password=password, password_hashed=password_hashed
|
||||
):
|
||||
@@ -158,7 +150,9 @@ 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,7 +262,9 @@ 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.
|
||||
"""
|
||||
@@ -417,7 +413,9 @@ 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")
|
||||
@@ -491,7 +489,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
|
||||
reachable_app_codes=reachable_app_codes,
|
||||
)
|
||||
redis_handler = RedisHandlers()
|
||||
redis_result = redis_handler.update_token_at_redis(
|
||||
@@ -502,7 +500,9 @@ 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
|
||||
@@ -635,13 +635,10 @@ class PasswordHandler:
|
||||
raise ValueError("")
|
||||
|
||||
collection_name = f"{found_user.related_company}*Domain"
|
||||
print("collection_name", collection_name)
|
||||
with mongo_handler.collection(collection_name) as mongo_engine:
|
||||
print({"user_uu_id": str(found_user.uu_id)})
|
||||
domain_via_user = mongo_engine.find_one(
|
||||
{"user_uu_id": str(found_user.uu_id)}
|
||||
)
|
||||
print("domain_via_user", domain_via_user)
|
||||
if not domain_via_user:
|
||||
raise ValueError("EYS_0024")
|
||||
domain_via_user = domain_via_user.get("main_domain", None)
|
||||
@@ -705,7 +702,7 @@ class PasswordHandler:
|
||||
|
||||
|
||||
class PageHandlers:
|
||||
|
||||
|
||||
@classmethod
|
||||
def retrieve_valid_page_via_token(cls, access_token: str, page_url: str) -> str:
|
||||
"""
|
||||
@@ -718,14 +715,17 @@ class PageHandlers:
|
||||
"""
|
||||
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):
|
||||
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):
|
||||
if application := result.selected_company.reachable_app_codes.get(
|
||||
page_url, None
|
||||
):
|
||||
return application
|
||||
raise ValueError("EYS_0013")
|
||||
|
||||
|
||||
@classmethod
|
||||
def retrieve_valid_sites_via_token(cls, access_token: str) -> list:
|
||||
"""
|
||||
|
||||
@@ -59,7 +59,9 @@ class OccupantToken(BaseModel):
|
||||
responsible_employee_id: Optional[int] = None
|
||||
responsible_employee_uuid: Optional[str] = None
|
||||
|
||||
reachable_event_codes: Optional[dict[str, 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
|
||||
|
||||
|
||||
@@ -83,7 +85,9 @@ class CompanyToken(BaseModel):
|
||||
|
||||
bulk_duties_id: int
|
||||
|
||||
reachable_event_codes: Optional[dict[str, 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
|
||||
|
||||
|
||||
|
||||
@@ -33,4 +33,3 @@ from Schemas import (
|
||||
application_code=APP001
|
||||
|
||||
"""
|
||||
|
||||
|
||||
@@ -14,11 +14,15 @@ if __name__ == "__main__":
|
||||
"""
|
||||
with get_db() as db_session:
|
||||
if super_man := Users.filter_one(
|
||||
Users.email == "karatay.berkay.sup@evyos.com.tr", db=db_session
|
||||
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)
|
||||
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
|
||||
)
|
||||
|
||||
@@ -1,40 +1,111 @@
|
||||
from Schemas import (
|
||||
Applications,
|
||||
Application2Employee,
|
||||
Employees
|
||||
)
|
||||
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"
|
||||
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"
|
||||
name="Individual",
|
||||
application_code="app000003",
|
||||
site_url="/individual",
|
||||
application_type="Dash",
|
||||
description="Individual Page for people",
|
||||
),
|
||||
dict(
|
||||
name="User",
|
||||
application_code="app000004",
|
||||
site_url="/user",
|
||||
application_type="Dash",
|
||||
description="Individual Page for user",
|
||||
),
|
||||
dict(
|
||||
name="Build",
|
||||
application_code="app000005",
|
||||
site_url="/build",
|
||||
application_type="Dash",
|
||||
description="Individual Page for build",
|
||||
),
|
||||
dict(
|
||||
name="BuildParts",
|
||||
application_code="app000006",
|
||||
site_url="/build/parts",
|
||||
application_type="Dash",
|
||||
description="Individual Page for build parts",
|
||||
),
|
||||
dict(
|
||||
name="BuildArea",
|
||||
application_code="app000007",
|
||||
site_url="/build/area",
|
||||
application_type="Dash",
|
||||
description="Individual Page for build area",
|
||||
),
|
||||
dict(
|
||||
name="ManagementAccounting",
|
||||
application_code="app000008",
|
||||
site_url="/management/accounting",
|
||||
application_type="Dash",
|
||||
description="Individual Page for management accounting",
|
||||
),
|
||||
dict(
|
||||
name="ManagementBudget",
|
||||
application_code="app000009",
|
||||
site_url="/management/budget",
|
||||
application_type="Dash",
|
||||
description="Individual Page for management accounting2",
|
||||
),
|
||||
dict(
|
||||
name="ManagementMeetingClose",
|
||||
application_code="app000010",
|
||||
site_url="/annual/meeting/close",
|
||||
application_type="Dash",
|
||||
description="Individual Page for management accounting3",
|
||||
),
|
||||
dict(
|
||||
name="EmergencyMeeting",
|
||||
application_code="app000011",
|
||||
site_url="/emergency/meeting",
|
||||
application_type="Dash",
|
||||
description="Individual Page for management accounting4",
|
||||
),
|
||||
dict(
|
||||
name="EmergencyMeetingClose",
|
||||
application_code="app000012",
|
||||
site_url="/emergency/meeting/close",
|
||||
application_type="Dash",
|
||||
description="Individual Page for management accounting5",
|
||||
),
|
||||
dict(
|
||||
name="MeetingParticipation",
|
||||
application_code="app000013",
|
||||
site_url="/meeting/participation",
|
||||
application_type="Dash",
|
||||
description="Individual Page for management accounting6",
|
||||
),
|
||||
]
|
||||
|
||||
for list_of_created_app in list_of_created_apps:
|
||||
dashboard_page = Applications.find_or_create(
|
||||
**list_of_created_app, db=db_session,
|
||||
created_page = Applications.find_or_create(
|
||||
**list_of_created_app,
|
||||
db=db_session,
|
||||
is_confirmed=True,
|
||||
)
|
||||
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,
|
||||
)
|
||||
if created_page.meta_data.created:
|
||||
created_page.save(db=db_session)
|
||||
|
||||
application_employee_created = Application2Employee.find_or_create(
|
||||
employee_id=super_user.id,
|
||||
employee_uu_id=str(super_user.uu_id),
|
||||
site_url=created_page.site_url,
|
||||
application_code=created_page.application_code,
|
||||
application_id=created_page.id,
|
||||
application_uu_id=str(created_page.uu_id),
|
||||
is_confirmed=True,
|
||||
db=db_session,
|
||||
)
|
||||
if application_employee_created.meta_data.created:
|
||||
application_employee_created.save(db=db_session)
|
||||
|
||||
@@ -15,7 +15,8 @@ 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,
|
||||
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(
|
||||
@@ -38,7 +39,7 @@ def init_service_to_event_matches_for_super_user(super_user, db_session=None) ->
|
||||
employee_id=super_user.id,
|
||||
employee_uu_id=str(super_user.uu_id),
|
||||
is_confirmed=True,
|
||||
db=db_session
|
||||
db=db_session,
|
||||
)
|
||||
if employee_added_service.meta_data.created:
|
||||
employee_added_service.save(db=db_session)
|
||||
|
||||
Reference in New Issue
Block a user