Merge pull request #1175 from AlanCoding/protect_hosts

Add deletion protection to hosts
This commit is contained in:
Alan Rominger 2018-04-18 10:06:05 -04:00 committed by GitHub
commit 18a7e86e0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -2177,7 +2177,7 @@ class HostList(HostRelatedSearchMixin, ListCreateAPIView):
return Response(dict(error=_(six.text_type(e))), status=status.HTTP_400_BAD_REQUEST)
class HostDetail(ControlledByScmMixin, RetrieveUpdateDestroyAPIView):
class HostDetail(RelatedJobsPreventDeleteMixin, ControlledByScmMixin, RetrieveUpdateDestroyAPIView):
always_allow_superuser = False
model = Host

View File

@ -517,7 +517,7 @@ class SmartInventoryMembership(BaseModel):
host = models.ForeignKey('Host', related_name='+', on_delete=models.CASCADE)
class Host(CommonModelNameNotUnique):
class Host(CommonModelNameNotUnique, RelatedJobsMixin):
'''
A managed node
'''
@ -703,6 +703,12 @@ class Host(CommonModelNameNotUnique):
self._update_host_smart_inventory_memeberships()
super(Host, self).delete(*args, **kwargs)
'''
RelatedJobsMixin
'''
def _get_related_jobs(self):
return self.inventory._get_related_jobs()
class Group(CommonModelNameNotUnique, RelatedJobsMixin):
'''