Spaces:
3SCError404
/
Paused

nexus / scripts /scrub_roles.py
dushyantsingh0
backend stabilization
4405ca9
Raw History Blame Contribute Delete
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())