diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-09-15 02:16:39 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-09-15 02:21:01 +0200 |
| commit | 73ad8e4eb566fe682107fa7e50ef624591199e99 (patch) | |
| tree | ff0017d014d46d8835487c080dca55c6def7fd6b /packages/meshbay-hub/src/meshbay_hub/api/admin.py | |
| parent | bdefcd025604f2c3009fe5e0cc01213c2ba62a6a (diff) | |
| download | meshbay-73ad8e4eb566fe682107fa7e50ef624591199e99.tar.gz | |
feat(hub): session lifetime is an admin setting, and a browser signs out when idle
Browser idle sign-out (media playback counts as activity; not the desktop app),
refresh idle window and maximum session length, in hours. Sign-out now revokes
on the hub, and the profile has "sign out everywhere".
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XuNrwLf5EFWCMHzfoEvnpm
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/api/admin.py')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/api/admin.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/api/admin.py b/packages/meshbay-hub/src/meshbay_hub/api/admin.py index 397b4d9..7ca1e68 100644 --- a/packages/meshbay-hub/src/meshbay_hub/api/admin.py +++ b/packages/meshbay-hub/src/meshbay_hub/api/admin.py @@ -42,6 +42,8 @@ class SettingsPatchRequest(BaseModel): mail: dict[str, int] | None = None # The sign-in lockout's two numbers, each optional, as for mail. login: dict[str, int] | None = None + # Session lifetime, in hours, each optional. + session: dict[str, int] | None = None # ── Instance settings ──────────────────────────────────────────────────────── @@ -59,6 +61,9 @@ async def _settings_payload(db: AsyncSession) -> dict: "login": await hub_settings.login_limits(db), "login_defaults": dict(hub_settings.LOGIN_DEFAULTS), "login_bounds": {k: list(v) for k, v in hub_settings.LOGIN_BOUNDS.items()}, + "session": await hub_settings.session_limits(db), + "session_defaults": dict(hub_settings.SESSION_DEFAULTS), + "session_bounds": {k: list(v) for k, v in hub_settings.SESSION_BOUNDS.items()}, } @@ -138,6 +143,26 @@ async def admin_patch_settings( )) await db.commit() + if body.session: + unknown = sorted(set(body.session) - set(hub_settings.SESSION_KEYS)) + if unknown: + raise HTTPException( + status_code=422, detail=f"Unknown session setting(s): {unknown}") + changed = [] + for key, value in body.session.items(): + clamped = hub_settings.clamp_session_value(key, value) + await hub_settings.set_raw(db, f"session.{key}", str(clamped)) + changed.append(f"{key}={clamped}") + log.info("Session lifetime changed by %s: %s", + current_user.username, ", ".join(changed)) + db.add(IPLog( + user_id=current_user.id, + event="admin_session_update", + ip_address="admin", + detail=", ".join(changed)[:255], + )) + await db.commit() + return await _settings_payload(db) |