Skip to content

feat(prompts): support a visible status for un-hiding components #74228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 15, 2024
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
8 changes: 6 additions & 2 deletions src/sentry/api/endpoints/prompts_activity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import calendar
from typing import Any

from django.db import IntegrityError, router, transaction
from django.db.models import Q
Expand All @@ -16,7 +17,7 @@
from sentry.models.promptsactivity import PromptsActivity
from sentry.utils.prompts import prompt_config

VALID_STATUSES = frozenset(("snoozed", "dismissed"))
VALID_STATUSES = frozenset(("snoozed", "dismissed", "visible"))


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

data = {}
data: dict[str, Any] = {}
now = calendar.timegm(timezone.now().utctimetuple())
if status == "snoozed":
data["snoozed_ts"] = now
elif status == "dismissed":
data["dismissed_ts"] = now
elif status == "visible":
data["snoozed_ts"] = None
data["dismissed_ts"] = None

try:
with transaction.atomic(router.db_for_write(PromptsActivity)):
Expand Down
66 changes: 66 additions & 0 deletions tests/sentry/api/endpoints/test_prompts_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,72 @@ def test_snooze_legacy_path(self):
self.path = reverse("sentry-api-0-prompts-activity")
self.test_snooze()

def test_visible(self):
data = {
"organization_id": self.org.id,
"project_id": self.project.id,
"feature": "releases",
}
resp = self.client.get(self.path, data)
assert resp.status_code == 200
assert resp.data.get("data", None) is None

self.client.put(
self.path,
{
"organization_id": self.org.id,
"project_id": self.project.id,
"feature": "releases",
"status": "visible",
},
)

resp = self.client.get(self.path, data)
assert resp.status_code == 200
assert "data" in resp.data
assert resp.data["data"].get("dismissed_ts") is None
assert resp.data["data"].get("snoozed_ts") is None

def test_visible_legacy_path(self):
self.path = reverse("sentry-api-0-prompts-activity")
self.test_visible()

def test_visible_after_dismiss(self):
data = {
"organization_id": self.org.id,
"project_id": self.project.id,
"feature": "releases",
}
resp = self.client.get(self.path, data)
assert resp.status_code == 200
assert resp.data.get("data", None) is None

self.client.put(
self.path,
{
"organization_id": self.org.id,
"project_id": self.project.id,
"feature": "releases",
"status": "dismiss",
},
)

self.client.put(
self.path,
{
"organization_id": self.org.id,
"project_id": self.project.id,
"feature": "releases",
"status": "visible",
},
)

resp = self.client.get(self.path, data)
assert resp.status_code == 200
assert "data" in resp.data
assert resp.data["data"].get("dismissed_ts") is None
assert resp.data["data"].get("snoozed_ts") is None

def test_batched(self):
data = {
"organization_id": self.org.id,
Expand Down
Loading