Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from src.services.auth_service import is_admin | |
| from src.db.connection import get_conn | |
| from src.db.audit import recent as recent_audit | |
| def render_admin_tab(db_path: str, auth_state: gr.State): | |
| with gr.Column() as panel: | |
| gr.Markdown("## Admin") | |
| info = gr.Markdown("Login as **Dr** to access admin features.") | |
| refresh = gr.Button("Refresh Audit (Admin)") | |
| table = gr.Dataframe( | |
| headers=["entity","entity_id","action","note","changed_by","changed_at_utc"], | |
| interactive=False, | |
| row_count=15, | |
| col_count=6, | |
| ) | |
| def _refresh(auth): | |
| if not auth: | |
| return "Please login.", [] | |
| if not is_admin(auth): | |
| return "β Admin only.", [] | |
| conn = get_conn(db_path) | |
| try: | |
| rows = recent_audit(conn, limit=30) | |
| finally: | |
| conn.close() | |
| data = [[r["entity"], r["entity_id"], r["action"], r["note"], r["changed_by"], r["changed_at_utc"]] for r in rows] | |
| return "β Audit loaded.", data | |
| refresh.click(_refresh, inputs=[auth_state], outputs=[info, table]) | |
| panel.load(_refresh, inputs=[auth_state], outputs=[info, table]) | |
| return panel, {} | |