Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
models: Store `is_system_bot_realm` information for `RemoteRealm`.
Aman Agrawalb4e4ca14d555
diff --git a/zerver/lib/remote_server.py b/zerver/lib/remote_server.pyindex 36ee743fe98..7018aad608d 100644--- a/zerver/lib/remote_server.py+++ b/zerver/lib/remote_server.py@@ -75,6 +75,7 @@ class RealmDataForAnalytics(BaseModel):org_type: int = 0date_created: floatdeactivated: bool+ is_system_bot_realm: bool = Falseauthentication_methods: Dict[str, bool] = Field(default_factory=dict)@@ -302,6 +303,7 @@ def get_realms_info_for_push_bouncer(realm_id: Optional[int] = None) -> List[Reaorg_type=realm.org_type,name=realm.name,authentication_methods=realm.authentication_methods_dict(),+ is_system_bot_realm=realm.string_id == settings.SYSTEM_BOT_REALM,)for realm in realms]diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.pyindex 64c4148114d..1ca2c25dbe2 100644--- a/zerver/tests/test_push_notifications.py+++ b/zerver/tests/test_push_notifications.py@@ -1143,6 +1143,7 @@ class AnalyticsBouncerTest(BouncerTestCase):"registration_deactivated","realm_deactivated","plan_type",+ "is_system_bot_realm",)),[@@ -1158,6 +1159,7 @@ class AnalyticsBouncerTest(BouncerTestCase):"registration_deactivated": False,"realm_deactivated": False,"plan_type": RemoteRealm.PLAN_TYPE_SELF_HOSTED,+ "is_system_bot_realm": realm.string_id == "zulipinternal",}for realm in Realm.objects.order_by("id")],@@ -1217,6 +1219,7 @@ class AnalyticsBouncerTest(BouncerTestCase):RemoteRealmAuditLog.objects.filter(event_type=RemoteRealmAuditLog.REMOTE_REALM_VALUE_UPDATED)+ .exclude(realm_id=get_realm("zulipinternal").id).order_by("id").values("event_type", "remote_id", "realm_id", "extra_data"))diff --git a/zilencer/migrations/0051_remoterealm_is_system_bot_realm.py b/zilencer/migrations/0051_remoterealm_is_system_bot_realm.pynew file mode 100644index 00000000000..c0bcf9a7f17--- /dev/null+++ b/zilencer/migrations/0051_remoterealm_is_system_bot_realm.py@@ -0,0 +1,17 @@+# Generated by Django 4.2.8 on 2023-12-11 20:38++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("zilencer", "0050_preregistrationremoterealmbillinguser_created_user_and_more"),+ ]++ operations = [+ migrations.AddField(+ model_name="remoterealm",+ name="is_system_bot_realm",+ field=models.BooleanField(default=False),+ ),+ ]diff --git a/zilencer/models.py b/zilencer/models.pyindex 107fa3f716d..bb95174dce1 100644--- a/zilencer/models.py+++ b/zilencer/models.py@@ -121,6 +121,8 @@ class RemoteRealm(models.Model):name = models.TextField(default="")+ is_system_bot_realm = models.BooleanField(default=False)+authentication_methods = models.JSONField(default=dict)org_type = models.PositiveSmallIntegerField(diff --git a/zilencer/views.py b/zilencer/views.pyindex 6daa71325ae..a66b9e52127 100644--- a/zilencer/views.py+++ b/zilencer/views.py@@ -603,6 +603,7 @@ def update_remote_realm_data_for_server(org_type=realm.org_type,name=realm.name,authentication_methods=realm.authentication_methods,+ is_system_bot_realm=realm.is_system_bot_realm,)for realm in server_realms_infoif realm.uuid not in already_registered_uuids@@ -629,6 +630,7 @@ def update_remote_realm_data_for_server(("name", "name"),("authentication_methods", "authentication_methods"),("realm_deactivated", "deactivated"),+ ("is_system_bot_realm", "is_system_bot_realm"),]:old_value = getattr(remote_realm, remote_realm_attr)new_value = getattr(realm, realm_dict_key)@@ -659,7 +661,14 @@ def update_remote_realm_data_for_server(RemoteRealm.objects.bulk_update(remote_realms_to_update,- ["host", "realm_deactivated", "name", "authentication_methods", "org_type"],+ [+ "host",+ "realm_deactivated",+ "name",+ "authentication_methods",+ "org_type",+ "is_system_bot_realm",+ ],)RemoteRealmAuditLog.objects.bulk_create(remote_realm_audit_logs)