Skip to content

Commit 2178fc2

Browse files
authored
feat(api): Add author when creating incident activity [SEN-700] (#13440)
When using the endpoint to create an incident, we should attach an author to the created activity item. Fixes SEN-700
1 parent 670ee2e commit 2178fc2

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/sentry/api/endpoints/organization_incident_index.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def post(self, request, organization):
122122
date_detected=result.get('dateDetected', result['dateStarted']),
123123
projects=result['projects'],
124124
groups=groups,
125+
user=request.user,
125126
)
126127
return Response(serialize(incident, request.user), status=201)
127128
return Response(serializer.errors, status=400)

src/sentry/incidents/logic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def create_incident(
4141
detection_uuid=None,
4242
projects=None,
4343
groups=None,
44+
user=None,
4445
):
4546
assert status in (IncidentStatus.CREATED, IncidentStatus.DETECTED)
4647
if date_detected is None:
@@ -81,6 +82,7 @@ def create_incident(
8182
incident,
8283
activity_status,
8384
event_stats_snapshot=event_stats_snapshot,
85+
user=user,
8486
)
8587
return incident
8688

tests/sentry/api/endpoints/test_organization_incident.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from freezegun import freeze_time
66

77
from sentry.api.serializers import serialize
8-
from sentry.incidents.models import Incident, IncidentStatus
8+
from sentry.incidents.models import Incident, IncidentStatus, IncidentActivity
99
from sentry.testutils import APITestCase
1010

1111

@@ -98,6 +98,10 @@ def test_simple(self):
9898
)
9999
assert resp.data == serialize([Incident.objects.get(id=resp.data['id'])])[0]
100100

101+
# should create an activity authored by user
102+
activity = IncidentActivity.objects.get(incident_id=resp.data['id'])
103+
assert activity.user == self.user
104+
101105
def test_project_access(self):
102106
self.create_member(
103107
user=self.user,

0 commit comments

Comments
 (0)