Skip to content

Commit

Permalink
Merge branch 'main' into less_reset
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Sep 17, 2021
2 parents af5688d + 80b4b5c commit a056759
Show file tree
Hide file tree
Showing 40 changed files with 198 additions and 179 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
v6.5.28
----------
* Add warning log entry when task takes longer than 1 minute

v6.5.27
----------
* Update to latest goflow (fixes word_slice)

v6.5.26
----------
* Update to latest goflow

v6.5.25
----------
* Add notifications for contact imports and set contact import status
Expand Down
4 changes: 2 additions & 2 deletions core/goflow/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ type simulatorTicketService struct {
ticketer *flows.Ticketer
}

func (s *simulatorTicketService) Open(session flows.Session, topic *flows.Topic, subject, body string, assignee *flows.User, logHTTP flows.HTTPLogCallback) (*flows.Ticket, error) {
return flows.OpenTicket(s.ticketer, topic, subject, body, assignee), nil
func (s *simulatorTicketService) Open(session flows.Session, topic *flows.Topic, body string, assignee *flows.User, logHTTP flows.HTTPLogCallback) (*flows.Ticket, error) {
return flows.OpenTicket(s.ticketer, topic, body, assignee), nil
}

func simulatorAirtimeServiceFactory(session flows.Session) (flows.AirtimeService, error) {
Expand Down
6 changes: 4 additions & 2 deletions core/goflow/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ func TestSimulatorTicket(t *testing.T) {
svc, err := goflow.Simulator(rt.Config).Services().Ticket(nil, flows.NewTicketer(ticketer))
assert.NoError(t, err)

ticket, err := svc.Open(nil, nil, "New ticket", "Where are my cookies?", nil, nil)
oa, err := models.GetOrgAssets(ctx, db, testdata.Org1.ID)
require.NoError(t, err)

ticket, err := svc.Open(nil, oa.SessionAssets().Topics().FindByName("General"), "Where are my cookies?", nil, nil)
assert.NoError(t, err)
assert.Equal(t, testdata.Mailgun.UUID, ticket.Ticketer().UUID())
assert.Equal(t, "New ticket", ticket.Subject())
assert.Equal(t, "Where are my cookies?", ticket.Body())
}

Expand Down
1 change: 0 additions & 1 deletion core/handlers/ticket_opened.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func handleTicketOpened(ctx context.Context, tx *sqlx.Tx, rp *redis.Pool, oa *mo
ticketer.ID(),
event.Ticket.ExternalID,
topicID,
event.Ticket.Subject,
event.Ticket.Body,
assigneeID,
map[string]interface{}{
Expand Down
4 changes: 1 addition & 3 deletions core/handlers/ticket_opened_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestTicketOpened(t *testing.T) {
}))

// an existing ticket
cathyTicket := models.NewTicket(flows.TicketUUID(uuids.New()), testdata.Org1.ID, testdata.Cathy.ID, testdata.Mailgun.ID, "748363", testdata.DefaultTopic.ID, "Old Question", "Who?", models.NilUserID, nil)
cathyTicket := models.NewTicket(flows.TicketUUID(uuids.New()), testdata.Org1.ID, testdata.Cathy.ID, testdata.Mailgun.ID, "748363", testdata.DefaultTopic.ID, "Who?", models.NilUserID, nil)
err := models.InsertTickets(ctx, db, []*models.Ticket{cathyTicket})
require.NoError(t, err)

Expand All @@ -57,7 +57,6 @@ func TestTicketOpened(t *testing.T) {
handlers.NewActionUUID(),
assets.NewTicketerReference(testdata.Mailgun.UUID, "Mailgun (IT Support)"),
assets.NewTopicReference(testdata.SupportTopic.UUID, "Support"),
"",
"Where are my cookies?",
assets.NewUserReference(testdata.Admin.Email, "Admin"),
"Email Ticket",
Expand All @@ -68,7 +67,6 @@ func TestTicketOpened(t *testing.T) {
handlers.NewActionUUID(),
assets.NewTicketerReference(testdata.Zendesk.UUID, "Zendesk (Nyaruka)"),
nil,
"Interesting",
"I've found some cookies",
nil,
"Zen Ticket",
Expand Down
6 changes: 3 additions & 3 deletions core/models/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/goflow/assets/static/types"
"github.com/nyaruka/goflow/assets/static"
"github.com/nyaruka/mailroom/core/models"
"github.com/nyaruka/mailroom/testsuite"
"github.com/nyaruka/mailroom/testsuite/testdata"
Expand Down Expand Up @@ -33,8 +33,8 @@ func TestCloneForSimulation(t *testing.T) {
}

testChannels := []assets.Channel{
types.NewChannel("d7be3965-4c76-4abd-af78-ebc0b84ab621", "Test Channel 1", "1234567890", []string{"tel"}, nil, nil),
types.NewChannel("fd130d20-65f8-43fc-a3c5-a3fa4d1e4193", "Test Channel 2", "2345678901", []string{"tel"}, nil, nil),
static.NewChannel("d7be3965-4c76-4abd-af78-ebc0b84ab621", "Test Channel 1", "1234567890", []string{"tel"}, nil, nil),
static.NewChannel("fd130d20-65f8-43fc-a3c5-a3fa4d1e4193", "Test Channel 2", "2345678901", []string{"tel"}, nil, nil),
}

clone, err := oa.CloneForSimulation(ctx, db, newDefs, testChannels)
Expand Down
2 changes: 1 addition & 1 deletion core/models/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func LoadContacts(ctx context.Context, db Queryer, org *OrgAssets, ids []Contact
for _, t := range e.Tickets {
ticketer := org.TicketerByID(t.TicketerID)
if ticketer != nil {
tickets = append(tickets, NewTicket(t.UUID, org.OrgID(), contact.ID(), ticketer.ID(), t.ExternalID, t.TopicID, t.Subject, t.Body, t.AssigneeID, nil))
tickets = append(tickets, NewTicket(t.UUID, org.OrgID(), contact.ID(), ticketer.ID(), t.ExternalID, t.TopicID, t.Body, t.AssigneeID, nil))
}
}
contact.tickets = tickets
Expand Down
8 changes: 3 additions & 5 deletions core/models/contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func TestContacts(t *testing.T) {
defer testsuite.Reset()

testdata.InsertContactURN(db, testdata.Org1, testdata.Bob, "whatsapp:250788373373", 999)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.SupportTopic, "Problem!", "Where are my shoes?", "1234", testdata.Agent)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.SalesTopic, "Another Problem!", "Where are my pants?", "2345", nil)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Bob, testdata.Mailgun, testdata.DefaultTopic, "Urgent", "His name is Bob", "", testdata.Editor)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.SupportTopic, "Where are my shoes?", "1234", testdata.Agent)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.SalesTopic, "Where are my pants?", "2345", nil)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Bob, testdata.Mailgun, testdata.DefaultTopic, "His name is Bob", "", testdata.Editor)

// delete mailgun ticketer
db.MustExec(`UPDATE tickets_ticketer SET is_active = false WHERE id = $1`, testdata.Mailgun.ID)
Expand Down Expand Up @@ -63,10 +63,8 @@ func TestContacts(t *testing.T) {
assert.Equal(t, 2, cathy.Tickets().Count())

cathyTickets := cathy.Tickets().All()
assert.Equal(t, "Problem!", cathyTickets[0].Subject())
assert.Equal(t, "Support", cathyTickets[0].Topic().Name())
assert.Equal(t, "agent1@nyaruka.com", cathyTickets[0].Assignee().Email())
assert.Equal(t, "Another Problem!", cathyTickets[1].Subject())
assert.Equal(t, "Sales", cathyTickets[1].Topic().Name())
assert.Nil(t, cathyTickets[1].Assignee())

Expand Down
2 changes: 1 addition & 1 deletion core/models/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func TestNonPersistentBroadcasts(t *testing.T) {

defer testsuite.ResetData(db)

ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Bob, testdata.Mailgun, testdata.DefaultTopic, "Problem", "", "", nil)
ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Bob, testdata.Mailgun, testdata.DefaultTopic, "", "", nil)
modelTicket := ticket.Load(db)

translations := map[envs.Language]*models.BroadcastTranslation{envs.Language("eng"): {Text: "Hi there"}}
Expand Down
2 changes: 1 addition & 1 deletion core/models/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func assertNotifications(t *testing.T, ctx context.Context, db *sqlx.DB, after t
}

func openTicket(t *testing.T, ctx context.Context, db *sqlx.DB, openedBy *testdata.User, assignee *testdata.User) (*models.Ticket, *models.TicketEvent) {
ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Internal, testdata.SupportTopic, "", "Where my pants", "", assignee)
ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Internal, testdata.SupportTopic, "Where my pants", "", assignee)
modelTicket := ticket.Load(db)

openedEvent := models.NewTicketOpenedEvent(modelTicket, openedBy.SafeID(), assignee.SafeID())
Expand Down
2 changes: 1 addition & 1 deletion core/models/ticket_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestTicketEvents(t *testing.T) {
db.MustExec(`DELETE FROM tickets_ticket`)
}()

ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Need help", "Have you seen my cookies?", "17", nil)
ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Have you seen my cookies?", "17", nil)
modelTicket := ticket.Load(db)

e1 := models.NewTicketOpenedEvent(modelTicket, testdata.Admin.ID, testdata.Agent.ID)
Expand Down
14 changes: 3 additions & 11 deletions core/models/tickets.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ type Ticket struct {
ExternalID null.String `db:"external_id"`
Status TicketStatus `db:"status"`
TopicID TopicID `db:"topic_id"`
Subject string `db:"subject"`
Body string `db:"body"`
AssigneeID UserID `db:"assignee_id"`
Config null.Map `db:"config"`
Expand All @@ -88,7 +87,7 @@ type Ticket struct {
}

// NewTicket creates a new open ticket
func NewTicket(uuid flows.TicketUUID, orgID OrgID, contactID ContactID, ticketerID TicketerID, externalID string, topicID TopicID, subject, body string, assigneeID UserID, config map[string]interface{}) *Ticket {
func NewTicket(uuid flows.TicketUUID, orgID OrgID, contactID ContactID, ticketerID TicketerID, externalID string, topicID TopicID, body string, assigneeID UserID, config map[string]interface{}) *Ticket {
t := &Ticket{}
t.t.UUID = uuid
t.t.OrgID = orgID
Expand All @@ -97,7 +96,6 @@ func NewTicket(uuid flows.TicketUUID, orgID OrgID, contactID ContactID, ticketer
t.t.ExternalID = null.String(externalID)
t.t.Status = TicketStatusOpen
t.t.TopicID = topicID
t.t.Subject = subject
t.t.Body = body
t.t.AssigneeID = assigneeID
t.t.Config = null.NewMap(config)
Expand All @@ -112,7 +110,6 @@ func (t *Ticket) TicketerID() TicketerID { return t.t.TicketerID }
func (t *Ticket) ExternalID() null.String { return t.t.ExternalID }
func (t *Ticket) Status() TicketStatus { return t.t.Status }
func (t *Ticket) TopicID() TopicID { return t.t.TopicID }
func (t *Ticket) Subject() string { return t.t.Subject }
func (t *Ticket) Body() string { return t.t.Body }
func (t *Ticket) AssigneeID() UserID { return t.t.AssigneeID }
func (t *Ticket) LastActivityOn() time.Time { return t.t.LastActivityOn }
Expand Down Expand Up @@ -146,7 +143,6 @@ func (t *Ticket) FlowTicket(oa *OrgAssets) (*flows.Ticket, error) {
t.UUID(),
oa.SessionAssets().Ticketers().Get(modelTicketer.UUID()),
topic,
t.Subject(),
t.Body(),
string(t.ExternalID()),
assignee,
Expand Down Expand Up @@ -183,7 +179,6 @@ SELECT
t.external_id AS external_id,
t.status AS status,
t.topic_id AS topic_id,
t.subject AS subject,
t.body AS body,
t.assignee_id AS assignee_id,
t.config AS config,
Expand Down Expand Up @@ -213,7 +208,6 @@ SELECT
t.external_id AS external_id,
t.status AS status,
t.topic_id AS topic_id,
t.subject AS subject,
t.body AS body,
t.assignee_id AS assignee_id,
t.config AS config,
Expand Down Expand Up @@ -262,7 +256,6 @@ SELECT
t.external_id AS external_id,
t.status AS status,
t.topic_id AS topic_id,
t.subject AS subject,
t.body AS body,
t.assignee_id AS assignee_id,
t.config AS config,
Expand Down Expand Up @@ -291,7 +284,6 @@ SELECT
t.external_id AS external_id,
t.status AS status,
t.topic_id AS topic_id,
t.subject AS subject,
t.body AS body,
t.assignee_id AS assignee_id,
t.config AS config,
Expand Down Expand Up @@ -333,8 +325,8 @@ func lookupTicket(ctx context.Context, db Queryer, query string, params ...inter

const insertTicketSQL = `
INSERT INTO
tickets_ticket(uuid, org_id, contact_id, ticketer_id, external_id, status, topic_id, subject, body, assignee_id, config, opened_on, modified_on, last_activity_on)
VALUES( :uuid, :org_id, :contact_id, :ticketer_id, :external_id, :status, :topic_id, :subject, :body, :assignee_id, :config, NOW(), NOW() , NOW())
tickets_ticket(uuid, org_id, contact_id, ticketer_id, external_id, status, topic_id, body, assignee_id, config, opened_on, modified_on, last_activity_on)
VALUES( :uuid, :org_id, :contact_id, :ticketer_id, :external_id, :status, :topic_id, :body, :assignee_id, :config, NOW(), NOW() , NOW())
RETURNING
id
`
Expand Down
Loading

0 comments on commit a056759

Please sign in to comment.