46 lines
No EOL
1.3 KiB
Python
46 lines
No EOL
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Simple script to promote a user to admin status in the AgentHub database.
|
|
"""
|
|
import asyncio
|
|
import sys
|
|
from motor.motor_asyncio import AsyncIOMotorClient
|
|
from dotenv import load_dotenv
|
|
import os
|
|
|
|
load_dotenv()
|
|
|
|
MONGODB_URI = os.getenv("MONGODB_URI", "mongodb://localhost:27017")
|
|
MONGODB_DBNAME = os.getenv("MONGODB_DBNAME", "agenthub_db")
|
|
|
|
async def make_user_admin(email: str):
|
|
"""Promote a user to admin status by email"""
|
|
client = AsyncIOMotorClient(MONGODB_URI)
|
|
db = client[MONGODB_DBNAME]
|
|
users_collection = db.get_collection("users")
|
|
|
|
# Find and update the user
|
|
result = await users_collection.update_one(
|
|
{"email": email},
|
|
{"$set": {"is_admin": True}}
|
|
)
|
|
|
|
if result.modified_count > 0:
|
|
print(f"✅ Successfully promoted {email} to admin status")
|
|
|
|
# Verify the update
|
|
user = await users_collection.find_one({"email": email})
|
|
if user:
|
|
print(f"User details: {user['full_name']} ({email}) - Admin: {user['is_admin']}")
|
|
else:
|
|
print(f"❌ User {email} not found or already an admin")
|
|
|
|
client.close()
|
|
|
|
if __name__ == "__main__":
|
|
email = "admin@agenthub.com"
|
|
if len(sys.argv) > 1:
|
|
email = sys.argv[1]
|
|
|
|
print(f"Promoting {email} to admin status...")
|
|
asyncio.run(make_user_admin(email)) |