feat: add identity_feature_state to project features endpoint#7451
Open
SahilJat wants to merge 2 commits intoFlagsmith:mainfrom
Open
feat: add identity_feature_state to project features endpoint#7451SahilJat wants to merge 2 commits intoFlagsmith:mainfrom
SahilJat wants to merge 2 commits intoFlagsmith:mainfrom
Conversation
|
@SahilJat is attempting to deploy a commit to the Flagsmith Team on Vercel. A member of the Team first needs to authorize it. |
47374da to
255b33e
Compare
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
docs/if required so people know about the feature.Changes
Closes #7095
This PR optimizes how identity overrides are fetched on the Identity Page by eliminating chained API calls.
Backend:
FeatureViewSet.get_querysetinapi/features/views.pyto accept anidentityquery parameter. When provided (and the project is not Edge/DynamoDB-enabled), it fetches the resolved identity feature states usingidentity.get_all_feature_states()and stores them on the view instance.FeatureViewSet.get_serializer_contextto injectidentity_feature_statesinto the serializer context.CreateFeatureSerializerinapi/features/serializers.pyto include a newidentity_feature_statefield viaSerializerMethodField, which reads from the injected context.Frontend:
identity_feature_stateto theProjectFlagtype infrontend/common/types/responses.ts.identityStatesto thefeatureListresponse type inRes.getFeatureListinfrontend/common/services/useProjectFlag.tsto pass theidentityparameter to the API and extractidentityStatesfrom thetransformResponse.frontend/web/components/pages/IdentityPage.tsxto remove the chainedgetActualFlags()call (which previously hit/environments/.../identities/.../all/), theactualFlagsstate, and associated dead Redux code. The component now readsidentity_feature_statedirectly fromuseGetFeatureListQuery.How did you test this code?
Automated tests:
Added integration tests in
api/tests/integration/features/test_identity_feature_states.pycovering:identity_feature_state(enabled + value)identityparam →identity_feature_stateisNone(backward compatibility)identity_feature_stateisNone(graceful handling)identity_feature_stateisNone(no Postgres crash)identity_feature_stateisNoneidentity_feature_stateisNoneAdded unit tests in
api/tests/unit/features/test_unit_identity_feature_states.pycovering:Nonewhen context has empty identity statesNonewhenidentity_feature_stateskey is missing from contextManual testing steps:
/projects/{id}/features/?environment=X&identity=Yand the old/identities/.../all/call is gone.