26 lines
761 B
Python
26 lines
761 B
Python
import json
|
|||
|
|
import os
|
||
|
|
from fastapi import APIRouter, HTTPException, Request
|
||
|
|
|
||
|
|
MENU_PERMISSIONS_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "menu_permissions.json")
|
||
|
|
|
||
|
|
router = APIRouter(tags=["Permisos"])
|
||
|
|
|
||
|
|
|
||
|
|
def load_permissions() -> dict:
|
||
|
|
if not os.path.exists(MENU_PERMISSIONS_PATH):
|
||
|
|
return {}
|
||
|
|
with open(MENU_PERMISSIONS_PATH, "r") as f:
|
||
|
|
return json.load(f)
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/api/user/menu")
|
||
|
|
async def get_user_menu(request: Request):
|
||
|
|
webUser = str(getattr(request.state, "webUser", ""))
|
||
|
|
if not webUser:
|
||
|
|
raise HTTPException(status_code=401, detail="Usuario no autenticado")
|
||
|
|
|
||
|
|
permissions = load_permissions()
|
||
|
|
allowed_paths = permissions.get(webUser, [])
|
||
|
|
|
||
|
|
return {"allowedPaths": allowed_paths}
|