Spaces:
Paused
Paused
Download scripts/scrub_roles.py from 3SCError404/miracle: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/3SCError404/miracle/resolve/main/scripts/scrub_roles.py
- Command line
-
hf download hf://spaces/3SCError404/miracle/scripts/scrub_roles.py
-
curl -L -o scrub_roles.py https://huggingface.co/spaces/3SCError404/miracle/resolve/main/scripts/scrub_roles.py
1.49 kB
| import asyncio | |
| from sqlalchemy import select | |
| from core.database import async_session_factory | |
| from core.config import get_settings | |
| from models.user import User, UserRole | |
| async def scrub_roles(): | |
| settings = get_settings() | |
| super_email = settings.SUPER_ADMIN_EMAIL.lower() | |
| async with async_session_factory() as db: | |
| print(f"Target Super Admin Email: {super_email}") | |
| # 1. Fetch all users with any global role | |
| stmt = select(User).where(User.global_role.isnot(None)) | |
| res = await db.execute(stmt) | |
| users = res.scalars().all() | |
| print(f"Found {len(users)} users with global_role.") | |
| for user in users: | |
| old_role = user.global_role | |
| if user.email.lower() == super_email: | |
| user.global_role = UserRole.SUPERADMIN | |
| print(f"UPGRADING {user.email}: {old_role} -> {user.global_role}") | |
| else: | |
| user.global_role = None | |
| print(f"CLEANING {user.email}: {old_role} -> None (Local Only)") | |
| db.add(user) | |
| # 2. Ensure non-super admins have local roles if they were global admins | |
| # Admin A (admin@a.com) should definitely have SC_ADMIN locally in their workspace. | |
| # This is already true based on previous inspect_db, but let's confirm. | |
| await db.commit() | |
| print("Scrubbing complete.") | |
| if __name__ == "__main__": | |
| asyncio.run(scrub_roles()) | |