def delete(self, request, project, monitor): """ Delete a monitor ```````````````` :pparam string monitor_id: the id of the monitor. :auth: required """ # TODO(dcramer0:) with transaction.atomic(): affected = Monitor.objects.filter( id=monitor.id, ).exclude( status__in=[MonitorStatus.PENDING_DELETION, MonitorStatus.DELETION_IN_PROGRESS], ).update( status=MonitorStatus.PENDING_DELETION ) if not affected: return self.respond(status=404) transaction_id = uuid4().hex self.create_audit_entry( request=request, organization=project.organization, target_object=monitor.id, event=AuditLogEntryEvent.MONITOR_REMOVE, data=monitor.get_audit_log_data(), transaction_id=transaction_id, ) generic_delete.apply_async( kwargs={ 'object_id': monitor.id, 'transaction_id': transaction_id, 'actor_id': request.user.id, }, ) delete_logger.info( 'object.delete.queued', extra={ 'object_id': monitor.id, 'transaction_id': transaction_id, 'model': Monitor.__name__, } ) return self.respond(status=202)
def delete(self, request, project, monitor): """ Delete a monitor ```````````````` :pparam string monitor_id: the id of the monitor. :auth: required """ # TODO(dcramer0:) with transaction.atomic(): affected = (Monitor.objects.filter(id=monitor.id).exclude( status__in=[ MonitorStatus.PENDING_DELETION, MonitorStatus.DELETION_IN_PROGRESS ]).update(status=MonitorStatus.PENDING_DELETION)) if not affected: return self.respond(status=404) transaction_id = uuid4().hex self.create_audit_entry( request=request, organization=project.organization, target_object=monitor.id, event=AuditLogEntryEvent.MONITOR_REMOVE, data=monitor.get_audit_log_data(), transaction_id=transaction_id, ) generic_delete.apply_async( kwargs={ "app_label": Monitor._meta.app_label, "model_name": Monitor._meta.model_name, "object_id": monitor.id, "transaction_id": transaction_id, "actor_id": request.user.id, }) delete_logger.info( "object.delete.queued", extra={ "object_id": monitor.id, "transaction_id": transaction_id, "model": Monitor.__name__, }, ) return self.respond(status=202)
def delete(self, request, organization, repo_id): if not request.user.is_authenticated(): return Response(status=401) try: repo = Repository.objects.get( id=repo_id, organization_id=organization.id, ) except Repository.DoesNotExist: raise ResourceDoesNotExist updated = Repository.objects.filter( id=repo.id, status=ObjectStatus.VISIBLE, ).update(status=ObjectStatus.PENDING_DELETION) if updated: repo.status = ObjectStatus.PENDING_DELETION transaction_id = uuid4().hex countdown = 86400 generic_delete.apply_async( kwargs={ 'app_label': Repository._meta.app_label, 'model_name': Repository._meta.model_name, 'object_id': repo.id, 'transaction_id': transaction_id, 'actor_id': request.user.id, }, countdown=countdown, ) delete_logger.info('object.delete.queued', extra={ 'object_id': repo.id, 'transaction_id': transaction_id, 'model': Repository.__name__, }) return Response(serialize(repo, request.user), status=202)
def delete(self, request, organization, repo_id): if not request.user.is_authenticated(): return Response(status=401) try: repo = Repository.objects.get( id=repo_id, organization_id=organization.id, ) except Repository.DoesNotExist: raise ResourceDoesNotExist updated = Repository.objects.filter( id=repo.id, status=ObjectStatus.VISIBLE, ).update(status=ObjectStatus.PENDING_DELETION) if updated: repo.status = ObjectStatus.PENDING_DELETION transaction_id = uuid4().hex countdown = 86400 generic_delete.apply_async( kwargs={ 'app_label': Repository._meta.app_label, 'model_name': Repository._meta.model_name, 'object_id': organization.id, 'transaction_id': transaction_id, 'actor_id': request.user.id, }, countdown=countdown, ) delete_logger.info('object.delete.queued', extra={ 'object_id': repo.id, 'transaction_id': transaction_id, 'model': Repository.__name__, }) return Response(serialize(repo, request.user), status=202)