Skip to content

Commit

Permalink
Merge branch 'feature/update-project-model' of https://github.com/wen…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslinhares committed Apr 12, 2024
2 parents 799eb60 + 4f2e285 commit 387d6ce
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 35 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion weni/activities/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ class ActivitiesConfig(AppConfig):
def ready(self) -> None:
if not settings.TESTING:
from weni.activities import signals # noqa: F401

36 changes: 36 additions & 0 deletions weni/activities/recent_activities.py
Original file line number Diff line number Diff line change
@@ -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="",
)
35 changes: 1 addition & 34 deletions weni/activities/signals.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,13 @@
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver

from temba.channels.models import Channel
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):
Expand Down
7 changes: 7 additions & 0 deletions weni/internal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 387d6ce

Please sign in to comment.