Created migration script grant_admin_artur_wiertel.py that: - Finds user by company_id=12 (WATERM) - Sets is_admin=True for the user - Supports --dry-run mode for verification - Includes error handling and rollback To deploy: Run script on production server with www-data user. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
99 lines
2.7 KiB
Python
99 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
Grant admin rights to Artur Wiertel (WATERM owner, company_id=12)
|
||
|
||
This script updates the is_admin field to True for the user associated
|
||
with WATERM company.
|
||
|
||
Usage:
|
||
python grant_admin_artur_wiertel.py [--dry-run]
|
||
|
||
Options:
|
||
--dry-run Show what would be changed without making changes
|
||
"""
|
||
|
||
import sys
|
||
from database import SessionLocal, User, Company
|
||
|
||
|
||
def grant_admin_to_waterm_owner(dry_run=False):
|
||
"""Grant admin rights to WATERM owner (company_id=12)"""
|
||
|
||
session = SessionLocal()
|
||
|
||
try:
|
||
# First, verify the company exists
|
||
company = session.query(Company).filter(Company.id == 12).first()
|
||
if not company:
|
||
print("❌ Error: Company with id=12 not found")
|
||
return False
|
||
|
||
print(f"✅ Found company: {company.name} (NIP: {company.nip})")
|
||
|
||
# Find the user associated with this company
|
||
user = session.query(User).filter(User.company_id == 12).first()
|
||
|
||
if not user:
|
||
print(f"❌ Error: No user found for company_id=12 ({company.name})")
|
||
print(" Please ensure the user account exists before granting admin rights.")
|
||
return False
|
||
|
||
print(f"✅ Found user: {user.name} ({user.email})")
|
||
print(f" Current admin status: {user.is_admin}")
|
||
|
||
if user.is_admin:
|
||
print("ℹ️ User already has admin rights. No changes needed.")
|
||
return True
|
||
|
||
if dry_run:
|
||
print("\n[DRY RUN] Would set is_admin=True for this user")
|
||
print("[DRY RUN] No changes made to database")
|
||
return True
|
||
|
||
# Grant admin rights
|
||
user.is_admin = True
|
||
session.commit()
|
||
|
||
print(f"\n✅ Successfully granted admin rights to {user.name}")
|
||
print(f" Email: {user.email}")
|
||
print(f" Company: {company.name}")
|
||
print(f" Admin status: {user.is_admin}")
|
||
|
||
return True
|
||
|
||
except Exception as e:
|
||
session.rollback()
|
||
print(f"❌ Error: {e}")
|
||
return False
|
||
|
||
finally:
|
||
session.close()
|
||
|
||
|
||
def main():
|
||
dry_run = '--dry-run' in sys.argv
|
||
|
||
print("=" * 60)
|
||
print("Grant Admin Rights - Artur Wiertel (WATERM)")
|
||
print("=" * 60)
|
||
|
||
if dry_run:
|
||
print("\n🔍 DRY RUN MODE - No changes will be made\n")
|
||
|
||
success = grant_admin_to_waterm_owner(dry_run=dry_run)
|
||
|
||
if success:
|
||
print("\n✅ Operation completed successfully")
|
||
if not dry_run:
|
||
print("\nNext steps:")
|
||
print("1. Ask Artur to log in at https://nordabiznes.pl/login")
|
||
print("2. Verify access to /admin/news panel")
|
||
return 0
|
||
else:
|
||
print("\n❌ Operation failed")
|
||
return 1
|
||
|
||
|
||
if __name__ == '__main__':
|
||
sys.exit(main())
|