ligbox-ops-platform/projects/ops-desk/legacy-app/modules/routes.py
Ligbox Spec Hub 821675ab4a Reorganize monorepo into projects/wizard, ops-desk, finance
Specs stay at repo root (cross-VM). Move deploy and code into logical
projects with README per domain, updated manifest.yaml, and symlinks at
legacy paths for VM122 backward compatibility.
2026-06-19 18:55:03 +00:00

43 lines
1.2 KiB
Python

"""Rotas API do registry de módulos."""
from __future__ import annotations
from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel
from app import auth
from app.modules import store
router = APIRouter(prefix="/api/v1/modules", tags=["modules"])
class ModuleToggle(BaseModel):
enabled: bool
@router.get("")
def list_modules(user: auth.DeskUser = Depends(auth.get_current_user)):
modules = store.list_modules(user.role)
visible = [
m
for m in modules
if user.role == "super_admin" or m["enabled_for_role"]
]
return {"modules": visible, "role": user.role}
@router.patch("/{module_id}")
def set_module(
module_id: str,
body: ModuleToggle,
user: auth.DeskUser = Depends(auth.get_current_user),
):
if user.role != "super_admin":
raise HTTPException(403, "insufficient permissions")
try:
store.set_module_enabled(module_id, body.enabled)
except KeyError:
raise HTTPException(404, "module not found") from None
except ValueError as exc:
raise HTTPException(400, str(exc)) from exc
return {"id": module_id, "enabled": store.is_module_enabled(module_id)}