-
Notifications
You must be signed in to change notification settings - Fork 429
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: Feature id in mv-option request is undefined #2751
Merged
novakzaballa
merged 6 commits into
main
from
fix/feature-id-in-mv-option-request-is-undefined
Sep 12, 2023
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
aecbfd0
fix: Feature id in mv-option request is undefined
novakzaballa 93efa8e
Add test and validate id
novakzaballa 769b106
Fix: Validated feature id type, and feature owners
novakzaballa d2ff80e
Fix: feature owners
novakzaballa 3b32d2f
fix: Refactored create logic
novakzaballa 4397eda
fix: Refactored create logic
novakzaballa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,12 @@ | |
from django.urls import reverse | ||
from pytest_lazyfixture import lazy_fixture | ||
from rest_framework import status | ||
from rest_framework.test import APIClient | ||
|
||
from features.models import Feature | ||
from organisations.models import Organisation | ||
from projects.models import Project | ||
from users.models import FFAdminUser | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
@@ -34,6 +40,68 @@ def test_can_create_mv_option(client, project, mv_option_50_percent, feature): | |
assert set(data.items()).issubset(set(response.json().items())) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"client, feature_id", | ||
[ | ||
(lazy_fixture("admin_client"), "undefined"), | ||
(lazy_fixture("admin_client"), "89809"), | ||
], | ||
) | ||
def test_cannot_create_mv_option_when_feature_id_invalid(client, feature_id, project): | ||
# Given | ||
url = reverse( | ||
"api-v1:projects:feature-mv-options-list", | ||
args=[project, feature_id], | ||
) | ||
|
||
data = { | ||
"type": "unicode", | ||
"feature": feature_id, | ||
"string_value": "bigger", | ||
"default_percentage_allocation": 50, | ||
} | ||
# When | ||
response = client.post( | ||
url, | ||
data=json.dumps(data), | ||
content_type="application/json", | ||
) | ||
# Then | ||
assert response.status_code == status.HTTP_404_NOT_FOUND | ||
|
||
|
||
def test_cannot_create_mv_option_when_user_is_not_owner_of_the_feature(project): | ||
# Given | ||
new_user = FFAdminUser.objects.create(email="[email protected]") | ||
organisation = Organisation.objects.create(name="Test Org") | ||
new_project = Project.objects.create(name="Test project", organisation=organisation) | ||
feature = Feature.objects.create( | ||
name="New_feature", | ||
project=new_project, | ||
) | ||
url = reverse( | ||
"api-v1:projects:feature-mv-options-list", | ||
args=[project, feature.id], | ||
) | ||
|
||
data = { | ||
"type": "unicode", | ||
"feature": feature.id, | ||
"string_value": "bigger", | ||
"default_percentage_allocation": 50, | ||
} | ||
client = APIClient() | ||
client.force_authenticate(user=new_user) | ||
# When | ||
response = client.post( | ||
url, | ||
data=json.dumps(data), | ||
content_type="application/json", | ||
) | ||
# Then | ||
assert response.status_code == status.HTTP_403_FORBIDDEN | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"client", | ||
[lazy_fixture("admin_master_api_key_client"), lazy_fixture("admin_client")], | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still isn't checking that it's a project they belong to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this being checked here, right?
flagsmith/api/features/multivariate/views.py
Line 21 in d2ff80e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, looks like that is checking they have permissions on the project. So it should be sufficient to change this to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I understand what you meant, Thank you, corrected.