Skip to content

Commit

Permalink
fix: Actions in surveys serializer (#26759)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Dec 9, 2024
1 parent 481a74c commit 6cdc10a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
17 changes: 15 additions & 2 deletions posthog/api/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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


Expand Down
14 changes: 0 additions & 14 deletions posthog/api/test/test_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [],
}
]
}
Expand Down

0 comments on commit 6cdc10a

Please sign in to comment.