add schedule_deletion method and signal

This commit is contained in:
Wayne Witzel III
2017-06-29 00:15:11 -04:00
parent 7d283f1dfd
commit e84ecabe72
3 changed files with 26 additions and 8 deletions

View File

@@ -59,7 +59,7 @@ import ansiconv
from social.backends.utils import load_backends
# AWX
from awx.main.tasks import send_notifications, update_host_smart_inventory_memberships, delete_inventory
from awx.main.tasks import send_notifications, update_host_smart_inventory_memberships
from awx.main.access import get_user_queryset
from awx.main.ha import is_ha_environment
from awx.api.authentication import TaskAuthentication, TokenGetAuthentication
@@ -1839,15 +1839,13 @@ class InventoryDetail(ControlledByScmMixin, RetrieveUpdateDestroyAPIView):
def destroy(self, request, *args, **kwargs):
obj = self.get_object()
if obj.pending_deletion is True:
return Response(dict(error=_("Inventory is already being deleted.")), status=status.HTTP_400_BAD_REQUEST)
if not request.user.can_access(self.model, 'delete', obj):
raise PermissionDenied()
obj.websocket_emit_status('pending_deletion')
delete_inventory.delay(obj.id)
obj.pending_deletion = True
obj.save(update_fields=['pending_deletion'])
return Response(status=status.HTTP_202_ACCEPTED)
try:
obj.schedule_deletion()
return Response(status=status.HTTP_202_ACCEPTED)
except RuntimeError, e:
return Response(dict(error=_("{0}".format(e))), status=status.HTTP_400_BAD_REQUEST)
class InventoryActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView):