Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
corporate: Adjust models for RemoteRealm customers.
Tim Abbottf916385cabfe
diff --git a/corporate/migrations/0020_add_remote_realm_customers.py b/corporate/migrations/0020_add_remote_realm_customers.pynew file mode 100644index 00000000000..9647eb91981--- /dev/null+++ b/corporate/migrations/0020_add_remote_realm_customers.py@@ -0,0 +1,37 @@+# Generated by Django 4.2.7 on 2023-11-17 20:11++import django.db.models.deletion+from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("zilencer", "0035_remoterealmcount_remote_realm_and_more"),+ ("corporate", "0019_zulipsponsorshiprequest_expected_total_users_and_more"),+ ]++ operations = [+ migrations.RemoveConstraint(+ model_name="customer",+ name="cloud_xor_self_hosted",+ ),+ migrations.AddField(+ model_name="customer",+ name="remote_realm",+ field=models.OneToOneField(+ null=True, on_delete=django.db.models.deletion.CASCADE, to="zilencer.remoterealm"+ ),+ ),+ migrations.AddConstraint(+ model_name="customer",+ constraint=models.CheckConstraint(+ check=models.Q(+ ("realm__isnull", False),+ ("remote_server__isnull", False),+ ("remote_realm__isnull", False),+ _connector="OR",+ ),+ name="has_associated_model_object",+ ),+ ),+ ]diff --git a/corporate/models.py b/corporate/models.pyindex 772b294597e..7bc499ba069 100644--- a/corporate/models.py+++ b/corporate/models.py@@ -17,8 +17,12 @@ class Customer(models.Model):and the active plan, if any."""+ # The actual model object that this customer is associated+ # with. Exactly one of the following will be non-null.realm = models.OneToOneField(Realm, on_delete=CASCADE, null=True)+ remote_realm = models.OneToOneField(RemoteRealm, on_delete=CASCADE, null=True)remote_server = models.OneToOneField(RemoteZulipServer, on_delete=CASCADE, null=True)+stripe_customer_id = models.CharField(max_length=255, null=True, unique=True)sponsorship_pending = models.BooleanField(default=False)# A percentage, like 85.@@ -30,10 +34,13 @@ class Customer(models.Model):exempt_from_license_number_check = models.BooleanField(default=False)class Meta:+ # Enforce that at least one of these is set.constraints = [models.CheckConstraint(- check=Q(realm__isnull=False) ^ Q(remote_server__isnull=False),- name="cloud_xor_self_hosted",+ check=Q(realm__isnull=False)+ | Q(remote_server__isnull=False)+ | Q(remote_realm__isnull=False),+ name="has_associated_model_object",)]