Skip to content

Commit 5a9f327

Browse files
authored
feat(prompts): support a visible status for un-hiding components (#74228)
Needed for #74209. We're using the prompt backend to persist a user's decision to hide/unhide user feedback in the issue details page. The goal is to be able to toggle between [promptIsDismissed](https://github.com/getsentry/sentry/blob/539945981a00bc93a9525e61e052563df701757a/static/app/utils/promptIsDismissed.tsx#L18) = true/false.
1 parent 3764770 commit 5a9f327

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

src/sentry/api/endpoints/prompts_activity.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import calendar
2+
from typing import Any
23

34
from django.db import IntegrityError, router, transaction
45
from django.db.models import Q
@@ -16,7 +17,7 @@
1617
from sentry.models.promptsactivity import PromptsActivity
1718
from sentry.utils.prompts import prompt_config
1819

19-
VALID_STATUSES = frozenset(("snoozed", "dismissed"))
20+
VALID_STATUSES = frozenset(("snoozed", "dismissed", "visible"))
2021

2122

2223
# Endpoint to retrieve multiple PromptsActivity at once
@@ -100,12 +101,15 @@ def put(self, request: Request, **kwargs):
100101
else:
101102
fields["organization_id"] = 0
102103

103-
data = {}
104+
data: dict[str, Any] = {}
104105
now = calendar.timegm(timezone.now().utctimetuple())
105106
if status == "snoozed":
106107
data["snoozed_ts"] = now
107108
elif status == "dismissed":
108109
data["dismissed_ts"] = now
110+
elif status == "visible":
111+
data["snoozed_ts"] = None
112+
data["dismissed_ts"] = None
109113

110114
try:
111115
with transaction.atomic(router.db_for_write(PromptsActivity)):

tests/sentry/api/endpoints/test_prompts_activity.py

+66
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,72 @@ def test_snooze_legacy_path(self):
123123
self.path = reverse("sentry-api-0-prompts-activity")
124124
self.test_snooze()
125125

126+
def test_visible(self):
127+
data = {
128+
"organization_id": self.org.id,
129+
"project_id": self.project.id,
130+
"feature": "releases",
131+
}
132+
resp = self.client.get(self.path, data)
133+
assert resp.status_code == 200
134+
assert resp.data.get("data", None) is None
135+
136+
self.client.put(
137+
self.path,
138+
{
139+
"organization_id": self.org.id,
140+
"project_id": self.project.id,
141+
"feature": "releases",
142+
"status": "visible",
143+
},
144+
)
145+
146+
resp = self.client.get(self.path, data)
147+
assert resp.status_code == 200
148+
assert "data" in resp.data
149+
assert resp.data["data"].get("dismissed_ts") is None
150+
assert resp.data["data"].get("snoozed_ts") is None
151+
152+
def test_visible_legacy_path(self):
153+
self.path = reverse("sentry-api-0-prompts-activity")
154+
self.test_visible()
155+
156+
def test_visible_after_dismiss(self):
157+
data = {
158+
"organization_id": self.org.id,
159+
"project_id": self.project.id,
160+
"feature": "releases",
161+
}
162+
resp = self.client.get(self.path, data)
163+
assert resp.status_code == 200
164+
assert resp.data.get("data", None) is None
165+
166+
self.client.put(
167+
self.path,
168+
{
169+
"organization_id": self.org.id,
170+
"project_id": self.project.id,
171+
"feature": "releases",
172+
"status": "dismiss",
173+
},
174+
)
175+
176+
self.client.put(
177+
self.path,
178+
{
179+
"organization_id": self.org.id,
180+
"project_id": self.project.id,
181+
"feature": "releases",
182+
"status": "visible",
183+
},
184+
)
185+
186+
resp = self.client.get(self.path, data)
187+
assert resp.status_code == 200
188+
assert "data" in resp.data
189+
assert resp.data["data"].get("dismissed_ts") is None
190+
assert resp.data["data"].get("snoozed_ts") is None
191+
126192
def test_batched(self):
127193
data = {
128194
"organization_id": self.org.id,

0 commit comments

Comments
 (0)