Skip to content

Commit 3760a6b

Browse files
authored
Force membership_type to be the same as integration_type (#3029)
1 parent 0dbfe56 commit 3760a6b

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Generated by Django 4.2.25 on 2025-10-23 13:56
2+
3+
from django.core.cache import caches
4+
from django.db import migrations
5+
from django.db.models import F
6+
7+
8+
def noop_reverse(apps, schema_editor):
9+
"""No-op the reverse - we won't be able to figure out what orgs were there before."""
10+
11+
return
12+
13+
14+
def sync_contract_type_fields(apps, schema_editor):
15+
"""
16+
Sync the contract type fields.
17+
18+
We added a `membership_type` field alongside the `integration_type` field -
19+
the intent was that the `integration_type` field would go away in the near
20+
future. It still will, but until then, these need to be synced so that the
21+
user contract reconciliation stuff works properly. The model now enforces
22+
this; this fixes the old records and flushes the cached memberships from Redis
23+
so that it will do it again for everyone.
24+
"""
25+
26+
User = apps.get_model("users", "User")
27+
ContractPage = apps.get_model("b2b", "ContractPage")
28+
29+
ContractPage.objects.update(membership_type=F("integration_type"))
30+
31+
for user_id in User.objects.values_list("id", flat=True).all():
32+
caches["redis"].delete(f"org-membership-cache-{user_id}")
33+
34+
35+
class Migration(migrations.Migration):
36+
dependencies = [
37+
("b2b", "0010_backfill_user_b2b_orgs"),
38+
]
39+
40+
operations = [
41+
migrations.RunPython(sync_contract_type_fields, noop_reverse),
42+
]

b2b/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,12 @@ def save(self, clean=True, user=None, log_action=False, **kwargs): # noqa: FBT0
296296
"""Save the page, and update the slug and title appropriately."""
297297

298298
self.title = str(self.name)
299-
300299
self.slug = slugify(f"contract-{self.organization.id}-{self.title}")
300+
301+
# This should be removed once we're done migrating orgs into Keycloak.
302+
# The integration type field should also be removed at that time.
303+
self.membership_type = self.integration_type
304+
301305
Page.save(self, clean=clean, user=user, log_action=log_action, **kwargs)
302306
queue_enrollment_code_check.delay(self.id)
303307

0 commit comments

Comments
 (0)