From 6cdc10a1d5811e80ebcb9d30379cd46a25a2e586 Mon Sep 17 00:00:00 2001 From: Ben White Date: Mon, 9 Dec 2024 18:23:06 +0100 Subject: [PATCH] fix: Actions in surveys serializer (#26759) --- posthog/api/survey.py | 17 +++++++++++++++-- posthog/api/test/test_survey.py | 14 -------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/posthog/api/survey.py b/posthog/api/survey.py index 3d13981a867f4..a3d8051e75651 100644 --- a/posthog/api/survey.py +++ b/posthog/api/survey.py @@ -19,7 +19,7 @@ from rest_framework.response import Response from ee.surveys.summaries.summarize_surveys import summarize_survey_responses -from posthog.api.action import ActionSerializer +from posthog.api.action import ActionSerializer, ActionStepJSONSerializer from posthog.api.feature_flag import ( BEHAVIOURAL_COHORT_FOUND_ERROR_CODE, FeatureFlagSerializer, @@ -801,6 +801,19 @@ class Meta: fields = ["survey_config"] +class SurveyAPIActionSerializer(serializers.ModelSerializer): + steps = ActionStepJSONSerializer(many=True, required=False) + + class Meta: + model = Action + fields = [ + "id", + "name", + "steps", + ] + read_only_fields = fields + + class SurveyAPISerializer(serializers.ModelSerializer): """ Serializer for the exposed /api/surveys endpoint, to be used in posthog-js and for headless APIs. @@ -844,7 +857,7 @@ def get_conditions(self, survey: Survey): if survey.conditions is None: survey.conditions = {} - survey.conditions["actions"] = {"values": ActionSerializer(actions, many=True).data} + survey.conditions["actions"] = {"values": SurveyAPIActionSerializer(actions, many=True).data} return survey.conditions diff --git a/posthog/api/test/test_survey.py b/posthog/api/test/test_survey.py index 0c79b33518c7b..fd84e884cbec8 100644 --- a/posthog/api/test/test_survey.py +++ b/posthog/api/test/test_survey.py @@ -2783,9 +2783,6 @@ def test_list_surveys_with_actions(self): { "id": action.id, "name": "user subscribed", - "description": "", - "post_to_slack": False, - "slack_message_format": "", "steps": [ { "event": "$pageview", @@ -2800,17 +2797,6 @@ def test_list_surveys_with_actions(self): "url_matching": "contains", } ], - "created_at": ANY, - "created_by": None, - "deleted": False, - "is_calculating": False, - "creation_context": None, - "last_calculated_at": ANY, - "team_id": self.team.id, - "is_action": True, - "bytecode_error": None, - "pinned_at": None, - "tags": [], } ] }