limit max number of users

This commit is contained in:
Davide Scaini
2026-04-10 12:35:34 +02:00
parent cbac82a2ba
commit 683b7d9c1b
4 changed files with 62 additions and 3 deletions
+10 -2
View File
@@ -17,13 +17,14 @@ console = Console()
@click.option("--password", required=True, hide_input=True, confirmation_prompt=True, help="Admin password")
@click.option("--display-name", default="", help="Admin display name (defaults to handle)")
@click.option("--name", default="", help="Instance name shown in the feed")
def init(data_dir: str, handle: str, password: str, display_name: str, name: str) -> None:
@click.option("--max-users", default=0, type=int, help="Maximum number of users allowed (0 = unlimited)")
def init(data_dir: str, handle: str, password: str, display_name: str, name: str, max_users: int) -> None:
"""Bootstrap a fresh bincio multi-user instance.
Creates the SQLite database, the admin user, the per-user data directory,
and prints a first invite code. Safe to re-run — skips steps already done.
"""
from bincio.serve.db import create_invite, create_user, get_user, open_db
from bincio.serve.db import create_invite, create_user, get_user, open_db, set_setting
dd = Path(data_dir).expanduser().resolve()
dd.mkdir(parents=True, exist_ok=True)
@@ -67,6 +68,13 @@ def init(data_dir: str, handle: str, password: str, display_name: str, name: str
else:
console.print(" [yellow]·[/yellow] root index.json already exists — skipping")
# ── User limit ────────────────────────────────────────────────────────────
if max_users > 0:
set_setting(db, "max_users", str(max_users))
console.print(f" [green]✓[/green] user limit set to {max_users}")
else:
console.print(" [dim]·[/dim] no user limit (unlimited)")
# ── First invite code ─────────────────────────────────────────────────────
code = create_invite(db, handle)