Skip to content
Merged
8 changes: 6 additions & 2 deletions src/sentry/api/endpoints/prompts_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ def put(self, request: Request, **kwargs):
# if project_id or organization_id in required fields make sure they exist
# if NOT in required fields, insert dummy value so dups aren't recorded
if "project_id" in required_fields:
if not Project.objects.filter(id=fields["project_id"]).exists():
return Response({"detail": "Project no longer exists"}, status=400)
if not Project.objects.filter(
Copy link
Member Author

Choose a reason for hiding this comment

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

aside this isnt actually a high severity concern afaict, but no idea what the consequence is

id=fields["project_id"], organization_id=request.organization.id
).exists():
return Response(
{"detail": "Project does not belong to this organization"}, status=400
)
else:
fields["project_id"] = 0

Expand Down
21 changes: 20 additions & 1 deletion tests/sentry/api/endpoints/test_prompts_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,20 @@ def test_invalid_project(self) -> None:
}
resp = self.client.get(self.path, data)
assert resp.status_code == 200
project_id = self.project.id
self.project.delete()
# project doesn't exist
resp = self.client.put(
self.path,
{
"organization_id": self.org.id,
"project_id": self.project.id,
"project_id": project_id,
"feature": "releases",
"status": "dismissed",
},
)
assert resp.status_code == 400
assert resp.data["detail"] == "Project does not belong to this organization"

def test_dismiss(self) -> None:
data = {
Expand Down Expand Up @@ -271,3 +273,20 @@ def test_batched(self) -> None:
assert resp.status_code == 200
assert "dismissed_ts" in resp.data["features"]["releases"]
assert "snoozed_ts" in resp.data["features"]["alert_stream"]

def test_project_from_different_organization(self) -> None:
other_org = self.create_organization()
other_project = self.create_project(organization=other_org)

resp = self.client.put(
self.path,
{
"organization_id": self.org.id,
"project_id": other_project.id,
"feature": "releases",
"status": "dismissed",
},
)

assert resp.status_code == 400
assert resp.data["detail"] == "Project does not belong to this organization"
Loading