Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Neil Kakkar <[email protected]>
  • Loading branch information
liyiy and neilkakkar authored Nov 16, 2023
1 parent a20b2b6 commit b3f6672
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions posthog/api/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def update(self, instance: Survey, validated_data):
existing_flag_serializer.is_valid(raise_exception=True)
existing_flag_serializer.save()
else:
new_flag = self._create_new_targeting_flag(instance.name, new_filters, instance.start_date)
new_flag = self._create_new_targeting_flag(instance.name, new_filters, bool(instance.start_date))
validated_data["targeting_flag_id"] = new_flag.id
validated_data.pop("targeting_flag_filters")

Expand All @@ -230,20 +230,20 @@ def update(self, instance: Survey, validated_data):
# turn off feature flag if survey is ended
if end_date is None:
instance.targeting_flag.active = True
elif end_date:
else:
instance.targeting_flag.active = False
instance.targeting_flag.save()

return super().update(instance, validated_data)

def _create_new_targeting_flag(self, name, filters, start_date=None):
def _create_new_targeting_flag(self, name, filters, active=False):
feature_flag_key = slugify(f"{SURVEY_TARGETING_FLAG_PREFIX}{name}")
feature_flag_serializer = FeatureFlagSerializer(
data={
"key": feature_flag_key,
"name": f"Targeting flag for survey {name}",
"filters": filters,
"active": True if start_date else False,
"active": active,
},
context=self.context,
)
Expand Down

0 comments on commit b3f6672

Please sign in to comment.