(self)
| 94 | return get_object_or_404(projects, pk=self.kwargs["project_pk"]) |
| 95 | |
| 96 | def get_queryset(self): # type: ignore[no-untyped-def] |
| 97 | if getattr(self, "swagger_fake_view", False): |
| 98 | return Segment.objects.none() |
| 99 | |
| 100 | project = self.get_project() |
| 101 | queryset = Segment.live_objects.filter(project=project, is_system_segment=False) |
| 102 | |
| 103 | if self.action == "list": |
| 104 | # TODO: at the moment, the UI only shows the name and description of the segment in the list view. |
| 105 | # we shouldn't return all of the rules and conditions in the list view. |
| 106 | queryset = queryset.prefetch_related( |
| 107 | "membership_counts", |
| 108 | "rules", |
| 109 | "rules__conditions", |
| 110 | "rules__rules", |
| 111 | "rules__rules__conditions", |
| 112 | "rules__rules__rules", |
| 113 | "metadata", |
| 114 | ) |
| 115 | |
| 116 | query_serializer = SegmentListQuerySerializer(data=self.request.query_params) |
| 117 | query_serializer.is_valid(raise_exception=True) |
| 118 | |
| 119 | identity_pk = query_serializer.validated_data.get("identity") |
| 120 | if identity_pk: |
| 121 | if identity_pk.isdigit(): |
| 122 | identity = Identity.objects.get(pk=identity_pk) |
| 123 | segment_ids = [segment.id for segment in identity.get_segments()] |
| 124 | else: |
| 125 | segment_ids = EdgeIdentity.dynamo_wrapper.get_segment_ids(identity_pk) |
| 126 | queryset = queryset.filter(id__in=segment_ids) |
| 127 | |
| 128 | search_term = query_serializer.validated_data.get("q") |
| 129 | if search_term: |
| 130 | queryset = queryset.filter(name__icontains=search_term) |
| 131 | |
| 132 | include_feature_specific = query_serializer.validated_data[ |
| 133 | "include_feature_specific" |
| 134 | ] |
| 135 | if include_feature_specific is False: |
| 136 | queryset = queryset.filter(feature__isnull=True) |
| 137 | |
| 138 | return queryset |
| 139 | |
| 140 | @extend_schema(parameters=[AssociatedFeaturesQuerySerializer]) |
| 141 | @action( |
nothing calls this directly
no test coverage detected