Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/weni-ai/rapidpro-apps into …
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
lucaslinhares committed Apr 11, 2024
2 parents 8394587 + aed1277 commit 799eb60
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]

## [2.8.1] - 2024-04-10
- Endpoint to list flows with pagination
- Add option to send delete in flow activity

## [2.8.0] - 2024-03-27
- Change recent activities to EDA
- Endpoint to delete chats sector
Expand Down
5 changes: 4 additions & 1 deletion weni/activities/apps.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from django.apps import AppConfig
from django.conf import settings


class ActivitiesConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "weni.activities"

def ready(self) -> None:
from weni.activities import signals # noqa: F401
if not settings.TESTING:
from weni.activities import signals # noqa: F401

27 changes: 19 additions & 8 deletions weni/activities/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,37 @@


def create_recent_activity(instance: models.Model, created: bool, delete=None):
routing_key = ""
if instance.is_active:
rabbitmq_publisher = RabbitmqPublisher()
if delete:
action = "DELETE"
routing_key = "flow-delete"
else:
action = "CREATE" if created else "UPDATE"
rabbitmq_publisher = RabbitmqPublisher()
rabbitmq_publisher.send_message(
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=routing_key,
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
1 change: 1 addition & 0 deletions weni/internal/flows/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class FlowSerializer(serializers.Serializer):
project = weni_fields.ProjectUUIDRelatedField(required=True, write_only=True)
flow_name = serializers.CharField(required=False, write_only=True)
sample_flow = serializers.JSONField(required=False, write_only=True)
uuid = serializers.UUIDField(read_only=True)
name = serializers.CharField(read_only=True)
Expand Down
13 changes: 11 additions & 2 deletions weni/internal/flows/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
from temba.flows.models import Flow


class FlowPagination(PageNumberPagination):
page_size_query_param = "page_size"
max_page_size = 20


class FlowViewSet(CreateModelMixin, InternalGenericViewSet, ListModelMixin):
serializer_class = FlowSerializer
pagination_class = PageNumberPagination
pagination_class = FlowPagination

def get_queryset(self):
serializer = self.get_serializer(data=self.request.query_params.dict())
Expand All @@ -21,8 +26,12 @@ def get_queryset(self):
is_active=True,
).exclude(is_archived=True)

flow_name = serializer.validated_data.get("flow_name")
if flow_name:
queryset = queryset.filter(name__icontains=flow_name)

if queryset:
return self.paginate_queryset(queryset)
return queryset

raise NotFound()

Expand Down

0 comments on commit 799eb60

Please sign in to comment.