From e102d2a1eec8e67ad06ee21fa4df35ec9f6bca8f Mon Sep 17 00:00:00 2001 From: Maciek Date: Thu, 6 Aug 2026 10:28:30 +0200 Subject: [PATCH] refactor(api): drop unused is_active from subscription and preauth Signed-off-by: Maciek --- .../024_subscriptions_unset_is_active.down.json | 1 + .../024_subscriptions_unset_is_active.up.json | 13 +++++++++++++ api/db/mongodb/subscription_test.go | 2 -- .../migrations/subscription_uuid_subtype_test.go | 4 +--- api/model/preauth.go | 1 - api/model/subscription.go | 1 - api/service/account/service_test.go | 1 - api/service/subscription/service.go | 2 -- api/service/subscription/service_test.go | 2 -- tests/bootstrap/mock-preauth/server.py | 2 +- tests/libs/accounts.py | 1 - 11 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 api/db/mongodb/migrations/024_subscriptions_unset_is_active.down.json create mode 100644 api/db/mongodb/migrations/024_subscriptions_unset_is_active.up.json diff --git a/api/db/mongodb/migrations/024_subscriptions_unset_is_active.down.json b/api/db/mongodb/migrations/024_subscriptions_unset_is_active.down.json new file mode 100644 index 00000000..fe51488c --- /dev/null +++ b/api/db/mongodb/migrations/024_subscriptions_unset_is_active.down.json @@ -0,0 +1 @@ +[] diff --git a/api/db/mongodb/migrations/024_subscriptions_unset_is_active.up.json b/api/db/mongodb/migrations/024_subscriptions_unset_is_active.up.json new file mode 100644 index 00000000..aa06ae6c --- /dev/null +++ b/api/db/mongodb/migrations/024_subscriptions_unset_is_active.up.json @@ -0,0 +1,13 @@ +[ + { + "update": "subscriptions", + "updates": [ + { + "q": { "is_active": { "$exists": true } }, + "u": { "$unset": { "is_active": "" } }, + "multi": true + } + ], + "writeConcern": { "w": "majority" } + } +] diff --git a/api/db/mongodb/subscription_test.go b/api/db/mongodb/subscription_test.go index ae3f9d07..d607ae9b 100644 --- a/api/db/mongodb/subscription_test.go +++ b/api/db/mongodb/subscription_test.go @@ -119,7 +119,6 @@ func (s *SubscriptionRepositorySuite) seedSub(tier string, activeUntil, updatedA Tier: tier, ActiveUntil: activeUntil, UpdatedAt: updatedAt, - IsActive: true, Notified: notified, NotifiedInactive: notifiedPD, } @@ -276,7 +275,6 @@ func (s *SubscriptionRepositorySuite) TestFindDuplicateTokenHashGroups() { Tier: "IVPN Tier 2", ActiveUntil: now.Add(30 * 24 * time.Hour), UpdatedAt: now, - IsActive: true, TokenHash: tokenHash, DeletionScheduledAt: deletionScheduled, } diff --git a/api/internal/migrations/subscription_uuid_subtype_test.go b/api/internal/migrations/subscription_uuid_subtype_test.go index 61f82f19..8df3ff5f 100644 --- a/api/internal/migrations/subscription_uuid_subtype_test.go +++ b/api/internal/migrations/subscription_uuid_subtype_test.go @@ -116,7 +116,6 @@ func (s *MigrateSuite) seedDoc(ctx context.Context, subtype byte, tier string) u {Key: "_id", Value: primitive.Binary{Subtype: subtype, Data: id[:]}}, {Key: "account_id", Value: primitive.NewObjectID()}, {Key: "active_until", Value: time.Now().Add(30 * 24 * time.Hour).UTC().Truncate(time.Millisecond)}, - {Key: "is_active", Value: true}, {Key: "tier", Value: tier}, {Key: "token_hash", Value: "hash-" + tier}, {Key: "updated_at", Value: time.Now().UTC().Truncate(time.Millisecond)}, @@ -191,7 +190,6 @@ func (s *MigrateSuite) TestMigrateResumesAfterPartialInsert() { base := bson.D{ {Key: "account_id", Value: accountID}, {Key: "active_until", Value: time.Now().Add(24 * time.Hour).UTC().Truncate(time.Millisecond)}, - {Key: "is_active", Value: true}, {Key: "tier", Value: "Tier 2"}, } @@ -274,7 +272,7 @@ func (s *MigrateSuite) snapshotByUUID(ctx context.Context, coll *mongo.Collectio func (s *MigrateSuite) assertFieldsPreserved(before, after bson.Raw) { s.T().Helper() - preservedKeys := []string{"account_id", "active_until", "is_active", "tier", "token_hash", "updated_at", "notified", "limits"} + preservedKeys := []string{"account_id", "active_until", "tier", "token_hash", "updated_at", "notified", "limits"} for _, key := range preservedKeys { beforeVal := before.Lookup(key) afterVal := after.Lookup(key) diff --git a/api/model/preauth.go b/api/model/preauth.go index 941bdc87..ff42797a 100644 --- a/api/model/preauth.go +++ b/api/model/preauth.go @@ -7,7 +7,6 @@ import "time" type Preauth struct { ID string `json:"id"` TokenHash string `json:"token_hash"` - IsActive bool `json:"is_active"` ActiveUntil time.Time `json:"active_until"` Tier string `json:"tier"` } diff --git a/api/model/subscription.go b/api/model/subscription.go index 803f25bf..17a9ecc8 100644 --- a/api/model/subscription.go +++ b/api/model/subscription.go @@ -56,7 +56,6 @@ type Subscription struct { ID uuid.UUID `json:"-" bson:"_id"` AccountID primitive.ObjectID `json:"-" bson:"account_id"` ActiveUntil time.Time `json:"active_until" bson:"active_until"` - IsActive bool `json:"-" bson:"is_active"` // Type is a legacy pre-0.1.8 enum ("Free"/"Managed") retained so old documents // surface to clients (the beta-ending banner gates on Type == "Managed"). // Cleared to "" by the resync flow once the user re-syncs with IVPN. diff --git a/api/service/account/service_test.go b/api/service/account/service_test.go index 5b551808..e27548c3 100644 --- a/api/service/account/service_test.go +++ b/api/service/account/service_test.go @@ -145,7 +145,6 @@ func (suite *AccountTestSuite) TestGetUnfinishedSignupOrPostAccount() { preauth := model.Preauth{ ID: preauthID, TokenHash: tokenHashStr, - IsActive: true, ActiveUntil: activeUntil, Tier: "pro", } diff --git a/api/service/subscription/service.go b/api/service/subscription/service.go index fd8232bc..b7a7ac9d 100644 --- a/api/service/subscription/service.go +++ b/api/service/subscription/service.go @@ -109,7 +109,6 @@ func (s *SubscriptionService) CreateSubscriptionFromPreauth(ctx context.Context, ID: uuid.New(), AccountID: accOID, ActiveUntil: preauth.ActiveUntil, - IsActive: preauth.IsActive, Tier: preauth.Tier, TokenHash: preauth.TokenHash, UpdatedAt: time.Now(), @@ -195,7 +194,6 @@ func (s *SubscriptionService) UpdateSubscriptionFromPASession(ctx context.Contex } sub.ActiveUntil = preauth.ActiveUntil - sub.IsActive = preauth.IsActive sub.Tier = preauth.Tier sub.TokenHash = preauth.TokenHash sub.UpdatedAt = time.Now() diff --git a/api/service/subscription/service_test.go b/api/service/subscription/service_test.go index 56f33ca8..dca41f29 100644 --- a/api/service/subscription/service_test.go +++ b/api/service/subscription/service_test.go @@ -49,7 +49,6 @@ func newPreauthServer(t *testing.T, token string) *httptest.Server { preauth := model.Preauth{ ID: "preauth-id-1", TokenHash: tokenHashStr, - IsActive: true, ActiveUntil: time.Now().Add(24 * time.Hour).UTC(), Tier: "IVPN Tier 2", } @@ -214,7 +213,6 @@ func TestUpdateSubscriptionFromPASession_ClearsLegacyType(t *testing.T) { preauth := model.Preauth{ ID: preauthID, TokenHash: tokenHashStr, - IsActive: true, ActiveUntil: activeUntil, Tier: "IVPN Tier 2", } diff --git a/tests/bootstrap/mock-preauth/server.py b/tests/bootstrap/mock-preauth/server.py index 0e4d8d84..000bcf86 100644 --- a/tests/bootstrap/mock-preauth/server.py +++ b/tests/bootstrap/mock-preauth/server.py @@ -5,7 +5,7 @@ Endpoints: POST /entry - Create preauth entry (called by test setup) - Body: {"id": "...", "token_hash": "...", "is_active": true, "active_until": "...", "tier": "..."} + Body: {"id": "...", "token_hash": "...", "active_until": "...", "tier": "..."} Returns: 201 GET / - Get preauth entry (called by API during registration) diff --git a/tests/libs/accounts.py b/tests/libs/accounts.py index c5cf9765..79c9d5d7 100644 --- a/tests/libs/accounts.py +++ b/tests/libs/accounts.py @@ -93,7 +93,6 @@ def create_temp_subscription( json={ "id": preauth_id, "token_hash": token_hash, - "is_active": True, "active_until": active_until, "tier": tier, },