diff --git a/hooks/contact_groups_changed.go b/hooks/contact_groups_changed.go index 6c392e440..b0cce66d4 100644 --- a/hooks/contact_groups_changed.go +++ b/hooks/contact_groups_changed.go @@ -5,7 +5,6 @@ import ( "github.com/gomodule/redigo/redis" "github.com/jmoiron/sqlx" - "github.com/lib/pq" "github.com/nyaruka/goflow/flows" "github.com/nyaruka/goflow/flows/events" "github.com/nyaruka/mailroom/models" @@ -68,18 +67,6 @@ func (h *CommitGroupChangesHook) Apply(ctx context.Context, tx *sqlx.Tx, rp *red return errors.Wrapf(err, "error removing contacts from groups") } - // build the list of all contact ids changed, we'll update modified_on for them - changedIDs := make([]models.ContactID, 0, len(changed)) - for c := range changed { - changedIDs = append(changedIDs, c) - } - if len(changedIDs) > 0 { - _, err = tx.ExecContext(ctx, `UPDATE contacts_contact SET modified_on = NOW() WHERE id = ANY($1)`, pq.Array(changedIDs)) - if err != nil { - return errors.Wrapf(err, "error updating contacts modified_on") - } - } - return nil } diff --git a/web/contact/contact.go b/web/contact/contact.go index 4f77fcb37..52f88aba9 100644 --- a/web/contact/contact.go +++ b/web/contact/contact.go @@ -338,17 +338,12 @@ func handleModify(ctx context.Context, s *web.Server, r *http.Request) (interfac return nil, http.StatusInternalServerError, errors.Wrapf(err, "error starting transaction") } - modifiedContactIDs := make([]models.ContactID, 0, len(contacts)) - // apply our events for _, scene := range scenes { err := models.HandleEvents(ctx, tx, s.RP, org, scene, results[scene.ContactID()].Events) if err != nil { return nil, http.StatusInternalServerError, errors.Wrapf(err, "error applying events") } - if len(results[scene.ContactID()].Events) > 0 { - modifiedContactIDs = append(modifiedContactIDs, scene.ContactID()) - } } // gather all our pre commit events, group them by hook and apply them @@ -357,12 +352,6 @@ func handleModify(ctx context.Context, s *web.Server, r *http.Request) (interfac return nil, http.StatusInternalServerError, errors.Wrapf(err, "error applying pre commit hooks") } - // apply modified_by - err = models.UpdateContactModifiedBy(ctx, tx, modifiedContactIDs, request.UserID) - if err != nil { - return nil, http.StatusInternalServerError, errors.Wrapf(err, "error applying modified_by") - } - // commit our transaction err = tx.Commit() if err != nil { diff --git a/web/contact/testdata/modify.json b/web/contact/testdata/modify.json index 916273895..31b23cad6 100644 --- a/web/contact/testdata/modify.json +++ b/web/contact/testdata/modify.json @@ -1125,5 +1125,95 @@ "count": 0 } ] + }, + { + "label": "multiple modifiers of different types", + "method": "POST", + "path": "/mr/contact/modify", + "body": { + "org_id": 1, + "contact_ids": [ + 10000 + ], + "modifiers": [ + { + "type": "name", + "name": "Juan" + }, + { + "type": "language", + "language": "spa" + }, + { + "type": "groups", + "modification": "add", + "groups": [ + { + "name": "Testers", + "uuid": "5e9d8fab-5e7e-4f51-b533-261af5dea70d" + } + ] + }, + { + "type": "urns", + "modification": "set", + "urns": [ + "tel:+255788555111" + ] + } + ] + }, + "status": 200, + "response": { + "10000": { + "contact": { + "uuid": "6393abc0-283d-4c9b-a1b3-641a035c34bf", + "id": 10000, + "name": "Juan", + "language": "spa", + "status": "active", + "timezone": "America/Los_Angeles", + "created_on": "2018-07-06T12:30:00.123457Z", + "urns": [ + "tel:+255788555111" + ], + "groups": [ + { + "uuid": "5e9d8fab-5e7e-4f51-b533-261af5dea70d", + "name": "Testers" + } + ] + }, + "events": [ + { + "type": "contact_name_changed", + "created_on": "2018-07-06T12:30:00.123456789Z", + "name": "Juan" + }, + { + "type": "contact_language_changed", + "created_on": "2018-07-06T12:30:01.123456789Z", + "language": "spa" + }, + { + "type": "contact_groups_changed", + "created_on": "2018-07-06T12:30:02.123456789Z", + "groups_added": [ + { + "uuid": "5e9d8fab-5e7e-4f51-b533-261af5dea70d", + "name": "Testers" + } + ] + }, + { + "type": "contact_urns_changed", + "created_on": "2018-07-06T12:30:03.123456789Z", + "urns": [ + "tel:+255788555111" + ] + } + ] + } + } } ] \ No newline at end of file