SIP_GoldBees_Backend/backend/promote_super_admin.py
Thigazhezhilan J 5f29d8c757 admin_page
2026-03-26 00:17:40 +05:30

41 lines
1.1 KiB
Python

import argparse
import sys
from app.services.auth_service import get_user_by_username
from app.services.db import db_connection
def promote_user(email: str) -> int:
user = get_user_by_username(email)
if not user:
print(f"User not found: {email}", file=sys.stderr)
return 1
with db_connection() as conn:
with conn:
with conn.cursor() as cur:
cur.execute(
"""
UPDATE app_user
SET role = 'SUPER_ADMIN',
is_admin = TRUE,
is_super_admin = TRUE
WHERE id = %s
""",
(user["id"],),
)
print(f"Promoted {email} to SUPER_ADMIN")
return 0
def main() -> int:
parser = argparse.ArgumentParser(description="Promote an existing user to SUPER_ADMIN.")
parser.add_argument("email", help="User email to promote")
args = parser.parse_args()
return promote_user(args.email.strip())
if __name__ == "__main__":
raise SystemExit(main())