Skip to content

Commit

Permalink
Merge pull request #74 from nyaruka/remove_assign_with_note
Browse files Browse the repository at this point in the history
Remove support for ticket assignment with a note
  • Loading branch information
rowanseymour authored May 18, 2023
2 parents 5133512 + 44dabec commit f90e328
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 20 deletions.
4 changes: 2 additions & 2 deletions core/models/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestTicketNotifications(t *testing.T) {
rt.DB.MustExec(`UPDATE notifications_notification SET is_seen = TRUE`)

// now have a user assign existing tickets to another user
_, err = models.TicketsAssign(ctx, rt.DB, oa, testdata.Admin.ID, []*models.Ticket{ticket1, ticket2}, testdata.Agent.ID, "")
_, err = models.TicketsAssign(ctx, rt.DB, oa, testdata.Admin.ID, []*models.Ticket{ticket1, ticket2}, testdata.Agent.ID)
require.NoError(t, err)

// check that the assigned user gets a ticket activity notification
Expand All @@ -99,7 +99,7 @@ func TestTicketNotifications(t *testing.T) {
rt.DB.MustExec(`UPDATE notifications_notification SET is_seen = TRUE`)

// and finally a user assigning a ticket to themselves
_, err = models.TicketsAssign(ctx, rt.DB, oa, testdata.Editor.ID, []*models.Ticket{ticket3}, testdata.Editor.ID, "")
_, err = models.TicketsAssign(ctx, rt.DB, oa, testdata.Editor.ID, []*models.Ticket{ticket3}, testdata.Editor.ID)
require.NoError(t, err)

// no notifications for self-assignment
Expand Down
6 changes: 3 additions & 3 deletions core/models/ticket_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type TicketEvent struct {
TicketID TicketID `json:"ticket_id" db:"ticket_id"`
EventType TicketEventType `json:"event_type" db:"event_type"`
Note null.String `json:"note,omitempty" db:"note"`
TopicID TopicID `json:"topic_id,omitempty" db:"topic_id"`
TopicID TopicID `json:"topic_id,omitempty" db:"topic_id"`
AssigneeID UserID `json:"assignee_id,omitempty" db:"assignee_id"`
CreatedByID UserID `json:"created_by_id,omitempty" db:"created_by_id"`
CreatedOn time.Time `json:"created_on" db:"created_on"`
Expand All @@ -40,8 +40,8 @@ func NewTicketOpenedEvent(t *Ticket, userID UserID, assigneeID UserID) *TicketEv
return newTicketEvent(t, userID, TicketEventTypeOpened, "", NilTopicID, assigneeID)
}

func NewTicketAssignedEvent(t *Ticket, userID UserID, assigneeID UserID, note string) *TicketEvent {
return newTicketEvent(t, userID, TicketEventTypeAssigned, note, NilTopicID, assigneeID)
func NewTicketAssignedEvent(t *Ticket, userID UserID, assigneeID UserID) *TicketEvent {
return newTicketEvent(t, userID, TicketEventTypeAssigned, "", NilTopicID, assigneeID)
}

func NewTicketNoteAddedEvent(t *Ticket, userID UserID, note string) *TicketEvent {
Expand Down
6 changes: 2 additions & 4 deletions core/models/ticket_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ func TestTicketEvents(t *testing.T) {
assert.Equal(t, null.NullString, e1.Note())
assert.Equal(t, testdata.Admin.ID, e1.CreatedByID())

e2 := models.NewTicketAssignedEvent(modelTicket, testdata.Admin.ID, testdata.Agent.ID, "please handle")
e2 := models.NewTicketAssignedEvent(modelTicket, testdata.Admin.ID, testdata.Agent.ID)
assert.Equal(t, models.TicketEventTypeAssigned, e2.EventType())
assert.Equal(t, testdata.Agent.ID, e2.AssigneeID())
assert.Equal(t, null.String("please handle"), e2.Note())
assert.Equal(t, testdata.Admin.ID, e2.CreatedByID())

e3 := models.NewTicketNoteAddedEvent(modelTicket, testdata.Agent.ID, "please handle")
Expand All @@ -57,6 +56,5 @@ func TestTicketEvents(t *testing.T) {
require.NoError(t, err)

assertdb.Query(t, rt.DB, `SELECT count(*) FROM tickets_ticketevent`).Returns(5)
assertdb.Query(t, rt.DB, `SELECT assignee_id, note FROM tickets_ticketevent WHERE id = $1`, e2.ID()).
Columns(map[string]interface{}{"assignee_id": int64(testdata.Agent.ID), "note": "please handle"})
assertdb.Query(t, rt.DB, `SELECT assignee_id FROM tickets_ticketevent WHERE id = $1`, e2.ID()).Columns(map[string]any{"assignee_id": int64(testdata.Agent.ID)})
}
4 changes: 2 additions & 2 deletions core/models/tickets.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ UPDATE tickets_ticket
WHERE id = ANY($1)`

// TicketsAssign assigns the passed in tickets
func TicketsAssign(ctx context.Context, db Queryer, oa *OrgAssets, userID UserID, tickets []*Ticket, assigneeID UserID, note string) (map[*Ticket]*TicketEvent, error) {
func TicketsAssign(ctx context.Context, db Queryer, oa *OrgAssets, userID UserID, tickets []*Ticket, assigneeID UserID) (map[*Ticket]*TicketEvent, error) {
ids := make([]TicketID, 0, len(tickets))
events := make([]*TicketEvent, 0, len(tickets))
eventsByTicket := make(map[*Ticket]*TicketEvent, len(tickets))
Expand All @@ -444,7 +444,7 @@ func TicketsAssign(ctx context.Context, db Queryer, oa *OrgAssets, userID UserID
t.ModifiedOn = now
t.LastActivityOn = now

e := NewTicketAssignedEvent(ticket, userID, assigneeID, note)
e := NewTicketAssignedEvent(ticket, userID, assigneeID)
events = append(events, e)
eventsByTicket[ticket] = e
}
Expand Down
4 changes: 2 additions & 2 deletions core/models/tickets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestTicketsAssign(t *testing.T) {

testdata.InsertOpenTicket(rt, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "", "", time.Now(), nil)

evts, err := models.TicketsAssign(ctx, rt.DB, oa, testdata.Admin.ID, []*models.Ticket{modelTicket1, modelTicket2, modelTicket3}, testdata.Agent.ID, "please handle these")
evts, err := models.TicketsAssign(ctx, rt.DB, oa, testdata.Admin.ID, []*models.Ticket{modelTicket1, modelTicket2, modelTicket3}, testdata.Agent.ID)
require.NoError(t, err)
assert.Equal(t, 3, len(evts))
assert.Equal(t, models.TicketEventTypeAssigned, evts[modelTicket1].EventType())
Expand All @@ -225,7 +225,7 @@ func TestTicketsAssign(t *testing.T) {
assertdb.Query(t, rt.DB, `SELECT assignee_id FROM tickets_ticket WHERE id = $1`, ticket3.ID).Columns(map[string]interface{}{"assignee_id": int64(testdata.Agent.ID)})

// and there are new assigned events with notifications
assertdb.Query(t, rt.DB, `SELECT count(*) FROM tickets_ticketevent WHERE event_type = 'A' AND note = 'please handle these'`).Returns(3)
assertdb.Query(t, rt.DB, `SELECT count(*) FROM tickets_ticketevent WHERE event_type = 'A'`).Returns(3)
assertdb.Query(t, rt.DB, `SELECT count(*) FROM notifications_notification WHERE user_id = $1 AND notification_type = 'tickets:activity'`, testdata.Agent.ID).Returns(1)

// and daily counts (we only count first assignments of a ticket)
Expand Down
6 changes: 2 additions & 4 deletions web/ticket/assign.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type assignRequest struct {
bulkTicketRequest

AssigneeID models.UserID `json:"assignee_id"`
Note string `json:"note"`
}

// Assigns the tickets with the given ids to the given user
Expand All @@ -27,8 +26,7 @@ type assignRequest struct {
// "org_id": 123,
// "user_id": 234,
// "ticket_ids": [1234, 2345],
// "assignee_id": 567,
// "note": "please look at these"
// "assignee_id": 567
// }
func handleAssign(ctx context.Context, rt *runtime.Runtime, r *assignRequest) (any, int, error) {
oa, err := models.GetOrgAssets(ctx, rt, r.OrgID)
Expand All @@ -41,7 +39,7 @@ func handleAssign(ctx context.Context, rt *runtime.Runtime, r *assignRequest) (a
return nil, 0, errors.Wrapf(err, "error loading tickets for org: %d", r.OrgID)
}

evts, err := models.TicketsAssign(ctx, rt.DB, oa, r.UserID, tickets, r.AssigneeID, r.Note)
evts, err := models.TicketsAssign(ctx, rt.DB, oa, r.UserID, tickets, r.AssigneeID)
if err != nil {
return nil, 0, errors.Wrap(err, "error assigning tickets")
}
Expand Down
5 changes: 2 additions & 3 deletions web/ticket/testdata/assign.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
2,
3
],
"assignee_id": 6,
"note": "please handle"
"assignee_id": 6
},
"status": 200,
"response": {
Expand All @@ -27,7 +26,7 @@
"count": 3
},
{
"query": "SELECT count(*) FROM tickets_ticketevent WHERE event_type = 'A' AND created_by_id = 3 AND note = 'please handle'",
"query": "SELECT count(*) FROM tickets_ticketevent WHERE event_type = 'A' AND created_by_id = 3",
"count": 2
}
]
Expand Down

0 comments on commit f90e328

Please sign in to comment.