Skip to content

Add admin tool to run spam checks from URLs#13012

Draft
ericholscher wants to merge 2 commits into
mainfrom
claude/admin-spam-action-HdJx1
Draft

Add admin tool to run spam checks from URLs#13012
ericholscher wants to merge 2 commits into
mainfrom
claude/admin-spam-action-HdJx1

Conversation

@ericholscher
Copy link
Copy Markdown
Member

Summary

This PR adds a new Django admin interface tool that allows administrators to queue spam rule checks for projects by pasting URLs directly, rather than having to manually convert URLs to project slugs.

Key Changes

  • New admin view and form: Added SpamRuleChecksFromURLsForm and spam_rule_checks_from_urls_view to ProjectAdmin to accept URLs and trigger spam checks
  • URL parsing utilities: Implemented _normalize_url() and _extract_project_slug_from_url() helper functions that:
    • Handle defanged URLs (hxxps://, [.], (.), etc.)
    • Support both documentation subdomain URLs (https://<slug>.readthedocs.io) and dashboard URLs (https://readthedocs.org/projects/&lt;slug&gt;/)
    • Tolerate messy inputs from automated reports (surrounding brackets, quotes, missing scheme, trailing punctuation)
  • Admin template: Created spam_rule_checks_from_urls.html template to display the form and results
  • Change list integration: Added custom change_list.html template with a link to the new spam checks tool
  • Comprehensive tests: Added test cases covering URL extraction from various formats and the admin view functionality

Implementation Details

  • The URL normalization is tolerant of common patterns seen in abuse reports and emails (markdown links, defanged URLs, surrounding whitespace/punctuation)
  • The view provides detailed feedback on which URLs were successfully matched to projects, which slugs had no matching project, and which URLs could not be parsed
  • Integration with the existing spam_rules_check task from the spamfighting extension with appropriate error handling if the extension is not installed
  • Uses Django's TemplateResponse for the custom admin view to maintain consistency with Django admin patterns

https://claude.ai/code/session_01FydVwRKkb4tzRSwVv6kpFJ

claude added 2 commits April 30, 2026 03:38
Adds a custom admin page where staff can paste URLs for spam projects
and queue spam rule checks for them, without manually converting URLs
to slugs first. Same logic as the existing 'Run spam rule checks'
admin action, just driven by URLs.

Generated by AI.
Normalize defanged URLs (hxxps://, [.], (.)), markdown links, surrounding
brackets/quotes, trailing punctuation, and missing schemes so URLs pasted
straight from automated abuse reports resolve to project slugs.

Generated by AI.
content = resp.content.decode()
assert self.project.slug in content
assert "no-such-project-slug" in content
assert "example.com" in content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants