From 76bdeddedac6fa32a041eb993adcb79acb377357 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Mon, 6 Sep 2021 16:46:15 -0500 Subject: [PATCH] Generate ticket activity notifications for new ticket notes --- core/models/notifications.go | 2 +- core/models/tickets.go | 5 +++++ core/models/tickets_test.go | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/models/notifications.go b/core/models/notifications.go index 3491d8786..1e2f27589 100644 --- a/core/models/notifications.go +++ b/core/models/notifications.go @@ -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 } } diff --git a/core/models/tickets.go b/core/models/tickets.go index e6f01dcc3..9105f5404 100644 --- a/core/models/tickets.go +++ b/core/models/tickets.go @@ -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 } diff --git a/core/models/tickets_test.go b/core/models/tickets_test.go index 17da6cb33..01523cb70 100644 --- a/core/models/tickets_test.go +++ b/core/models/tickets_test.go @@ -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) @@ -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) {