FASHIONISTAR CI/CD
🔄 Celery Queues Deploy: 4aae6106b1530c3cc7d7d64f5e3c3e1d5015691d [GitHub Actions]
27c799c | from django.apps import apps | |
| from drf_spectacular.utils import extend_schema | |
| from rest_framework import generics, status | |
| from rest_framework.permissions import IsAuthenticated | |
| from apps.admin_backend.serializers import DeliveryStatusUpdateSerializer | |
| from apps.common.renderers import CustomJSONRenderer | |
| from apps.common.responses import error_response, success_response | |
| def _get_cart_order_model(): | |
| try: | |
| return apps.get_model("store", "CartOrder") | |
| except LookupError: | |
| return None | |
| class DeliveryStatusUpdateView(generics.GenericAPIView): | |
| """ | |
| POST /admin_backend/delivery/<order_id>/update/ | |
| Temporary compatibility endpoint while order ownership migrates to apps/order. | |
| """ | |
| renderer_classes = [CustomJSONRenderer] | |
| serializer_class = DeliveryStatusUpdateSerializer | |
| permission_classes = [IsAuthenticated] | |
| lookup_field = "id" | |
| lookup_url_kwarg = "order_id" | |
| def post(self, request, *args, **kwargs): | |
| CartOrder = _get_cart_order_model() | |
| if CartOrder is None: | |
| return error_response( | |
| message="Delivery status updates are temporarily unavailable while the order domain migration is completing.", | |
| code="order_domain_migration_pending", | |
| status=status.HTTP_503_SERVICE_UNAVAILABLE, | |
| ) | |
| try: | |
| order = CartOrder.objects.get(id=kwargs.get(self.lookup_url_kwarg)) | |
| except CartOrder.DoesNotExist: | |
| return error_response( | |
| message="Order not found.", | |
| code="order_not_found", | |
| status=status.HTTP_404_NOT_FOUND, | |
| ) | |
| serializer = self.get_serializer(data=request.data) | |
| serializer.is_valid(raise_exception=True) | |
| delivery_status = serializer.validated_data.get("delivery_status") | |
| tracking_id = serializer.validated_data.get("tracking_id") | |
| update_fields = [] | |
| if delivery_status: | |
| order.delivery_status = delivery_status | |
| update_fields.append("delivery_status") | |
| if tracking_id: | |
| order.tracking_id = tracking_id | |
| update_fields.append("tracking_id") | |
| if update_fields: | |
| order.save(update_fields=update_fields) | |
| # ── Compliance audit: admin delivery status changes affect escrow release ── | |
| try: | |
| from apps.audit_logs.services.admin_backend import admin_audit | |
| admin_audit.log_admin_action( | |
| actor=request.user, | |
| action_description=( | |
| f"Admin delivery status update: order={kwargs.get(self.lookup_url_kwarg)} " | |
| f"status={delivery_status} tracking={tracking_id}" | |
| ), | |
| resource_type="CartOrder", | |
| resource_id=str(kwargs.get(self.lookup_url_kwarg)), | |
| new_values={ | |
| "delivery_status": delivery_status, | |
| "tracking_id": tracking_id, | |
| }, | |
| request=request, | |
| ) | |
| except Exception: | |
| import logging as _log | |
| _log.getLogger(__name__).warning( | |
| "admin_audit.delivery_status_update failed silently", exc_info=True | |
| ) | |
| return success_response(message="Delivery status updated successfully.") | |