|
2 | 2 |
|
3 | 3 | # Check if openedx-authz package is installed |
4 | 4 | if python -c "import pkg_resources; pkg_resources.require('openedx-authz')" 2>/dev/null; then |
5 | | - ./manage.py lms load_policies |
| 5 | + echo "================================================================================" |
| 6 | + echo "Starting openedx-authz initialization tasks" |
| 7 | + echo "================================================================================" |
| 8 | + |
| 9 | + # Step 1: Setup mock data for migration testing |
| 10 | + echo "" |
| 11 | + echo "[1/6] Setting up mock migration test data..." |
| 12 | + echo "--------------------------------------------------------------------------------" |
| 13 | + if ./manage.py lms mock_migrate setup 2>&1; then |
| 14 | + echo "✓ Mock migration test data setup completed successfully" |
| 15 | + else |
| 16 | + EXIT_CODE=$? |
| 17 | + echo "✗ FAILED: Mock migration test data setup failed with exit code ${EXIT_CODE}" |
| 18 | + echo "This may be because the data already exists or there's a configuration issue." |
| 19 | + echo "Continuing with migration anyway..." |
| 20 | + fi |
| 21 | + |
| 22 | + # Step 2: Run the legacy permissions migration |
| 23 | + echo "" |
| 24 | + echo "[2/6] Running legacy permissions migration (openedx_authz 0005)..." |
| 25 | + echo "--------------------------------------------------------------------------------" |
| 26 | + echo "This migration will convert legacy ContentLibraryPermission entries to the new authz model." |
| 27 | + echo "" |
| 28 | + if ./manage.py lms migrate openedx_authz 0005_migrate_legacy_permissions 2>&1; then |
| 29 | + echo "" |
| 30 | + echo "✓ Legacy permissions migration completed" |
| 31 | + else |
| 32 | + EXIT_CODE=$? |
| 33 | + echo "" |
| 34 | + echo "✗ CRITICAL: Migration failed with exit code ${EXIT_CODE}" |
| 35 | + echo "Please review the error messages above for details." |
| 36 | + echo "The migration may have partially completed - check the database state." |
| 37 | + exit ${EXIT_CODE} |
| 38 | + fi |
| 39 | + |
| 40 | + # Step 3: Verify the migration results |
| 41 | + echo "" |
| 42 | + echo "[3/6] Verifying migration results..." |
| 43 | + echo "--------------------------------------------------------------------------------" |
| 44 | + if ./manage.py lms mock_migrate verify 2>&1; then |
| 45 | + echo "✓ Migration verification passed - all permissions migrated correctly" |
| 46 | + else |
| 47 | + EXIT_CODE=$? |
| 48 | + echo "✗ WARNING: Migration verification failed with exit code ${EXIT_CODE}" |
| 49 | + echo "The migration completed but the verification checks failed." |
| 50 | + echo "This could indicate:" |
| 51 | + echo " - Permissions were not migrated correctly" |
| 52 | + echo " - Test data is missing or corrupted" |
| 53 | + echo " - There's an issue with the verification logic" |
| 54 | + echo "Please review the verification output above." |
| 55 | + echo "Continuing with cleanup..." |
| 56 | + fi |
| 57 | + |
| 58 | + # Step 4: Cleanup mock data |
| 59 | + echo "" |
| 60 | + echo "[4/6] Cleaning up mock migration test data..." |
| 61 | + echo "--------------------------------------------------------------------------------" |
| 62 | + if ./manage.py lms mock_migrate cleanup 2>&1; then |
| 63 | + echo "✓ Mock migration test data cleaned up successfully" |
| 64 | + else |
| 65 | + EXIT_CODE=$? |
| 66 | + echo "✗ WARNING: Cleanup failed with exit code ${EXIT_CODE}" |
| 67 | + echo "Some test data may remain in the database." |
| 68 | + echo "This won't affect production but may cause issues if you run the test again." |
| 69 | + echo "Consider manually cleaning up test objects with prefix 'tmlp_'" |
| 70 | + fi |
| 71 | + |
| 72 | + # Step 5: Load authz policies |
| 73 | + echo "" |
| 74 | + echo "[5/6] Loading authz policies..." |
| 75 | + echo "--------------------------------------------------------------------------------" |
| 76 | + if ./manage.py lms load_policies 2>&1; then |
| 77 | + echo "✓ Authz policies loaded successfully" |
| 78 | + else |
| 79 | + EXIT_CODE=$? |
| 80 | + echo "✗ CRITICAL: Policy loading failed with exit code ${EXIT_CODE}" |
| 81 | + echo "The system may not function correctly without policies loaded." |
| 82 | + exit ${EXIT_CODE} |
| 83 | + fi |
| 84 | + |
| 85 | + # Summary |
| 86 | + echo "" |
| 87 | + echo "================================================================================" |
| 88 | + echo "[6/6] openedx-authz initialization completed" |
| 89 | + echo "================================================================================" |
| 90 | + echo "" |
| 91 | + echo "Summary:" |
| 92 | + echo " ✓ Migration setup, execution, verification, and cleanup completed" |
| 93 | + echo " ✓ Policies loaded" |
| 94 | + echo "" |
| 95 | + echo "If you saw any warnings or errors above, please review them carefully." |
| 96 | + echo "The system should now be ready to use with the new authz model." |
| 97 | + echo "================================================================================" |
| 98 | + |
6 | 99 | else |
7 | 100 | echo "Warning: openedx-authz package is not installed. Skipping policy loading." |
8 | 101 | exit 0 |
|
0 commit comments