-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into environments-endpoint
- Loading branch information
Showing
32 changed files
with
1,035 additions
and
37 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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 |
---|---|---|
|
@@ -140,6 +140,17 @@ def get_decide(request: HttpRequest): | |
team = user.teams.get(id=project_id) | ||
|
||
if team: | ||
if team.id in settings.DECIDE_SHORT_CIRCUITED_TEAM_IDS: | ||
return cors_response( | ||
request, | ||
generate_exception_response( | ||
"decide", | ||
f"Team with ID {team.id} cannot access the /decide endpoint." | ||
f"Please contact us at [email protected]", | ||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, | ||
), | ||
) | ||
|
||
token = cast(str, token) # we know it's not None if we found a team | ||
structlog.contextvars.bind_contextvars(team_id=team.id) | ||
|
||
|
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
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 |
---|---|---|
|
@@ -1162,6 +1162,9 @@ def test_create_from_template_json(self, mock_capture) -> None: | |
|
||
self.assertEqual(dashboard["name"], valid_template["template_name"], dashboard) | ||
self.assertEqual(dashboard["description"], valid_template["dashboard_description"]) | ||
self.assertEqual( | ||
dashboard["created_by"], dashboard["created_by"] | {"first_name": "", "email": "[email protected]"} | ||
) | ||
|
||
self.assertEqual(len(dashboard["tiles"]), 1) | ||
|
||
|
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 |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
Plugin, | ||
PluginConfig, | ||
PluginSourceFile, | ||
Project, | ||
) | ||
from posthog.models.cohort.cohort import Cohort | ||
from posthog.models.feature_flag.feature_flag import FeatureFlagHashKeyOverride | ||
|
@@ -2647,6 +2648,40 @@ def test_missing_token(self, *args): | |
response = self._post_decide({"distinct_id": "example_id", "api_key": None, "project_id": self.team.id}) | ||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) | ||
|
||
def test_short_circuited_team(self, *args): | ||
short_circuited_team_token = "short_circuited_team_token" | ||
|
||
_, short_circuited_team = Project.objects.create_with_team( | ||
organization=self.organization, | ||
team_fields={ | ||
"api_token": short_circuited_team_token, | ||
"test_account_filters": [ | ||
{ | ||
"key": "email", | ||
"value": "@posthog.com", | ||
"operator": "not_icontains", | ||
"type": "person", | ||
} | ||
], | ||
"has_completed_onboarding_for": {"product_analytics": True}, | ||
}, | ||
initiating_user=self.user, | ||
) | ||
with self.settings(DECIDE_SHORT_CIRCUITED_TEAM_IDS=[short_circuited_team.id]): | ||
response = self._post_decide( | ||
{ | ||
"distinct_id": "example_id", | ||
"api_key": short_circuited_team_token, | ||
"project_id": short_circuited_team.id, | ||
} | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_422_UNPROCESSABLE_ENTITY) | ||
response_data = response.json() | ||
self.assertEqual( | ||
response_data["detail"], | ||
f"Team with ID {short_circuited_team.id} cannot access the /decide endpoint.Please contact us at [email protected]", | ||
) | ||
|
||
def test_invalid_payload_on_decide_endpoint(self, *args): | ||
invalid_payloads = [ | ||
base64.b64encode(b"1-1").decode("utf-8"), | ||
|
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
Oops, something went wrong.