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: users with VIEW_ENVIRONMENT should be able to retrieve environment #4814

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/environments/permissions/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def has_permission(self, request, view):
def has_object_permission(self, request, view, obj):
if view.action == "clone":
return request.user.has_project_permission(CREATE_ENVIRONMENT, obj.project)
elif view.action == "get_document":
elif view.action in ("get_document", "retrieve", "trait_keys"):
return request.user.has_environment_permission(VIEW_ENVIRONMENT, obj)

return request.user.is_environment_admin(obj) or view.action in [
Expand Down
38 changes: 38 additions & 0 deletions api/tests/unit/environments/test_unit_environments_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ def test_retrieve_environment(
)


def test_user_with_view_environment_permission_can_retrieve_environment(
staff_client: APIClient,
environment: Environment,
with_environment_permissions: WithEnvironmentPermissionsCallable,
) -> None:
# Given
url = reverse("api-v1:environments:environment-detail", args=[environment.api_key])

with_environment_permissions([VIEW_ENVIRONMENT])

# When
response = staff_client.get(url)

# Then
assert response.status_code == status.HTTP_200_OK


def test_can_clone_environment_with_create_environment_permission(
test_user,
test_user_client,
Expand Down Expand Up @@ -920,6 +937,27 @@ def test_get_all_trait_keys_for_environment_only_returns_distinct_keys(
assert len(res.json().get("keys")) == 2


def test_user_with_view_environment_can_get_trait_keys(
identity: Identity,
staff_client: APIClient,
trait: Trait,
environment: Environment,
with_environment_permissions: WithEnvironmentPermissionsCallable,
) -> None:
# Given
url = reverse(
"api-v1:environments:environment-trait-keys", args=[environment.api_key]
)

with_environment_permissions([VIEW_ENVIRONMENT])

# When
res = staff_client.get(url)

# Then
assert res.status_code == status.HTTP_200_OK


def test_delete_trait_keys_deletes_traits_matching_provided_key_only(
identity: Identity,
admin_client_new: APIClient,
Expand Down
Loading