views.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from rest_framework import exceptions, viewsets
  2. from rest_framework.decorators import action
  3. from rest_framework.response import Response
  4. from apps.files.tasks import assemble_artifacts_task
  5. from apps.organizations_ext.models import Organization
  6. from .models import Release
  7. from .permissions import ReleasePermission
  8. from .serializers import (
  9. AssembleSerializer,
  10. ReleaseSerializer,
  11. )
  12. class ReleaseViewSet(viewsets.ModelViewSet):
  13. """
  14. /organizations/<org-slug>/releases/
  15. Sentry includes only project name and slug in nested list. This view uses ProjectReferenceSerializer,
  16. which also includes id and platform, for consistency.
  17. """
  18. queryset = Release.objects.all()
  19. serializer_class = ReleaseSerializer
  20. permission_classes = [ReleasePermission]
  21. lookup_field = "version"
  22. lookup_value_regex = "[^/]+"
  23. def get_organization(self):
  24. try:
  25. return Organization.objects.get(
  26. slug=self.kwargs.get("organization_slug"),
  27. users=self.request.user,
  28. )
  29. except Organization.DoesNotExist:
  30. raise exceptions.ValidationError("Organization does not exist")
  31. @action(detail=True, methods=["post"])
  32. def assemble(self, request, organization_slug: str, version: str):
  33. organization = self.get_organization()
  34. # release = self.get_object()
  35. serializer = AssembleSerializer(data=request.data)
  36. serializer.is_valid(raise_exception=True)
  37. checksum = serializer.validated_data.get("checksum", None)
  38. chunks = serializer.validated_data.get("chunks", [])
  39. assemble_artifacts_task.delay(
  40. org_id=organization.id,
  41. version=version,
  42. checksum=checksum,
  43. chunks=chunks,
  44. )
  45. # TODO should return more state's
  46. return Response({"state": "ok", "missingChunks": []})