diff --git a/.gitignore b/.gitignore index 19202d12..a5c57bc2 100644 --- a/.gitignore +++ b/.gitignore @@ -206,8 +206,8 @@ marimo/_static/ marimo/_lsp/ __marimo__/ -# Claude Code (local settings with permissions/tokens) -.claude/settings.local.json +# Claude Code (local config, agents, settings) +.claude/ # Railway CLI (local tooling) node_modules/ diff --git a/backend/make_superadmin.py b/backend/make_superadmin.py new file mode 100644 index 00000000..098e32df --- /dev/null +++ b/backend/make_superadmin.py @@ -0,0 +1,73 @@ +"""Script to promote a user to super admin.""" +import asyncio +import sys +from sqlalchemy import select +from app.core.database import async_session_maker + +# Import models to ensure they're registered +import app.models.user +import app.models.tree +import app.models.account +from app.models.user import User + + +async def make_super_admin(email: str): + """Promote a user to super admin by email.""" + async with async_session_maker() as db: + result = await db.execute(select(User).where(User.email == email)) + user = result.scalar_one_or_none() + + if not user: + print(f"āŒ User not found: {email}") + return False + + if user.is_super_admin: + print(f"āœ… {email} is already a super admin") + return True + + user.is_super_admin = True + await db.commit() + print(f"āœ… {email} promoted to super admin") + return True + + +async def list_users(): + """List all users and their admin status.""" + async with async_session_maker() as db: + result = await db.execute( + select(User.email, User.is_super_admin, User.is_active) + .order_by(User.created_at) + ) + users = result.all() + + if not users: + print("No users found") + return + + print("\nšŸ“‹ Current users:") + print("-" * 60) + for email, is_super_admin, is_active in users: + admin_badge = "šŸ”‘ SUPER ADMIN" if is_super_admin else "" + active_badge = "āœ…" if is_active else "āŒ INACTIVE" + print(f"{active_badge} {email:40} {admin_badge}") + print("-" * 60) + + +async def main(): + if len(sys.argv) < 2: + print("Usage:") + print(" python make_superadmin.py list - List all users") + print(" python make_superadmin.py - Promote user to super admin") + sys.exit(1) + + command = sys.argv[1] + + if command == "list": + await list_users() + else: + email = command + await make_super_admin(email) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/backend/make_superadmin_simple.py b/backend/make_superadmin_simple.py new file mode 100644 index 00000000..5702bf21 --- /dev/null +++ b/backend/make_superadmin_simple.py @@ -0,0 +1,73 @@ +"""Simple script to promote a user to super admin using raw SQL.""" +import asyncio +import sys +from sqlalchemy import text +from app.core.database import engine + + +async def make_super_admin(email: str): + """Promote a user to super admin by email.""" + async with engine.begin() as conn: + # Check if user exists + result = await conn.execute( + text("SELECT email, is_super_admin FROM users WHERE email = :email"), + {"email": email} + ) + row = result.fetchone() + + if not row: + print(f"[X] User not found: {email}") + return False + + if row[1]: # is_super_admin + print(f"[OK] {email} is already a super admin") + return True + + # Promote to super admin + await conn.execute( + text("UPDATE users SET is_super_admin = TRUE WHERE email = :email"), + {"email": email} + ) + print(f"[OK] {email} promoted to super admin") + return True + + +async def list_users(): + """List all users and their admin status.""" + async with engine.connect() as conn: + result = await conn.execute( + text("SELECT email, is_super_admin, is_active FROM users ORDER BY created_at") + ) + rows = result.fetchall() + + if not rows: + print("No users found") + return + + print("\nCurrent users:") + print("-" * 70) + for email, is_super_admin, is_active in rows: + admin_badge = "[SUPER ADMIN]" if is_super_admin else "" + active_badge = "[ACTIVE]" if is_active else "[INACTIVE]" + print(f"{active_badge:12} {email:40} {admin_badge}") + print("-" * 60) + + +async def main(): + if len(sys.argv) < 2: + print("Usage:") + print(" python make_superadmin_simple.py list - List all users") + print(" python make_superadmin_simple.py - Promote user to super admin") + sys.exit(1) + + command = sys.argv[1] + + if command == "list": + await list_users() + else: + email = command + await make_super_admin(email) + + +if __name__ == "__main__": + asyncio.run(main())