Skip to content

Commit

Permalink
feat(issues/feedback): allow hasAttachments to be expanded for feedba…
Browse files Browse the repository at this point in the history
…ck usecase (#70102)

relates to #67795

allow expansion of a new flag on an issue, `hasAttachments`, which will
specify whether a group has any event attachments. we'll use this in
user feedback to show a indicator when a feedback has an attachment
(e.g. screenshot).

context: the user feedback list shows small icon indicators when certain
properties are true (e.g. `hasReplay`, `hasLinkedError`) and we want to
add another one to this list: `hasAttachments` (aka `hasScreenshots`).
however, the list relies on having issue data only. we don't have access
to the attachments list just from the issue (we'd have to do a separate
api call on the frontend to get the list of attachments which is
unideal), so instead i'm adding an option to expand and directly put the
`hasAttachments` property onto the issue when requested.

frontend changes using this PR are here:
#70109
  • Loading branch information
michellewzhang authored May 2, 2024
1 parent 15da708 commit 7f2ff4c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/sentry/api/endpoints/group_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from sentry.issues.escalating_group_forecast import EscalatingGroupForecast
from sentry.issues.grouptype import GroupCategory
from sentry.models.activity import Activity
from sentry.models.eventattachment import EventAttachment
from sentry.models.group import Group
from sentry.models.groupinbox import get_inbox_details
from sentry.models.grouplink import GroupLink
Expand Down Expand Up @@ -235,6 +236,17 @@ def get(self, request: Request, group) -> Response:
)
data.update({"sentryAppIssues": sentry_app_issues})

if "hasAttachments" in expand:
if not features.has(
"organizations:event-attachments",
group.project.organization,
actor=request.user,
):
return self.respond(status=404)

num_attachments = EventAttachment.objects.filter(group_id=group.id).count()
data.update({"hasAttachments": num_attachments > 0})

data.update(
{
"activity": serialize(activity, request.user),
Expand Down
16 changes: 16 additions & 0 deletions src/sentry/api/serializers/models/group_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from sentry.constants import StatsPeriod
from sentry.issues.grouptype import GroupCategory
from sentry.models.environment import Environment
from sentry.models.eventattachment import EventAttachment
from sentry.models.group import Group
from sentry.models.groupinbox import get_inbox_details
from sentry.models.grouplink import GroupLink
Expand Down Expand Up @@ -396,6 +397,18 @@ def get_attrs(
)
attrs[item].update({"sentryAppIssues": sentry_app_issues})

if self._expand("hasAttachments"):
if not features.has(
"organizations:event-attachments",
item.project.organization,
actor=request.user,
):
return self.respond(status=404)

for item in item_list:
num_attachments = EventAttachment.objects.filter(group_id=item.id).count()
attrs[item].update({"hasAttachments": num_attachments > 0})

return attrs

def serialize(
Expand Down Expand Up @@ -454,6 +467,9 @@ def serialize(
if self._expand("sentryAppIssues"):
result["sentryAppIssues"] = attrs["sentryAppIssues"]

if self._expand("hasAttachments"):
result["hasAttachments"] = attrs["hasAttachments"]

return result

def query_tsdb(
Expand Down
43 changes: 43 additions & 0 deletions tests/sentry/issues/endpoints/test_organization_group_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
)
from sentry.models.activity import Activity
from sentry.models.apitoken import ApiToken
from sentry.models.eventattachment import EventAttachment
from sentry.models.files.file import File
from sentry.models.group import Group, GroupStatus
from sentry.models.groupassignee import GroupAssignee
from sentry.models.groupbookmark import GroupBookmark
Expand Down Expand Up @@ -1853,6 +1855,47 @@ def test_expand_sentry_app_issues(self):
assert response.data[0]["sentryAppIssues"][0]["displayName"] == issue_1.display_name
assert response.data[0]["sentryAppIssues"][1]["displayName"] == issue_2.display_name

@with_feature("organizations:event-attachments")
def test_expand_has_attachments(self):
event = self.store_event(
data={"timestamp": iso_format(before_now(seconds=500)), "fingerprint": ["group-1"]},
project_id=self.project.id,
)
query = "status:unresolved"
self.login_as(user=self.user)
response = self.get_response(
sort_by="date", limit=10, query=query, expand=["hasAttachments"]
)
assert response.status_code == 200
assert len(response.data) == 1
assert int(response.data[0]["id"]) == event.group.id
# No attachments
assert response.data[0]["hasAttachments"] is False

# Test with no expand
response = self.get_response(sort_by="date", limit=10, query=query)
assert response.status_code == 200
assert len(response.data) == 1
assert int(response.data[0]["id"]) == event.group.id
assert "hasAttachments" not in response.data[0]

# Add 1 attachment
file_attachment = File.objects.create(name="hello.png", type="image/png")
EventAttachment.objects.create(
group_id=event.group.id,
event_id=event.event_id,
project_id=event.project_id,
file_id=file_attachment.id,
type=file_attachment.type,
name="hello.png",
)

response = self.get_response(
sort_by="date", limit=10, query=query, expand=["hasAttachments"]
)
assert response.status_code == 200
assert response.data[0]["hasAttachments"] is True

def test_expand_owners(self):
event = self.store_event(
data={"timestamp": iso_format(before_now(seconds=500)), "fingerprint": ["group-1"]},
Expand Down

0 comments on commit 7f2ff4c

Please sign in to comment.