diff --git a/CHANGELOG.md b/CHANGELOG.md index e9bbe2d3c..14aecb7ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## [Unreleased] +## [2.8.2] - 2024-04-10 +- Update recent activities to avoid flows tests errors + ## [2.8.1] - 2024-04-10 - Endpoint to list flows with pagination - Add option to send delete in flow activity diff --git a/weni/activities/apps.py b/weni/activities/apps.py index 58f81f0a4..9f85c071a 100644 --- a/weni/activities/apps.py +++ b/weni/activities/apps.py @@ -9,4 +9,3 @@ class ActivitiesConfig(AppConfig): def ready(self) -> None: if not settings.TESTING: from weni.activities import signals # noqa: F401 - diff --git a/weni/activities/recent_activities.py b/weni/activities/recent_activities.py new file mode 100644 index 000000000..350011688 --- /dev/null +++ b/weni/activities/recent_activities.py @@ -0,0 +1,36 @@ +from django.db import models +from temba.event_driven.publisher.rabbitmq_publisher import RabbitmqPublisher + + +def create_recent_activity(instance: models.Model, created: bool, delete=None): + if instance.is_active: + rabbitmq_publisher = RabbitmqPublisher() + if delete: + action = "DELETE" + rabbitmq_publisher.send_message( + body=dict( + action=action, + entity=instance.__class__.__name__.upper(), + entity_name=getattr(instance, "name", None), + entity_uuid=str(instance.uuid), + project_uuid=str(instance.org.project.project_uuid), + user=instance.modified_by.email, + flow_organization=str(instance.org.uuid), + ), + exchange="recent-activities.topic", + routing_key="flow-delete", + ) + else: + action = "CREATE" if created else "UPDATE" + rabbitmq_publisher.send_message( + body=dict( + action=action, + entity=instance.__class__.__name__.upper(), + entity_name=getattr(instance, "name", None), + project_uuid=str(instance.org.project.project_uuid), + user=instance.modified_by.email, + flow_organization=str(instance.org.uuid), + ), + exchange="recent-activities.topic", + routing_key="", + ) diff --git a/weni/activities/signals.py b/weni/activities/signals.py index 990019b1f..cc4a9436b 100644 --- a/weni/activities/signals.py +++ b/weni/activities/signals.py @@ -1,4 +1,3 @@ -from django.db import models from django.db.models.signals import post_save from django.dispatch import receiver @@ -6,41 +5,9 @@ from temba.flows.models import Flow from temba.triggers.models import Trigger from temba.campaigns.models import Campaign -from temba.event_driven.publisher.rabbitmq_publisher import RabbitmqPublisher +from weni.activities.recent_activities import create_recent_activity -def create_recent_activity(instance: models.Model, created: bool, delete=None): - if instance.is_active: - rabbitmq_publisher = RabbitmqPublisher() - if delete: - action = "DELETE" - rabbitmq_publisher.send_message( - body=dict( - action=action, - entity=instance.__class__.__name__.upper(), - entity_name=getattr(instance, "name", None), - entity_uuid=str(instance.uuid), - project_uuid=str(instance.org.project.project_uuid), - user=instance.modified_by.email, - flow_organization=str(instance.org.uuid), - ), - exchange="recent-activities.topic", - routing_key="flow-delete", - ) - else: - action = "CREATE" if created else "UPDATE" - rabbitmq_publisher.send_message( - body=dict( - action=action, - entity=instance.__class__.__name__.upper(), - entity_name=getattr(instance, "name", None), - project_uuid=str(instance.org.project.project_uuid), - user=instance.modified_by.email, - flow_organization=str(instance.org.uuid), - ), - exchange="recent-activities.topic", - routing_key="", - ) @receiver(post_save, sender=Channel) def channel_recent_activity_signal(sender, instance: Channel, created: bool, **kwargs): diff --git a/weni/internal/models.py b/weni/internal/models.py index d9885c563..db2bfbc19 100644 --- a/weni/internal/models.py +++ b/weni/internal/models.py @@ -37,3 +37,10 @@ def __str__(self): @property def org(self): return self.org_ptr + + def save(self, *args, **kwargs): + if not self.pk: + super().save(*args, **kwargs) + + self.org_ptr.proj_uuid = self.project_uuid + self.org_ptr.save()