Skip to content

Commit

Permalink
fix(env-clone/permission): allow clone using CREATE_ENVIRONMENT (#2675)
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi authored Aug 24, 2023
1 parent 15ff343 commit edc3afc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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

3 comments on commit edc3afc

@vercel
Copy link

@vercel vercel bot commented on edc3afc Aug 24, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on edc3afc Aug 24, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

docs – ./docs

docs-git-main-flagsmith.vercel.app
docs-flagsmith.vercel.app
docs.bullet-train.io
docs.flagsmith.com

@vercel
Copy link

@vercel vercel bot commented on edc3afc Aug 24, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.