'Delete an Organization
Schedules an organization for deletion.  This API endpoint cannot
be invoked without a user context for security reasons.  This means
that at present an organization can only be deleted from the
Sentry UI.
Deletion happens asynchronously and therefor is not immediate.
However once deletion has begun the state of a project changes and
will be hidden from most public views.
:pparam string organization_slug: the slug of the organization the
team should be created for.
:auth: required, user-context-needed'

@sudo_required
def delete(self, request, organization):

    if (not request.user.is_authenticated()):
        return Response({'detail': 'This    request    requires    a    user.'}, status=401)
    if organization.is_default:
        return Response({'detail': ERR_DEFAULT_ORG}, status=400)
    updated = Organization.objects.filter(id=organization.id, status=OrganizationStatus.VISIBLE).update(status=OrganizationStatus.PENDING_DELETION)
    if updated:
        transaction_id = uuid4().hex
        countdown = 86400
        entry = self.create_audit_entry(request=request, organization=organization, target_object=organization.id, event=AuditLogEntryEvent.ORG_REMOVE, data=organization.get_audit_log_data(), transaction_id=transaction_id)
        organization.send_delete_confirmation(entry, countdown)
        delete_organization.apply_async(kwargs={'object_id': organization.id, 'transaction_id': transaction_id}, countdown=countdown)
        delete_logger.info('object.delete.queued', extra={'object_id': organization.id, 'transaction_id': transaction_id, 'model': Organization.__name__})
    return Response(status=204)
