Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure SimpleFeatureStateViewSet uses correct permissions for segment overrides #2990

Merged

Conversation

matthewelwell
Copy link
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have run pre-commit to check linting
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

Fixes an issue found when testing the new MANAGE_SEGMENTS permission functionality. The FE uses the SimpleFeatureStateViewSet for updating segment overrides, which the new permission didn't cover. This PR ensures that this endpoint is correctly covered by the new permission for creating (although this is not used by the FE) and updating segment overrides via this API route.

How did you test this code?

Added new unit tests.

@matthewelwell matthewelwell requested review from a team and zachaysan and removed request for a team November 17, 2023 10:18
Copy link

vercel bot commented Nov 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 17, 2023 11:06am
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 17, 2023 11:06am
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 17, 2023 11:06am

Copy link
Contributor

github-actions bot commented Nov 17, 2023

Uffizzi Preview deployment-40964 was deleted.

@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e4325a8) 95.56% compared to head (64261ae) 95.58%.
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2990      +/-   ##
==========================================
+ Coverage   95.56%   95.58%   +0.01%     
==========================================
  Files        1014     1016       +2     
  Lines       29421    29526     +105     
==========================================
+ Hits        28116    28222     +106     
+ Misses       1305     1304       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


def test_create_segment_override__using_simple_feature_state_viewset__allows_manage_segment_overrides(
staff_client: APIClient,
with_environment_permissions: Callable[[list[str], int], None],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with_environment_permissions: Callable[[list[str], int], None],
with_environment_permissions: Callable[[list[str]], None],

Not precisely accurate but correct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, technically, I guess it should be Callable[[list[str], int | None], None] based on the definition:

@pytest.fixture()
def with_environment_permissions(
    environment: Environment, staff_user: FFAdminUser
) -> typing.Callable[[list[str], int], None]:
    """
    Add environment permissions to the staff_user fixture.
    Defaults to associating to the environment fixture.
    """

    def _with_environment_permissions(
        permission_keys: list[str], environment_id: typing.Optional[int] = None
    ) -> UserEnvironmentPermission:
        environment_id = environment_id or environment.id
        uep, __ = UserEnvironmentPermission.objects.get_or_create(
            environment_id=environment_id, user=staff_user
        )
        uep.permissions.add(*permission_keys)

        return uep

    return _with_environment_permissions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here

Copy link
Member

@khvn26 khvn26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some typing nitpicks, otherwise LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants