Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions src/sentry/api/endpoints/event_ai_suggested_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,30 @@ def get(self, request: Request, project, event_id) -> HttpResponse | StreamingHt
if event is None:
raise ResourceDoesNotExist

# Check the OpenAI access policy
policy = get_openai_policy(
request.organization,
request.user,
pii_certified=request.GET.get("pii_certified") == "yes",
)
policy_failure = None
stream = request.GET.get("stream") == "yes"

if policy == "subprocessor":
policy_failure = "subprocessor"
elif policy == "individual_consent":
if request.GET.get("consent") != "yes":
policy_failure = "individual_consent"
elif policy == "pii_certification_required":
policy_failure = "pii_certification_required"
elif policy == "allowed":
pass
# If the option has specifically been set to False,
if not bool(request.organization.get_option("sentry:ai_suggested_solution", default=False)):
policy_failure = "organization_consent_required"
Copy link
Member

Choose a reason for hiding this comment

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

I typically would suggest handling this failure case in the UI gracefully too, but as we're sunsetting this feature soon with autofix anyways, this should be fine. It will show a generic error component.

else:
logger.warning("Unknown OpenAI policy state")
# Check the OpenAI access policy
policy = get_openai_policy(
request.organization,
request.user,
pii_certified=request.GET.get("pii_certified") == "yes",
)
stream = request.GET.get("stream") == "yes"

if policy == "subprocessor":
policy_failure = "subprocessor"
elif policy == "individual_consent":
if request.GET.get("consent") != "yes":
policy_failure = "individual_consent"
elif policy == "pii_certification_required":
policy_failure = "pii_certification_required"
elif policy == "allowed":
pass
else:
logger.warning("Unknown OpenAI policy state")

if policy_failure is not None:
return HttpResponse(
Expand Down
12 changes: 12 additions & 0 deletions tests/sentry/api/endpoints/test_event_ai_suggested_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,25 @@ def test_consent(self):
"sentry.api.endpoints.event_ai_suggested_fix.get_openai_policy",
return_value="individual_consent",
):
response = self.client.get(self.path)
assert response.status_code == 403
assert response.json() == {"restriction": "organization_consent_required"}

self.organization.update_option("sentry:ai_suggested_solution", True)
response = self.client.get(self.path)
assert response.status_code == 403
assert response.json() == {"restriction": "individual_consent"}

response = self.client.get(self.path + "?consent=yes")
assert response.status_code == 200
assert response.json() == {"suggestion": "AI generated response"}

self.organization.update_option("sentry:ai_suggested_solution", False)
response = self.client.get(self.path + "?consent=yes")
assert response.status_code == 403
assert response.json() == {"restriction": "organization_consent_required"}

self.organization.update_option("sentry:ai_suggested_solution", True)
with patch(
"sentry.api.endpoints.event_ai_suggested_fix.get_openai_policy",
return_value="subprocessor",
Expand Down
Loading