endpoint retriever updated
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
from fastapi.routing import APIRouter
|
||||
from fastapi.requests import Request
|
||||
|
||||
from api_objects import OccupantTokenObject, EmployeeTokenObject
|
||||
from api_validations.validations_request import (
|
||||
UpdateEndpointAccessList,
|
||||
InsertEndpointAccess,
|
||||
)
|
||||
|
||||
from api_services.redis.auth_actions.token import parse_token_object_to_dict
|
||||
|
||||
from databases import (
|
||||
EndpointRestriction,
|
||||
Event2Occupant,
|
||||
Event2Employee,
|
||||
Events,
|
||||
)
|
||||
|
||||
endpoint_restriction_route = APIRouter(prefix="/access", tags=["Endpoint Access"])
|
||||
endpoint_restriction_route.include_router(
|
||||
@@ -25,7 +31,7 @@ def endpoint_restriction_create(request: Request, data: InsertEndpointAccess):
|
||||
|
||||
|
||||
@endpoint_restriction_route.post(
|
||||
path="/endpoint/bind/update", summary="Update extra restriction to endpoints list"
|
||||
path="/endpoint/update", summary="Update extra restriction to endpoints list"
|
||||
)
|
||||
def endpoint_restriction_update(request: Request, data: UpdateEndpointAccessList):
|
||||
token_dict = parse_token_object_to_dict(request=request)
|
||||
@@ -33,11 +39,36 @@ def endpoint_restriction_update(request: Request, data: UpdateEndpointAccessList
|
||||
|
||||
|
||||
@endpoint_restriction_route.post(
|
||||
path="/endpoint/bind/list", summary="List extra restriction to endpoints list"
|
||||
path="/endpoints/available", summary="List extra restriction to endpoints list"
|
||||
)
|
||||
def endpoint_restriction_list(request: Request):
|
||||
token_dict = parse_token_object_to_dict(request=request)
|
||||
return
|
||||
token_dict, records = parse_token_object_to_dict(request=request), []
|
||||
if isinstance(token_dict, OccupantTokenObject):
|
||||
occupant_events = Event2Occupant.filter_all(
|
||||
Event2Occupant.build_living_space_id
|
||||
== token_dict.selected_occupant.living_space_id
|
||||
).data
|
||||
events_list = Events.filter_all(
|
||||
Events.id.in_([event.event_id for event in occupant_events])
|
||||
).data
|
||||
records = EndpointRestriction.filter_all(
|
||||
EndpointRestriction.id.in_([event.endpoint_id for event in events_list])
|
||||
).data
|
||||
elif isinstance(token_dict, EmployeeTokenObject):
|
||||
employee_events = Event2Employee.filter_all(
|
||||
Event2Employee.employee_id == token_dict.selected_company.employee_id
|
||||
).data
|
||||
events_list = Events.filter_all(
|
||||
Events.id.in_([event.event_id for event in employee_events])
|
||||
).data
|
||||
records = EndpointRestriction.filter_all(
|
||||
EndpointRestriction.id.in_([event.endpoint_id for event in events_list])
|
||||
).data
|
||||
return dict(
|
||||
completed=True,
|
||||
message="Available endpoints are listed successfully",
|
||||
result=[str(record.endpoint_name) for record in records],
|
||||
)
|
||||
|
||||
|
||||
@endpoint_restriction_route.patch(
|
||||
|
||||
Reference in New Issue
Block a user