From 9cd4d6bfbf47fa1d97dc6dfa1b200524425e6feb Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Thu, 26 Sep 2024 17:01:45 -0500 Subject: [PATCH] Remove check in deindex contact for contact being inactive.. so that it can be run before deletion actually occurs --- web/contact/base_test.go | 8 +------- web/contact/deindex.go | 10 ---------- web/contact/testdata/deindex.json | 30 ------------------------------ 3 files changed, 1 insertion(+), 47 deletions(-) diff --git a/web/contact/base_test.go b/web/contact/base_test.go index e5eeab45f..f5ed8854e 100644 --- a/web/contact/base_test.go +++ b/web/contact/base_test.go @@ -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) } diff --git a/web/contact/deindex.go b/web/contact/deindex.go index ff95b8b9e..86a45aff0 100644 --- a/web/contact/deindex.go +++ b/web/contact/deindex.go @@ -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" @@ -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) diff --git a/web/contact/testdata/deindex.json b/web/contact/testdata/deindex.json index a4c2efe4b..6844e9328 100644 --- a/web/contact/testdata/deindex.json +++ b/web/contact/testdata/deindex.json @@ -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",