Skip to content

Commit

Permalink
Merge pull request #349 from nyaruka/deindex_fix
Browse files Browse the repository at this point in the history
Remove check in deindex contact for contact being inactive
  • Loading branch information
rowanseymour authored Sep 26, 2024
2 parents c7014eb + 9cd4d6b commit 793a278
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 47 deletions.
8 changes: 1 addition & 7 deletions web/contact/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ func TestCreate(t *testing.T) {
func TestDeindex(t *testing.T) {
ctx, rt := testsuite.Runtime()

defer func() {
rt.DB.MustExec(`UPDATE contacts_contact SET is_active = true, modified_on = NOW() WHERE id IN ($1, $2)`, testdata.Bob.ID, testdata.George.ID)

testsuite.Reset(testsuite.ResetElastic)
}()

rt.DB.MustExec(`UPDATE contacts_contact SET is_active = false, modified_on = NOW() WHERE id IN ($1, $2)`, testdata.Bob.ID, testdata.George.ID)
defer testsuite.Reset(testsuite.ResetElastic)

testsuite.RunWebTests(t, ctx, rt, "testdata/deindex.json", nil)
}
Expand Down
10 changes: 0 additions & 10 deletions web/contact/deindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net/http"

"github.com/lib/pq"
"github.com/nyaruka/mailroom/core/models"
"github.com/nyaruka/mailroom/core/search"
"github.com/nyaruka/mailroom/runtime"
Expand All @@ -29,15 +28,6 @@ type deindexRequest struct {

// handles a request to resend the given messages
func handleDeindex(ctx context.Context, rt *runtime.Runtime, r *deindexRequest) (any, int, error) {
// check that org exists and is not active
var count int
if err := rt.DB.Get(&count, `SELECT count(*) FROM contacts_contact WHERE id = ANY($1) AND org_id = $2 AND NOT is_active`, pq.Array(r.ContactIDs), r.OrgID); err != nil {
return nil, 0, fmt.Errorf("error querying contacts to be de-indexed in org #%d: %w", r.OrgID, err)
}
if count != len(r.ContactIDs) {
return nil, 0, fmt.Errorf("some contacts to be de-indexed in org #%d are active or don't exist", r.OrgID)
}

deindexed, err := search.DeindexContactsByID(ctx, rt, r.OrgID, r.ContactIDs)
if err != nil {
return nil, 0, fmt.Errorf("error de-indexing contacts in org #%d: %w", r.OrgID, err)
Expand Down
30 changes: 0 additions & 30 deletions web/contact/testdata/deindex.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,6 @@
"error": "illegal method: GET"
}
},
{
"label": "invalid contact id",
"method": "POST",
"path": "/mr/contact/deindex",
"body": {
"org_id": 1,
"contact_ids": [
100000000
]
},
"status": 500,
"response": {
"error": "some contacts to be de-indexed in org #1 are active or don't exist"
}
},
{
"label": "contact that is still active",
"method": "POST",
"path": "/mr/contact/deindex",
"body": {
"org_id": 1,
"contact_ids": [
10000
]
},
"status": 500,
"response": {
"error": "some contacts to be de-indexed in org #1 are active or don't exist"
}
},
{
"label": "contacts that are inactive",
"method": "POST",
Expand Down

0 comments on commit 793a278

Please sign in to comment.