From 7f1bf9d6abf0ce32105f23b08a715116676e1dad Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Thu, 2 Mar 2023 22:03:11 +0530 Subject: [PATCH] models: Add PreregistrationRealm class. This commit adds PreregistrationRealm class which will be similar to PreregistrationUser and will store initial information of the realm before its creation as we are changing the organization creation flow as per #24307. Fixes part of #24307. --- zerver/lib/export.py | 1 + .../migrations/0433_preregistrationrealm.py | 68 +++++++++++++++++++ zerver/models.py | 36 ++++++++++ 3 files changed, 105 insertions(+) create mode 100644 zerver/migrations/0433_preregistrationrealm.py diff --git a/zerver/lib/export.py b/zerver/lib/export.py index a9cd7d1d24..764ee5a897 100644 --- a/zerver/lib/export.py +++ b/zerver/lib/export.py @@ -134,6 +134,7 @@ ALL_ZULIP_TABLES = { "zerver_missedmessageemailaddress", "zerver_multiuseinvite", "zerver_multiuseinvite_streams", + "zerver_preregistrationrealm", "zerver_preregistrationuser", "zerver_preregistrationuser_streams", "zerver_pushdevicetoken", diff --git a/zerver/migrations/0433_preregistrationrealm.py b/zerver/migrations/0433_preregistrationrealm.py new file mode 100644 index 0000000000..ad7aec7289 --- /dev/null +++ b/zerver/migrations/0433_preregistrationrealm.py @@ -0,0 +1,68 @@ +# Generated by Django 4.1.7 on 2023-03-07 09:14 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("zerver", "0432_alter_and_migrate_realm_name_in_notifications"), + ] + + operations = [ + migrations.CreateModel( + name="PreregistrationRealm", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("name", models.CharField(max_length=40)), + ( + "org_type", + models.PositiveSmallIntegerField( + choices=[ + (0, "Unspecified"), + (10, "Business"), + (20, "Open-source project"), + (30, "Education (non-profit)"), + (35, "Education (for-profit)"), + (40, "Research"), + (50, "Event or conference"), + (60, "Non-profit (registered)"), + (70, "Government"), + (80, "Political group"), + (90, "Community"), + (100, "Personal"), + (1000, "Other"), + ], + default=0, + ), + ), + ("string_id", models.CharField(max_length=40)), + ("email", models.EmailField(max_length=254)), + ("status", models.IntegerField(default=0)), + ( + "created_realm", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + to="zerver.realm", + ), + ), + ( + "created_user", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), + ] diff --git a/zerver/models.py b/zerver/models.py index 71c8ab968a..7396a552e0 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -2286,6 +2286,42 @@ def remote_user_to_email(remote_user: str) -> str: post_save.connect(flush_user_profile, sender=UserProfile) +class PreregistrationRealm(models.Model): + """Data on a partially created realm entered by a user who has + completed the "new organization" form. Used to transfer the user's + selections from the pre-confirmation "new organization" form to + the post-confirmation user registration form. + + Note that the values stored here may not match those of the + created realm (in the event the user creates a realm at all), + because we allow the user to edit these values in the registration + form (and in fact the user will be required to do so if the + `string_id` is claimed by another realm before registraiton is + completed). + """ + + name = models.CharField(max_length=Realm.MAX_REALM_NAME_LENGTH) + org_type = models.PositiveSmallIntegerField( + default=Realm.ORG_TYPES["unspecified"]["id"], + choices=[(t["id"], t["name"]) for t in Realm.ORG_TYPES.values()], + ) + string_id = models.CharField(max_length=Realm.MAX_REALM_SUBDOMAIN_LENGTH) + email = models.EmailField() + + confirmation = GenericRelation("confirmation.Confirmation", related_query_name="prereg_realm") + status = models.IntegerField(default=0) + + # The Realm created upon completion of the registration + # for this PregistrationRealm + created_realm = models.ForeignKey(Realm, null=True, related_name="+", on_delete=models.SET_NULL) + + # The UserProfile created upon completion of the registration + # for this PregistrationRealm + created_user = models.ForeignKey( + UserProfile, null=True, related_name="+", on_delete=models.SET_NULL + ) + + class PreregistrationUser(models.Model): # Data on a partially created user, before the completion of # registration. This is used in at least three major code paths: