Skip to content

Commit ae9d7c0

Browse files
authored
fix(prompts) Handle string organization id values (#104543)
The prompts-activity endpoint checks that organization_id is equal to the current organziation id. However, we also need to handle string ids, as JS code will have organization.id as a string.
1 parent a030338 commit ae9d7c0

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/sentry/api/endpoints/prompts_activity.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ def put(self, request: Request, **kwargs):
9797
else:
9898
fields["project_id"] = 0
9999

100-
if (
101-
"organization_id" in required_fields
102-
and fields["organization_id"] == request.organization.id
100+
if "organization_id" in required_fields and str(fields["organization_id"]) == str(
101+
request.organization.id
103102
):
104103
if not Organization.objects.filter(id=fields["organization_id"]).exists():
105104
return Response({"detail": "Organization no longer exists"}, status=400)

tests/sentry/api/endpoints/test_prompts_activity.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_dismiss(self) -> None:
104104
assert resp.status_code == 200
105105
assert resp.data.get("data", None) is None
106106

107-
self.client.put(
107+
resp = self.client.put(
108108
self.path,
109109
{
110110
"organization_id": self.org.id,
@@ -113,9 +113,33 @@ def test_dismiss(self) -> None:
113113
"status": "dismissed",
114114
},
115115
)
116+
assert resp.status_code == 201
117+
118+
resp = self.client.get(self.path, data)
119+
assert resp.status_code == 200
120+
assert "data" in resp.data
121+
assert "dismissed_ts" in resp.data["data"]
122+
123+
def test_dismiss_str_id(self) -> None:
124+
resp = self.client.put(
125+
self.path,
126+
{
127+
"organization_id": str(self.org.id),
128+
"project_id": str(self.project.id),
129+
"feature": "releases",
130+
"status": "dismissed",
131+
},
132+
)
133+
assert resp.status_code == 201, resp.content
116134

135+
data = {
136+
"organization_id": self.org.id,
137+
"project_id": self.project.id,
138+
"feature": "releases",
139+
}
117140
resp = self.client.get(self.path, data)
118141
assert resp.status_code == 200
142+
assert resp.data
119143
assert "data" in resp.data
120144
assert "dismissed_ts" in resp.data["data"]
121145

0 commit comments

Comments
 (0)