corporate: Adjust models for RemoteRealm customers.

This commit is contained in:
Tim Abbott
2023-11-17 12:13:37 -08:00
parent c5940bd68f
commit f916385cab
2 changed files with 46 additions and 2 deletions

View File

@@ -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",
),
),
]

View File

@@ -17,8 +17,12 @@ class Customer(models.Model):
and the active plan, if any. 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) 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) remote_server = models.OneToOneField(RemoteZulipServer, on_delete=CASCADE, null=True)
stripe_customer_id = models.CharField(max_length=255, null=True, unique=True) stripe_customer_id = models.CharField(max_length=255, null=True, unique=True)
sponsorship_pending = models.BooleanField(default=False) sponsorship_pending = models.BooleanField(default=False)
# A percentage, like 85. # A percentage, like 85.
@@ -30,10 +34,13 @@ class Customer(models.Model):
exempt_from_license_number_check = models.BooleanField(default=False) exempt_from_license_number_check = models.BooleanField(default=False)
class Meta: class Meta:
# Enforce that at least one of these is set.
constraints = [ constraints = [
models.CheckConstraint( models.CheckConstraint(
check=Q(realm__isnull=False) ^ Q(remote_server__isnull=False), check=Q(realm__isnull=False)
name="cloud_xor_self_hosted", | Q(remote_server__isnull=False)
| Q(remote_realm__isnull=False),
name="has_associated_model_object",
) )
] ]