Michael Rabinovich commited on
Commit ·
02751ff
1
Parent(s): 293bc3b
admin: refresh table on auth load
Browse files- app.py +9 -4
- tests/test_proxy.py +28 -0
app.py
CHANGED
|
@@ -296,12 +296,17 @@ def _gate_admin_controls(
|
|
| 296 |
) -> tuple[gr.Dataframe, gr.Radio, gr.Button, gr.Button, gr.Checkbox, gr.Button, str]:
|
| 297 |
"""Enable the admin controls only for a logged-in user in the admin set.
|
| 298 |
|
| 299 |
-
Runs on every page load and re-runs on LoginButton auth events
|
| 300 |
-
|
| 301 |
-
|
|
|
|
|
|
|
| 302 |
re-check in each handler. The delete button always loads disarmed:
|
| 303 |
it only enables once the confirm checkbox is ticked.
|
| 304 |
"""
|
|
|
|
|
|
|
|
|
|
| 305 |
admin = is_admin(profile)
|
| 306 |
if profile is None:
|
| 307 |
status = "Log in with an admin account to enable the controls below."
|
|
@@ -313,7 +318,7 @@ def _gate_admin_controls(
|
|
| 313 |
"set. Controls are disabled."
|
| 314 |
)
|
| 315 |
return (
|
| 316 |
-
gr.Dataframe(interactive=admin),
|
| 317 |
gr.Radio(interactive=admin),
|
| 318 |
gr.Button(interactive=admin),
|
| 319 |
gr.Button(interactive=admin),
|
|
|
|
| 296 |
) -> tuple[gr.Dataframe, gr.Radio, gr.Button, gr.Button, gr.Checkbox, gr.Button, str]:
|
| 297 |
"""Enable the admin controls only for a logged-in user in the admin set.
|
| 298 |
|
| 299 |
+
Runs on every page load and re-runs on LoginButton auth events, so
|
| 300 |
+
the table value is also refreshed from the live Hub data instead of
|
| 301 |
+
staying pinned to whatever rows existed when the Space process
|
| 302 |
+
booted. Non-admins and logged-out visitors get the tab with the
|
| 303 |
+
table read-only and every control disabled, mirroring the server-side
|
| 304 |
re-check in each handler. The delete button always loads disarmed:
|
| 305 |
it only enables once the confirm checkbox is ticked.
|
| 306 |
"""
|
| 307 |
+
admin_df, error = _safe_load_admin()
|
| 308 |
+
if error:
|
| 309 |
+
gr.Warning(f"Admin table unavailable: {error}")
|
| 310 |
admin = is_admin(profile)
|
| 311 |
if profile is None:
|
| 312 |
status = "Log in with an admin account to enable the controls below."
|
|
|
|
| 318 |
"set. Controls are disabled."
|
| 319 |
)
|
| 320 |
return (
|
| 321 |
+
gr.Dataframe(value=admin_df, interactive=admin),
|
| 322 |
gr.Radio(interactive=admin),
|
| 323 |
gr.Button(interactive=admin),
|
| 324 |
gr.Button(interactive=admin),
|
tests/test_proxy.py
CHANGED
|
@@ -211,6 +211,34 @@ def test_safe_load_admin_returns_empty_and_error_on_hub_failure(monkeypatch):
|
|
| 211 |
assert list(admin_df.columns) == leaderboard.ADMIN_COLUMNS
|
| 212 |
|
| 213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
def test_data_error_banner_md_present_on_error_empty_otherwise():
|
| 215 |
"""Banner markdown is non-empty (and names the cause) only on error."""
|
| 216 |
assert app._data_error_banner_md(None) == ""
|
|
|
|
| 211 |
assert list(admin_df.columns) == leaderboard.ADMIN_COLUMNS
|
| 212 |
|
| 213 |
|
| 214 |
+
def test_gate_admin_controls_refreshes_live_table(monkeypatch):
|
| 215 |
+
"""Page/auth load refreshes the admin table, not just interactivity."""
|
| 216 |
+
live_df = pd.DataFrame(
|
| 217 |
+
[
|
| 218 |
+
{
|
| 219 |
+
"select": False,
|
| 220 |
+
"validation_status": "unvalidated",
|
| 221 |
+
"validation_method": None,
|
| 222 |
+
"submission_name": "UC3 e2e test 20260602-205316",
|
| 223 |
+
"submitter_name": "michaelr27",
|
| 224 |
+
"submitted_at": "2026-06-02 19:00 UTC",
|
| 225 |
+
"status": "completed",
|
| 226 |
+
"aggregate_score": 0.5853,
|
| 227 |
+
"submission_id": "uc3-e2e",
|
| 228 |
+
}
|
| 229 |
+
],
|
| 230 |
+
columns=leaderboard.ADMIN_COLUMNS,
|
| 231 |
+
)
|
| 232 |
+
monkeypatch.setattr(app, "_safe_load_admin", lambda: (live_df, None))
|
| 233 |
+
monkeypatch.setattr(app, "is_admin", lambda profile: True)
|
| 234 |
+
|
| 235 |
+
table_update = app._gate_admin_controls(types.SimpleNamespace(username="michaelr27"))[0]
|
| 236 |
+
|
| 237 |
+
assert table_update.value["headers"] == leaderboard.ADMIN_COLUMNS
|
| 238 |
+
assert table_update.value["data"][0][3] == "UC3 e2e test 20260602-205316"
|
| 239 |
+
assert table_update.interactive is True
|
| 240 |
+
|
| 241 |
+
|
| 242 |
def test_data_error_banner_md_present_on_error_empty_otherwise():
|
| 243 |
"""Banner markdown is non-empty (and names the cause) only on error."""
|
| 244 |
assert app._data_error_banner_md(None) == ""
|