Skip to content

feature/approval-utility-function-v2 - #107

Open
Teja-Sri-Surya wants to merge 31 commits into
Wikimedia-Suomi:mainfrom
Teja-Sri-Surya:feature/approval-utility-function
Open

feature/approval-utility-function-v2#107
Teja-Sri-Surya wants to merge 31 commits into
Wikimedia-Suomi:mainfrom
Teja-Sri-Surya:feature/approval-utility-function

Conversation

@Teja-Sri-Surya

Copy link
Copy Markdown
Contributor

Description

This PR implements a comprehensive utility function for approving/unapproving pending changes revisions using pywikibot's SimpleRequest API, with dry-run mode support and a Django management command for testing.

Changes Made

✅ Core Implementation

  • approve_revision() utility function - Complete API integration with pywikibot
  • Dry-run mode - Safe testing with Merkityt_versiot_-kokeilu/* namespace check
  • Settings configuration - PENDING_CHANGES_DRY_RUN setting for environment control
  • Django management command - test_pending_changes_review for testing

✅ Safety Features

  • Production Safety - Dry-run mode prevents accidental approvals on production pages
  • Test Namespace Support - Allows approvals on Merkityt_versiot_-kokeilu/* pages even in dry-run mode
  • Error Handling - Comprehensive exception handling and logging
  • API Validation - Proper response validation and error reporting

✅ Testing

  • 12 Unit Tests - Comprehensive test coverage for all scenarios
  • Mock Testing - Proper mocking of external dependencies
  • Integration Tests - Settings and configuration tests
  • Edge Cases - Error handling, exceptions, API failures

Technical Details

API Integration

  • Uses pywikibot.data.api.Request (SimpleRequest) for MediaWiki FlaggedRevs API
  • Supports action=review endpoint with proper authentication
  • Handles CSRF tokens and API responses correctly

Dry-Run Logic

if settings.PENDING_CHANGES_DRY_RUN:
    if not page_title.startswith('Merkityt_versiot_-kokeilu/'):
        # Skip actual API call, return dry-run response
        return {'result': 'success', 'dry_run': True}

Management Command Usage

# Test approval
python manage.py test_pending_changes_review --revid 12345 --comment "Test approval"

# Test unapproval  
python manage.py test_pending_changes_review --revid 12345 --unapprove --comment "Test unapproval"

# Test with custom value
python manage.py test_pending_changes_review --revid 12345 --value 1 --comment "Test with value"

Files Added/Modified

New Files

  • app/reviews/utils/approval.py - Core utility function
  • app/reviews/management/commands/test_pending_changes_review.py - Management command
  • app/reviews/tests/test_approval.py - Comprehensive test suite
  • app/reviews/utils/__init__.py - Utils package
  • app/reviews/management/__init__.py - Management package
  • app/reviews/management/commands/__init__.py - Commands package

Modified Files

  • app/reviewer/settings.py - Added PENDING_CHANGES_DRY_RUN setting

Testing

Unit Tests (12 test cases)

  • ✅ Successful approval/unapproval
  • ✅ Dry-run mode with production pages (skips)
  • ✅ Dry-run mode with test pages (proceeds)
  • ✅ Custom value parameter support
  • ✅ API error handling
  • ✅ Exception handling
  • ✅ Page title retrieval
  • ✅ Settings configuration

Management Command Testing

  • ✅ All parameters work correctly
  • ✅ Dry-run mode displays appropriate messages
  • ✅ Error handling and user feedback
  • ✅ Configuration display

Configuration

Environment Variables

# Enable/disable dry-run mode (default: True)
PENDING_CHANGES_DRY_RUN=True

# Set to False for production use
PENDING_CHANGES_DRY_RUN=False

Settings

# In settings.py
PENDING_CHANGES_DRY_RUN = os.getenv("PENDING_CHANGES_DRY_RUN", "True").lower() in ("true", "1", "yes")

Acceptance Criteria Met

  • approve_revision() successfully approves revisions using pywikibot's API
  • unapprove parameter correctly unapproves revisions when set to True
  • ✅ Dry-run mode prevents accidental approvals on non-test pages
  • Merkityt_versiot_-kokeilu/* pages are processed even in dry-run mode
  • ✅ Management command can test both approval and unapproval scenarios
  • ✅ Function returns appropriate success/error responses
  • ✅ All parameters work as documented
  • ✅ Proper logging is implemented for debugging and audit trail

Future Integration

This utility function is designed to be moved to the Pywikibot codebase in the future, as mentioned in the issue description. The current implementation provides a solid foundation for that transition.

Related

- Add revert detection check to autoreview system
- Implement @zache-fi's Superset approach for finding reviewed revisions
- Add change_tag_params to Superset query for revert detection
- Add comprehensive tests for revert detection functionality
- Add ENABLE_REVERT_DETECTION configuration setting
- Parse change tag parameters to extract reverted revision IDs
- Query MediaWiki database for previously reviewed content by SHA1

Fixes Wikimedia-Suomi#3 - Add check for already-reviewed reverted edits
- Implement approve_revision() utility function with pywikibot API integration
- Add PENDING_CHANGES_DRY_RUN setting for safe testing
- Create Django management command test_pending_changes_review
- Add comprehensive unit tests (12 test cases)
- Implement dry-run mode with Merkityt_versiot_-kokeilu/* namespace check
- Add proper error handling and logging
- Support for approve/unapprove operations with custom values

Fixes Wikimedia-Suomi#106
@Teja-Sri-Surya Teja-Sri-Surya changed the title Feature/approval utility function feature/approval-utility-function-final Oct 24, 2025
@Teja-Sri-Surya Teja-Sri-Surya changed the title feature/approval-utility-function-final feature/approval-utility-function-v2 Oct 24, 2025
- Fixed settings.py conflict by combining revert detection, pending changes dry-run, and ORES settings
- Removed old autoreview.py file (replaced by directory structure in PR Wikimedia-Suomi#96)
- Fixed wiki_client.py conflict by keeping statistics functionality
- All conflicts resolved and PR Wikimedia-Suomi#107 should now be ready for review

This resolves the same conflicts as PR Wikimedia-Suomi#108 but for the approval utility function.
@Teja-Sri-Surya

Copy link
Copy Markdown
Contributor Author

✅ Merge Conflicts Resolved!

Hi @zache-fi! I've successfully resolved all merge conflicts with the latest main branch.

What Was Fixed:

  1. Settings Integration - Combined revert detection, pending changes dry-run, and ORES settings
  2. File Structure - Removed old autoreview.py file (replaced by PR Restructure code and add check configuration #96 directory structure)
  3. Statistics Support - Maintained all statistics functionality from PR Feat: Add statistics page #89

Changes Made:

  • app/reviewer/settings.py - Combined all three settings configurations
  • app/reviews/autoreview.py - Removed (replaced by directory structure)
  • app/reviews/services/wiki_client.py - Fixed statistics functionality conflict

Current Status:

  • ✅ All conflicts resolved
  • ✅ Code committed and pushed
  • ✅ Ready for review
  • ✅ All functionality preserved

The PR now includes:

  • Complete approval utility function with pywikibot integration
  • Dry-run mode with Finnish Wikipedia test namespace support
  • Django management command for testing
  • 12 comprehensive unit tests
  • Proper error handling and logging

Ready for final review! 🚀

@Teja-Sri-Surya

Teja-Sri-Surya commented Oct 27, 2025

Copy link
Copy Markdown
Contributor Author

Hi @zache-fi , @ademolaomosanya

Please review this PR. It implements a utility function for approving/unapproving pending changes revisions with pywikibot API integration, dry-run mode support, and 12 comprehensive unit tests. All components are tested and ready for review.

@ademolaomosanya ademolaomosanya added the ready for review Indicates the PR is complete and ready for maintainer review. label Oct 29, 2025
…cleanups, suppress S608 with validated ids)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review Indicates the PR is complete and ready for maintainer review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Utility Function for Approving/Unapproving Pending Changes

2 participants