Spaces:
Running
Running
Download backend/grant_admin.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 2.14 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/grant_admin.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/grant_admin.py
-
curl -L -o grant_admin.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/grant_admin.py
2.14 kB
| import asyncio | |
| from sqlmodel import select | |
| from app.core.database import async_session_maker | |
| from app.models.user import User | |
| from app.models.tenant import Tenant | |
| TARGET_EMAIL = "axeroni.s2@gmail.com" | |
| DEFAULT_PASSWORD = "ChangeMe123!" | |
| async def grant_admin(): | |
| print(f"π Granting Admin Access to {TARGET_EMAIL}...") | |
| async with async_session_maker() as session: | |
| try: | |
| # 1. Check if user exists | |
| result = await session.execute(select(User).where(User.email == TARGET_EMAIL)) | |
| user = result.scalar_one_or_none() | |
| if user: | |
| print(f"β User found: {user.id}") | |
| user.is_superuser = True | |
| user.role = "OWNER" | |
| session.add(user) | |
| await session.commit() | |
| print("π User promoted to SUPERUSER!") | |
| else: | |
| print("β οΈ User not found. Creating new...") | |
| # 2. Find a tenant to link to | |
| t_result = await session.execute(select(Tenant)) | |
| tenant = t_result.scalars().first() | |
| if not tenant: | |
| print("β No Tenants found! Cannot create user without a tenant.") | |
| return | |
| print(f"π Linking to Tenant: {tenant.name} ({tenant.id})") | |
| # 3. Create User | |
| hashed = User.get_password_hash(DEFAULT_PASSWORD) | |
| new_user = User( | |
| email=TARGET_EMAIL, | |
| hashed_password=hashed, | |
| tenant_id=tenant.id, | |
| role="OWNER", | |
| is_superuser=True, | |
| full_name="Admin User" | |
| ) | |
| session.add(new_user) | |
| await session.commit() | |
| print(f"π Created new Admin User. Password: {DEFAULT_PASSWORD}") | |
| except Exception as e: | |
| print(f"β Error: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| if __name__ == "__main__": | |
| asyncio.run(grant_admin()) | |