Skip to content
This repository has been archived by the owner on Oct 28, 2019. It is now read-only.

Commit

Permalink
Stop deletion of content unit used by repo version
Browse files Browse the repository at this point in the history
You should not be able to delete a unit of content that is used by a
repo version so that ability has been removed.

fixes #3418
https://pulp.plan.io/issues/3418
  • Loading branch information
CodeHeeler authored and daviddavis committed Mar 20, 2018
1 parent 7cdf69f commit f30561a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pulpcore/pulpcore/app/viewsets/content.py
Expand Up @@ -6,7 +6,7 @@
from rest_framework.response import Response


from pulpcore.app.models import Artifact, Content, ContentArtifact
from pulpcore.app.models import Artifact, Content, ContentArtifact, RepositoryContent
from pulpcore.app.serializers import ArtifactSerializer, ContentSerializer
from pulpcore.app.viewsets import CreateDestroyReadNamedModelViewSet

Expand Down Expand Up @@ -61,6 +61,23 @@ def create(self, request):
headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)

def destroy(self, request, pk):
"""
Remove Content unit only if it is not associated with a repository version
"""
repository_content_set = RepositoryContent.objects.filter(content__pk=pk)

if repository_content_set:
msg = (_('The Content unit cannot be deleted because it is associated with a repository'
' version, which is immutable. Repository: ') +
repository_content_set[0].repository.name)
data = {'detail': msg}
return Response(data, status=status.HTTP_409_CONFLICT)
else:
instance = self.get_object()
self.perform_destroy(instance)
return Response(status=status.HTTP_204_NO_CONTENT)


class ArtifactViewSet(CreateDestroyReadNamedModelViewSet):
endpoint_name = 'artifacts'
Expand Down

0 comments on commit f30561a

Please sign in to comment.