diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-08-28 03:43:29 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-08-28 03:43:29 +0200 |
| commit | 2f573b4143212b21d92ff20179356acb8f8fe635 (patch) | |
| tree | ce0c4ff78044a56c0882d7ba94fbea436f0e83c3 /packages/meshbay-hub/src/meshbay_hub/hub_settings.py | |
| parent | e1f1b65cfac031096e4bae24ccf102ca0dbb86d9 (diff) | |
| parent | b5b4f188a39fc96c4d32e67151e067b1add6dcfc (diff) | |
| download | meshbay-2f573b4143212b21d92ff20179356acb8f8fe635.tar.gz | |
Merge branch 'feat/hub-disable-public-groups'
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/hub_settings.py')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/hub_settings.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/hub_settings.py b/packages/meshbay-hub/src/meshbay_hub/hub_settings.py new file mode 100644 index 0000000..280d1e2 --- /dev/null +++ b/packages/meshbay-hub/src/meshbay_hub/hub_settings.py @@ -0,0 +1,44 @@ +""" +Instance-wide settings stored in the `hub_settings` table. + +One reader per concern, so callers never touch raw strings or key names. A +missing row means the built-in default — an upgrade never changes behaviour on +its own, and a downgrade that drops the table just returns to defaults. +""" + +from sqlalchemy.ext.asyncio import AsyncSession + +from meshbay_hub.db.models import HubSetting + +# Whether a member may create a group that is listed in the public directory and +# open for anyone to join. Off makes the hub private-groups-only. +ALLOW_PUBLIC_GROUPS = "allow_public_groups" + +_DEFAULTS: dict[str, str] = { + ALLOW_PUBLIC_GROUPS: "true", +} + + +async def get_raw(db: AsyncSession, key: str) -> str | None: + row = await db.get(HubSetting, key) + return row.value if row else None + + +async def set_raw(db: AsyncSession, key: str, value: str) -> None: + """Upsert. The caller owns the commit.""" + row = await db.get(HubSetting, key) + if row: + row.value = value + else: + db.add(HubSetting(key=key, value=value)) + + +async def get_bool(db: AsyncSession, key: str) -> bool: + raw = await get_raw(db, key) + if raw is None: + raw = _DEFAULTS.get(key, "false") + return raw == "true" + + +async def public_groups_allowed(db: AsyncSession) -> bool: + return await get_bool(db, ALLOW_PUBLIC_GROUPS) |