mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 09:51:09 +03:00
Merge pull request #1328 from AlanCoding/job_del_protect
make deletion protection mixin work with inventories
This commit is contained in:
commit
a7ecc306e1
@ -204,6 +204,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)
|
||||||
@ -214,7 +218,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):
|
||||||
@ -2080,6 +2083,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)
|
||||||
|
Loading…
Reference in New Issue
Block a user