mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-02-05 16:35:18 -05:00
Add @extend_schema decorators to moderation ViewSet actions
- Add drf_spectacular imports (extend_schema, OpenApiResponse, inline_serializer) - Annotate claim action with response schemas for 200/404/409/400 - Annotate unclaim action with response schemas for 200/403/400 - Annotate approve action with request=None and response schemas - Annotate reject action with reason request body schema - Annotate escalate action with reason request body schema - All actions tagged with 'Moderation' for API docs grouping
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
Signal handlers for moderation-related FSM state transitions.
|
||||
|
||||
This module provides signal handlers that execute when moderation
|
||||
models (EditSubmission, PhotoSubmission, ModerationReport, etc.)
|
||||
models (EditSubmission, ModerationReport, etc.)
|
||||
undergo state transitions.
|
||||
|
||||
Includes:
|
||||
@@ -114,6 +114,7 @@ def handle_submission_rejected(instance, source, target, user, context=None, **k
|
||||
Handle submission rejection transitions.
|
||||
|
||||
Called when an EditSubmission or PhotoSubmission is rejected.
|
||||
For photo submissions, queues Cloudflare image cleanup to prevent orphaned assets.
|
||||
|
||||
Args:
|
||||
instance: The submission instance.
|
||||
@@ -130,6 +131,19 @@ def handle_submission_rejected(instance, source, target, user, context=None, **k
|
||||
f"Submission {instance.pk} rejected by {user if user else 'system'}" f"{f': {reason}' if reason else ''}"
|
||||
)
|
||||
|
||||
# Cleanup Cloudflare image for rejected photo submissions
|
||||
if getattr(instance, "submission_type", None) == "PHOTO" and instance.photo:
|
||||
try:
|
||||
from apps.moderation.tasks import cleanup_cloudflare_image
|
||||
|
||||
# Get image ID from the CloudflareImage model
|
||||
image_id = getattr(instance.photo, "image_id", None) or str(instance.photo.id)
|
||||
if image_id:
|
||||
cleanup_cloudflare_image.delay(image_id)
|
||||
logger.info(f"Queued Cloudflare image cleanup for rejected submission {instance.pk}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to queue Cloudflare image cleanup for submission {instance.pk}: {e}")
|
||||
|
||||
|
||||
def handle_submission_escalated(instance, source, target, user, context=None, **kwargs):
|
||||
"""
|
||||
@@ -377,18 +391,13 @@ def register_moderation_signal_handlers():
|
||||
EditSubmission,
|
||||
ModerationQueue,
|
||||
ModerationReport,
|
||||
PhotoSubmission,
|
||||
)
|
||||
|
||||
# EditSubmission handlers
|
||||
# EditSubmission handlers (handles both EDIT and PHOTO types now)
|
||||
register_transition_handler(EditSubmission, "*", "APPROVED", handle_submission_approved, stage="post")
|
||||
register_transition_handler(EditSubmission, "*", "REJECTED", handle_submission_rejected, stage="post")
|
||||
register_transition_handler(EditSubmission, "*", "ESCALATED", handle_submission_escalated, stage="post")
|
||||
|
||||
# PhotoSubmission handlers
|
||||
register_transition_handler(PhotoSubmission, "*", "APPROVED", handle_submission_approved, stage="post")
|
||||
register_transition_handler(PhotoSubmission, "*", "REJECTED", handle_submission_rejected, stage="post")
|
||||
register_transition_handler(PhotoSubmission, "*", "ESCALATED", handle_submission_escalated, stage="post")
|
||||
|
||||
# ModerationReport handlers
|
||||
register_transition_handler(ModerationReport, "*", "RESOLVED", handle_report_resolved, stage="post")
|
||||
@@ -403,9 +412,6 @@ def register_moderation_signal_handlers():
|
||||
register_transition_handler(EditSubmission, "PENDING", "CLAIMED", handle_submission_claimed, stage="post")
|
||||
register_transition_handler(EditSubmission, "CLAIMED", "PENDING", handle_submission_unclaimed, stage="post")
|
||||
|
||||
# Claim/Unclaim handlers for PhotoSubmission
|
||||
register_transition_handler(PhotoSubmission, "PENDING", "CLAIMED", handle_submission_claimed, stage="post")
|
||||
register_transition_handler(PhotoSubmission, "CLAIMED", "PENDING", handle_submission_unclaimed, stage="post")
|
||||
|
||||
logger.info("Registered moderation signal handlers")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user