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

Commit

Permalink
Remove ability to delete content units
Browse files Browse the repository at this point in the history
  • Loading branch information
dralley committed Apr 4, 2018
1 parent 181360e commit 2e9f917
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
2 changes: 2 additions & 0 deletions pulpcore/pulpcore/app/apps.py
Expand Up @@ -94,11 +94,13 @@ def import_serializers(self):
def import_viewsets(self):
# circular import avoidance
from pulpcore.app.viewsets import (GenericNamedModelViewSet, NamedModelViewSet,
CreateReadNamedModelViewSet,
CreateDestroyReadNamedModelViewSet,
CreateReadAsyncUpdateDestroyNamedModelViewset)
# These viewsets are used as base classes for actual model viewsets and
# should not be registered
base_viewsets = [GenericNamedModelViewSet, NamedModelViewSet,
CreateReadNamedModelViewSet,
CreateDestroyReadNamedModelViewSet,
CreateReadAsyncUpdateDestroyNamedModelViewset]
self.named_viewsets = {}
Expand Down
1 change: 1 addition & 0 deletions pulpcore/pulpcore/app/viewsets/__init__.py
@@ -1,5 +1,6 @@
from pulpcore.app.viewsets.base import (GenericNamedModelViewSet, NamedModelViewSet, # noqa
CreateDestroyReadNamedModelViewSet,
CreateReadNamedModelViewSet,
CreateReadAsyncUpdateDestroyNamedModelViewset) # noqa
from pulpcore.app.viewsets.content import ArtifactViewSet, ContentViewSet # noqa
from pulpcore.app.viewsets.repository import (DistributionViewSet, # noqa
Expand Down
11 changes: 11 additions & 0 deletions pulpcore/pulpcore/app/viewsets/base.py
Expand Up @@ -258,7 +258,18 @@ class CreateDestroyReadNamedModelViewSet(mixins.CreateModelMixin,
A customized NamedModelViewSet for models that don't support updates.
A viewset that provides default `create()`, `retrieve()`, `destroy()` and `list()` actions.
"""
pass


class CreateReadNamedModelViewSet(mixins.CreateModelMixin,
mixins.RetrieveModelMixin,
mixins.ListModelMixin,
GenericNamedModelViewSet):
"""
A customized NamedModelViewSet for models that don't support updates or deletes.
A viewset that provides default `create()`, `retrieve()`, and `list()` actions.
"""
pass

Expand Down
23 changes: 3 additions & 20 deletions pulpcore/pulpcore/app/viewsets/content.py
Expand Up @@ -6,9 +6,9 @@
from rest_framework.response import Response


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


class ContentFilter(filterset.FilterSet):
Expand Down Expand Up @@ -41,7 +41,7 @@ class Meta:
fields = ['md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512']


class ContentViewSet(CreateDestroyReadNamedModelViewSet):
class ContentViewSet(CreateReadNamedModelViewSet):
endpoint_name = 'content'
queryset = Content.objects.all()
serializer_class = ContentSerializer
Expand All @@ -61,23 +61,6 @@ 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 2e9f917

Please sign in to comment.