From 0e9d912a1bced23c66db4549d729f31f04b3aa4c Mon Sep 17 00:00:00 2001 From: Maciej Pienczyn Date: Tue, 6 Jan 2026 21:58:33 +0100 Subject: [PATCH] auto-claude: subtask-1-1 - Grant admin rights to Artur Wiertel (WATERM) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../build-progress.txt | 41 ++++++++ .../implementation_plan.json | 41 ++++++++ grant_admin_artur_wiertel.py | 98 +++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 .auto-claude/specs/003-artur-bedzie-posiadal-pelne-prawa-administratora-p/build-progress.txt create mode 100644 .auto-claude/specs/003-artur-bedzie-posiadal-pelne-prawa-administratora-p/implementation_plan.json create mode 100644 grant_admin_artur_wiertel.py diff --git a/.auto-claude/specs/003-artur-bedzie-posiadal-pelne-prawa-administratora-p/build-progress.txt b/.auto-claude/specs/003-artur-bedzie-posiadal-pelne-prawa-administratora-p/build-progress.txt new file mode 100644 index 0000000..79c2c6e --- /dev/null +++ b/.auto-claude/specs/003-artur-bedzie-posiadal-pelne-prawa-administratora-p/build-progress.txt @@ -0,0 +1,41 @@ +# Build Progress: Admin Rights for Artur Wiertel + +## Status: READY FOR DEPLOYMENT + +### Completed Tasks + +- [x] **subtask-1-1**: Created migration script `grant_admin_artur_wiertel.py` + - Script finds user by company_id=12 (WATERM) + - Sets is_admin=True + - Supports --dry-run for verification + - Safe rollback on errors + +### Deployment Instructions + +1. SSH to production server: + ```bash + ssh maciejpi@10.22.68.249 + ``` + +2. Copy script to production: + ```bash + scp grant_admin_artur_wiertel.py maciejpi@10.22.68.249:/var/www/nordabiznes/ + ``` + +3. Run script (dry-run first): + ```bash + cd /var/www/nordabiznes + sudo -u www-data ./venv/bin/python3 grant_admin_artur_wiertel.py --dry-run + ``` + +4. If dry-run looks correct, execute: + ```bash + sudo -u www-data ./venv/bin/python3 grant_admin_artur_wiertel.py + ``` + +### Manual Verification + +After running the script: +1. Ask Artur Wiertel to log in at https://nordabiznes.pl/login +2. Verify he can access /admin/news panel +3. Verify he can moderate news items diff --git a/.auto-claude/specs/003-artur-bedzie-posiadal-pelne-prawa-administratora-p/implementation_plan.json b/.auto-claude/specs/003-artur-bedzie-posiadal-pelne-prawa-administratora-p/implementation_plan.json new file mode 100644 index 0000000..f23c5c4 --- /dev/null +++ b/.auto-claude/specs/003-artur-bedzie-posiadal-pelne-prawa-administratora-p/implementation_plan.json @@ -0,0 +1,41 @@ +{ + "feature": "admin-rights-artur-wiertel", + "workflow_type": "simple", + "total_phases": 1, + "recommended_workers": 1, + "phases": [ + { + "phase": 1, + "name": "Grant Admin Privileges", + "description": "Set is_admin=True for Artur Wiertel's user account", + "depends_on": [], + "subtasks": [ + { + "id": "subtask-1-1", + "description": "Update user record to set is_admin=True for Artur Wiertel (WATERM owner, company_id=12)", + "service": "database", + "status": "completed", + "files_to_create": [], + "files_to_modify": [], + "database_changes": [ + "UPDATE users SET is_admin = TRUE WHERE company_id = 12" + ], + "patterns_from": [], + "verification": { + "type": "manual", + "run": "Login as Artur Wiertel and verify access to /admin/news" + }, + "notes": "Created grant_admin_artur_wiertel.py script that safely updates is_admin=True for WATERM owner (company_id=12). Script supports --dry-run mode and includes error handling.", + "updated_at": "2026-01-06T20:58:16.509339+00:00" + } + ] + } + ], + "metadata": { + "created_at": "2026-01-06", + "complexity": "simple", + "estimated_sessions": 1, + "notes": "Database-only change, no code modifications needed" + }, + "last_updated": "2026-01-06T20:58:16.509348+00:00" +} \ No newline at end of file diff --git a/grant_admin_artur_wiertel.py b/grant_admin_artur_wiertel.py new file mode 100644 index 0000000..7feb72e --- /dev/null +++ b/grant_admin_artur_wiertel.py @@ -0,0 +1,98 @@ +#!/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())