Spaces:
Paused
Paused
File size: 1,492 Bytes
3143c25 4405ca9 3143c25 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
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())
|