Skip to content

Commit

Permalink
Generate ticket activity notifications for new ticket notes
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Sep 6, 2021
1 parent 68dafd9 commit 76bdedd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/models/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NotificationsFromTicketEvents(ctx context.Context, db Queryer, oa *OrgAsset
}
case TicketEventTypeNoteAdded:
// notify ticket assignee if they didn't add note themselves
if ticket.AssigneeID() != evt.CreatedByID() {
if ticket.AssigneeID() != NilUserID && ticket.AssigneeID() != evt.CreatedByID() {
notifyTicketsActivity[ticket.AssigneeID()] = true
}
}
Expand Down
5 changes: 5 additions & 0 deletions core/models/tickets.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,11 @@ func TicketsAddNote(ctx context.Context, db Queryer, oa *OrgAssets, userID UserI
return nil, errors.Wrapf(err, "error inserting ticket events")
}

err = NotificationsFromTicketEvents(ctx, db, oa, eventsByTicket)
if err != nil {
return nil, errors.Wrap(err, "error inserting notifications")
}

return eventsByTicket, nil
}

Expand Down
4 changes: 3 additions & 1 deletion core/models/tickets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestTicketsAddNote(t *testing.T) {
ticket1 := testdata.InsertClosedTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Problem", "Where my shoes", "123", nil)
modelTicket1 := ticket1.Load(db)

ticket2 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Old Problem", "Where my pants", "234", nil)
ticket2 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Old Problem", "Where my pants", "234", testdata.Agent)
modelTicket2 := ticket2.Load(db)

testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Ignore", "", "", nil)
Expand All @@ -237,6 +237,8 @@ func TestTicketsAddNote(t *testing.T) {

// check there are new note events
testsuite.AssertQuery(t, db, `SELECT count(*) FROM tickets_ticketevent WHERE event_type = 'N' AND note = 'spam'`).Returns(2)

testsuite.AssertQuery(t, db, `SELECT count(*) FROM notifications_notification WHERE user_id = $1 AND notification_type = 'tickets:activity'`, testdata.Agent.ID).Returns(1)
}

func TestTicketsChangeTopic(t *testing.T) {
Expand Down

0 comments on commit 76bdedd

Please sign in to comment.