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(env-clone/permission): allow clone using CREATE_ENVIRONMENT #2675

Merged
merged 1 commit into from
Aug 24, 2023
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 @@ -48,7 +48,7 @@ def has_object_permission(self, request, view, obj):
return False

if view.action == "clone":
return request.user.is_project_admin(obj.project)
return request.user.has_project_permission(CREATE_ENVIRONMENT, obj.project)

return request.user.is_environment_admin(obj) or view.action in [
"user_permissions"
Expand Down
20 changes: 20 additions & 0 deletions api/tests/unit/environments/test_unit_environments_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from rest_framework.test import APIClient

from environments.models import Environment
from projects.permissions import CREATE_ENVIRONMENT


def test_retrieve_environment(
Expand Down Expand Up @@ -45,3 +46,22 @@ def test_retrieve_environment(
response_json["use_mv_v2_evaluation"]
== environment.use_identity_composite_key_for_hashing
)


def test_can_clone_environment_with_create_environment_permission(
test_user,
test_user_client,
environment,
user_project_permission,
):
# Given
env_name = "Cloned env"
user_project_permission.permissions.add(CREATE_ENVIRONMENT)

url = reverse("api-v1:environments:environment-clone", args=[environment.api_key])

# When
response = test_user_client.post(url, {"name": env_name})

# Then
assert response.status_code == status.HTTP_200_OK