From a721d09b11fed90d5f8705b5edbdfe6aead6828b Mon Sep 17 00:00:00 2001 From: helllllllder Date: Tue, 15 Oct 2024 16:27:35 -0300 Subject: [PATCH] feat: fix flowstart verification on room create feat: add transaction atomic when starting a flow, for it not to close the room if the flow start responds a error --- chats/apps/api/v1/external/rooms/serializers.py | 5 +++-- chats/apps/api/v1/projects/viewsets.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/chats/apps/api/v1/external/rooms/serializers.py b/chats/apps/api/v1/external/rooms/serializers.py index 96c52d28..8802e7fa 100644 --- a/chats/apps/api/v1/external/rooms/serializers.py +++ b/chats/apps/api/v1/external/rooms/serializers.py @@ -40,8 +40,9 @@ def get_active_room_flow_start(contact, flow_uuid, project): fs.is_deleted = True fs.save() room = fs.room - room.close([], "new_room") - close_room(str(room.pk)) + if room.is_active: + room.close([], "new_room") + close_room(str(room.pk)) return None return None diff --git a/chats/apps/api/v1/projects/viewsets.py b/chats/apps/api/v1/projects/viewsets.py index c3adc6a5..e5ca6eb0 100644 --- a/chats/apps/api/v1/projects/viewsets.py +++ b/chats/apps/api/v1/projects/viewsets.py @@ -1,6 +1,7 @@ import json from django.core.exceptions import ObjectDoesNotExist, ValidationError +from django.db import transaction from django.db.models import CharField, Value from django.db.models.functions import Concat from django_filters.rest_framework import DjangoFilterBackend @@ -263,6 +264,7 @@ def _create_flow_start_instances(self, data, flow_start): url_name="flows", serializer_class=ProjectFlowStartSerializer, ) + @transaction.atomic # revert room update if the flows request fails def start_flow(self, request, *args, **kwargs): project = self.get_object() serializer = ProjectFlowStartSerializer(data=request.data)