1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 09:51:09 +03:00

make deletion protection mixin work with inventories

This commit is contained in:
AlanCoding 2018-04-11 07:54:09 -04:00
parent 03f4010edc
commit 0c224df9ad
No known key found for this signature in database
GPG Key ID: FD2C3C012A72926B

View File

@ -203,6 +203,10 @@ class InstanceGroupMembershipMixin(object):
class RelatedJobsPreventDeleteMixin(object): class RelatedJobsPreventDeleteMixin(object):
def perform_destroy(self, obj): def perform_destroy(self, obj):
self.check_related_active_jobs(obj)
return super(RelatedJobsPreventDeleteMixin, self).perform_destroy(obj)
def check_related_active_jobs(self, obj):
active_jobs = obj.get_active_jobs() active_jobs = obj.get_active_jobs()
if len(active_jobs) > 0: if len(active_jobs) > 0:
raise ActiveJobConflict(active_jobs) raise ActiveJobConflict(active_jobs)
@ -213,7 +217,6 @@ class RelatedJobsPreventDeleteMixin(object):
raise PermissionDenied(_( raise PermissionDenied(_(
'Related job {} is still processing events.' 'Related job {} is still processing events.'
).format(unified_job.log_format)) ).format(unified_job.log_format))
return super(RelatedJobsPreventDeleteMixin, self).perform_destroy(obj)
class ApiRootView(APIView): class ApiRootView(APIView):
@ -2085,6 +2088,7 @@ class InventoryDetail(RelatedJobsPreventDeleteMixin, ControlledByScmMixin, Retri
obj = self.get_object() obj = self.get_object()
if not request.user.can_access(self.model, 'delete', obj): if not request.user.can_access(self.model, 'delete', obj):
raise PermissionDenied() raise PermissionDenied()
self.check_related_active_jobs(obj) # related jobs mixin
try: try:
obj.schedule_deletion(getattr(request.user, 'id', None)) obj.schedule_deletion(getattr(request.user, 'id', None))
return Response(status=status.HTTP_202_ACCEPTED) return Response(status=status.HTTP_202_ACCEPTED)