Skip to content

Commit

Permalink
rewire api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
witlox committed Dec 10, 2024
1 parent d450e93 commit 67286e3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 21 deletions.
21 changes: 0 additions & 21 deletions horao/api/alive_controller.py

This file was deleted.

56 changes: 56 additions & 0 deletions horao/api/user_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-#
import json
import logging
import os

from starlette.authentication import requires
from starlette.requests import Request # type: ignore
from starlette.responses import JSONResponse # type: ignore

from horao.auth.permissions import Namespace, Permission
from horao.auth.validate import permission_required
from horao.persistance import HoraoEncoder, init_session


@requires("authenticated")
@permission_required(Namespace.User, Permission.Read)
async def get_reservations(request: Request) -> JSONResponse:
"""
responses:
200:
description: reservations for current user.
examples: [
{"type": "Reservation",
"name": "reservation",
"start": "start timestamp",
"end": "end timestamp",
"resources": [],
"maximal_resources": [],
"hsn_only": obj.hsn_only,
}
]
403:
description: Unauthorized
500:
description: Error processing request
"""
logging.debug(f"Calling Reservations ({request})")
try:
session = init_session()
logical_infrastructure = await session.load_logical_infrastructure()
claims = []
for claim in logical_infrastructure.claims:
if claim.owner == request.user or request.user in claim.delegates:
claims.append(claim)
return JSONResponse(
status_code=200, content={"claims": json.dumps(claims, cls=HoraoEncoder)}
)
except Exception as e:
logging.error(f"Error processing request: {e}")
if os.getenv("DEBUG", "False") == "True":
return JSONResponse(
status_code=500, content={"error": f"Error processing request {str(e)}"}
)
return JSONResponse(
status_code=500, content={"error": f"Error processing request"}
)

0 comments on commit 67286e3

Please sign in to comment.