Retrieve the flags for an environment. --- *Note*: when providing the `feature` query argument, this endpoint will return either a single object or a 404 (if the feature does not exist) rather than a list. --- *Note*: using this endpoint wit
(self, request, identifier=None, *args, **kwargs)
| 995 | ) |
| 996 | ) |
| 997 | def get(self, request, identifier=None, *args, **kwargs): # type: ignore[no-untyped-def] |
| 998 | """ |
| 999 | Retrieve the flags for an environment. |
| 1000 | |
| 1001 | --- |
| 1002 | *Note*: when providing the `feature` query argument, this endpoint will |
| 1003 | return either a single object or a 404 (if the feature does not exist) rather |
| 1004 | than a list. |
| 1005 | |
| 1006 | --- |
| 1007 | *Note*: using this endpoint with an identifier is deprecated. |
| 1008 | Please use `/api/v1/identities/?identifier=<identifier>` instead. |
| 1009 | """ |
| 1010 | if identifier: |
| 1011 | return self._get_flags_response_with_identifier(request, identifier) |
| 1012 | |
| 1013 | if "feature" in request.GET: |
| 1014 | feature_states = get_environment_flags_list( |
| 1015 | environment=request.environment, |
| 1016 | feature_name=request.GET["feature"], |
| 1017 | additional_filters=self._additional_filters, |
| 1018 | from_replica=True, |
| 1019 | ) |
| 1020 | if not feature_states: |
| 1021 | return Response( |
| 1022 | {"detail": "Given feature not found"}, |
| 1023 | status=status.HTTP_404_NOT_FOUND, |
| 1024 | ) |
| 1025 | |
| 1026 | return Response(self.get_serializer(feature_states[0]).data) |
| 1027 | |
| 1028 | if settings.CACHE_FLAGS_SECONDS > 0: |
| 1029 | data = self._get_flags_from_cache(request.environment, from_replica=True) |
| 1030 | else: |
| 1031 | data = self.get_serializer( |
| 1032 | get_environment_flags_list( |
| 1033 | environment=request.environment, |
| 1034 | additional_filters=self._additional_filters, |
| 1035 | from_replica=True, |
| 1036 | ), |
| 1037 | many=True, |
| 1038 | ).data |
| 1039 | |
| 1040 | updated_at = self.request.environment.updated_at |
| 1041 | return Response( |
| 1042 | data, |
| 1043 | headers={FLAGSMITH_UPDATED_AT_HEADER: updated_at.timestamp()}, |
| 1044 | ) |
| 1045 | |
| 1046 | @property |
| 1047 | def _additional_filters(self) -> Q: |
no test coverage detected