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:
@@ -13,7 +13,7 @@ from django.http import (
|
||||
)
|
||||
from django.views.generic import DetailView
|
||||
|
||||
from .models import EditSubmission, PhotoSubmission, UserType
|
||||
from .models import EditSubmission, UserType
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
@@ -146,6 +146,8 @@ class EditSubmissionMixin(DetailView):
|
||||
class PhotoSubmissionMixin(DetailView):
|
||||
"""
|
||||
Mixin for handling photo submissions with proper moderation.
|
||||
|
||||
Photos are now handled via EditSubmission with submission_type='PHOTO'.
|
||||
"""
|
||||
|
||||
model: type[models.Model] | None = None
|
||||
@@ -177,19 +179,25 @@ class PhotoSubmissionMixin(DetailView):
|
||||
|
||||
content_type = ContentType.objects.get_for_model(obj)
|
||||
|
||||
submission = PhotoSubmission(
|
||||
# Create EditSubmission with PHOTO type
|
||||
submission = EditSubmission(
|
||||
user=request.user,
|
||||
content_type=content_type,
|
||||
object_id=getattr(obj, "id", None),
|
||||
submission_type="PHOTO",
|
||||
changes={}, # No field changes for photos
|
||||
photo=request.FILES["photo"],
|
||||
caption=request.POST.get("caption", ""),
|
||||
date_taken=request.POST.get("date_taken"),
|
||||
reason="Photo submission",
|
||||
)
|
||||
|
||||
# Auto-approve for moderators and above
|
||||
user_role = getattr(request.user, "role", None)
|
||||
if user_role in ["MODERATOR", "ADMIN", "SUPERUSER"]:
|
||||
submission.auto_approve()
|
||||
submission.save()
|
||||
submission.claim(user=request.user)
|
||||
submission.approve(cast(UserType, request.user))
|
||||
return JsonResponse(
|
||||
{
|
||||
"status": "success",
|
||||
|
||||
Reference in New Issue
Block a user