nordabiz/grant_admin_artur_wiertel.py
Maciej Pienczyn 0e9d912a1b auto-claude: subtask-1-1 - Grant admin rights to Artur Wiertel (WATERM)
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>
2026-01-06 21:58:33 +01:00

99 lines
2.7 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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())