Michael Rabinovich commited on
Commit ·
02751ff
1
Parent(s): 293bc3b
admin: refresh table on auth load
Browse filesFiles changed (2)
- app.py+9-4
- tests/test_proxy.py+28
295 unmodified lines2962972982993003013023033043053063075 unmodified lines313314315316317318319295 unmodified lines) -> tuple[gr.Dataframe, gr.Radio, gr.Button, gr.Button, gr.Checkbox, gr.Button, str]:"""Enable the admin controls only for a logged-in user in the admin set.Runs on every page load and re-runs on LoginButton auth events.Non-admins and logged-out visitors get the tab with the tableread-only and every control disabled, mirroring the server-sidere-check in each handler. The delete button always loads disarmed:it only enables once the confirm checkbox is ticked."""admin = is_admin(profile)if profile is None:status = "Log in with an admin account to enable the controls below."5 unmodified lines"set. Controls are disabled.")return (gr.Dataframe(interactive=admin),gr.Radio(interactive=admin),gr.Button(interactive=admin),gr.Button(interactive=admin),295 unmodified lines2962972982993003013023033043053063073083093103113125 unmodified lines318319320321322323324295 unmodified lines) -> tuple[gr.Dataframe, gr.Radio, gr.Button, gr.Button, gr.Checkbox, gr.Button, str]:"""Enable the admin controls only for a logged-in user in the admin set.Runs on every page load and re-runs on LoginButton auth events, sothe table value is also refreshed from the live Hub data instead ofstaying pinned to whatever rows existed when the Space processbooted. Non-admins and logged-out visitors get the tab with thetable read-only and every control disabled, mirroring the server-sidere-check in each handler. The delete button always loads disarmed:it only enables once the confirm checkbox is ticked."""admin_df, error = _safe_load_admin()if error:gr.Warning(f"Admin table unavailable: {error}")admin = is_admin(profile)if profile is None:status = "Log in with an admin account to enable the controls below."5 unmodified lines"set. Controls are disabled.")return (gr.Dataframe(value=admin_df, interactive=admin),gr.Radio(interactive=admin),gr.Button(interactive=admin),gr.Button(interactive=admin),
210 unmodified lines211212213214215216210 unmodified linesassert list(admin_df.columns) == leaderboard.ADMIN_COLUMNSdef test_data_error_banner_md_present_on_error_empty_otherwise():"""Banner markdown is non-empty (and names the cause) only on error."""assert app._data_error_banner_md(None) == ""210 unmodified lines211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244210 unmodified linesassert list(admin_df.columns) == leaderboard.ADMIN_COLUMNSdef test_gate_admin_controls_refreshes_live_table(monkeypatch):"""Page/auth load refreshes the admin table, not just interactivity."""live_df = pd.DataFrame([{"select": False,"validation_status": "unvalidated","validation_method": None,"submission_name": "UC3 e2e test 20260602-205316","submitter_name": "michaelr27","submitted_at": "2026-06-02 19:00 UTC","status": "completed","aggregate_score": 0.5853,"submission_id": "uc3-e2e",}],columns=leaderboard.ADMIN_COLUMNS,)monkeypatch.setattr(app, "_safe_load_admin", lambda: (live_df, None))monkeypatch.setattr(app, "is_admin", lambda profile: True)table_update = app._gate_admin_controls(types.SimpleNamespace(username="michaelr27"))[0]assert table_update.value["headers"] == leaderboard.ADMIN_COLUMNSassert table_update.value["data"][0][3] == "UC3 e2e test 20260602-205316"assert table_update.interactive is Truedef test_data_error_banner_md_present_on_error_empty_otherwise():"""Banner markdown is non-empty (and names the cause) only on error."""assert app._data_error_banner_md(None) == ""
app.py+9-4
tests/test_proxy.py+28