mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 04:23:46 +00:00
models: Store is_system_bot_realm information for RemoteRealm.
This will help us filter out system bot realm and control feature access to it.
This commit is contained in:
@@ -75,6 +75,7 @@ class RealmDataForAnalytics(BaseModel):
|
|||||||
org_type: int = 0
|
org_type: int = 0
|
||||||
date_created: float
|
date_created: float
|
||||||
deactivated: bool
|
deactivated: bool
|
||||||
|
is_system_bot_realm: bool = False
|
||||||
|
|
||||||
authentication_methods: Dict[str, bool] = Field(default_factory=dict)
|
authentication_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[Rea
|
|||||||
org_type=realm.org_type,
|
org_type=realm.org_type,
|
||||||
name=realm.name,
|
name=realm.name,
|
||||||
authentication_methods=realm.authentication_methods_dict(),
|
authentication_methods=realm.authentication_methods_dict(),
|
||||||
|
is_system_bot_realm=realm.string_id == settings.SYSTEM_BOT_REALM,
|
||||||
)
|
)
|
||||||
for realm in realms
|
for realm in realms
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1143,6 +1143,7 @@ class AnalyticsBouncerTest(BouncerTestCase):
|
|||||||
"registration_deactivated",
|
"registration_deactivated",
|
||||||
"realm_deactivated",
|
"realm_deactivated",
|
||||||
"plan_type",
|
"plan_type",
|
||||||
|
"is_system_bot_realm",
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
[
|
[
|
||||||
@@ -1158,6 +1159,7 @@ class AnalyticsBouncerTest(BouncerTestCase):
|
|||||||
"registration_deactivated": False,
|
"registration_deactivated": False,
|
||||||
"realm_deactivated": False,
|
"realm_deactivated": False,
|
||||||
"plan_type": RemoteRealm.PLAN_TYPE_SELF_HOSTED,
|
"plan_type": RemoteRealm.PLAN_TYPE_SELF_HOSTED,
|
||||||
|
"is_system_bot_realm": realm.string_id == "zulipinternal",
|
||||||
}
|
}
|
||||||
for realm in Realm.objects.order_by("id")
|
for realm in Realm.objects.order_by("id")
|
||||||
],
|
],
|
||||||
@@ -1217,6 +1219,7 @@ class AnalyticsBouncerTest(BouncerTestCase):
|
|||||||
RemoteRealmAuditLog.objects.filter(
|
RemoteRealmAuditLog.objects.filter(
|
||||||
event_type=RemoteRealmAuditLog.REMOTE_REALM_VALUE_UPDATED
|
event_type=RemoteRealmAuditLog.REMOTE_REALM_VALUE_UPDATED
|
||||||
)
|
)
|
||||||
|
.exclude(realm_id=get_realm("zulipinternal").id)
|
||||||
.order_by("id")
|
.order_by("id")
|
||||||
.values("event_type", "remote_id", "realm_id", "extra_data")
|
.values("event_type", "remote_id", "realm_id", "extra_data")
|
||||||
)
|
)
|
||||||
|
|||||||
17
zilencer/migrations/0051_remoterealm_is_system_bot_realm.py
Normal file
17
zilencer/migrations/0051_remoterealm_is_system_bot_realm.py
Normal file
@@ -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),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -121,6 +121,8 @@ class RemoteRealm(models.Model):
|
|||||||
|
|
||||||
name = models.TextField(default="")
|
name = models.TextField(default="")
|
||||||
|
|
||||||
|
is_system_bot_realm = models.BooleanField(default=False)
|
||||||
|
|
||||||
authentication_methods = models.JSONField(default=dict)
|
authentication_methods = models.JSONField(default=dict)
|
||||||
|
|
||||||
org_type = models.PositiveSmallIntegerField(
|
org_type = models.PositiveSmallIntegerField(
|
||||||
|
|||||||
@@ -603,6 +603,7 @@ def update_remote_realm_data_for_server(
|
|||||||
org_type=realm.org_type,
|
org_type=realm.org_type,
|
||||||
name=realm.name,
|
name=realm.name,
|
||||||
authentication_methods=realm.authentication_methods,
|
authentication_methods=realm.authentication_methods,
|
||||||
|
is_system_bot_realm=realm.is_system_bot_realm,
|
||||||
)
|
)
|
||||||
for realm in server_realms_info
|
for realm in server_realms_info
|
||||||
if realm.uuid not in already_registered_uuids
|
if realm.uuid not in already_registered_uuids
|
||||||
@@ -629,6 +630,7 @@ def update_remote_realm_data_for_server(
|
|||||||
("name", "name"),
|
("name", "name"),
|
||||||
("authentication_methods", "authentication_methods"),
|
("authentication_methods", "authentication_methods"),
|
||||||
("realm_deactivated", "deactivated"),
|
("realm_deactivated", "deactivated"),
|
||||||
|
("is_system_bot_realm", "is_system_bot_realm"),
|
||||||
]:
|
]:
|
||||||
old_value = getattr(remote_realm, remote_realm_attr)
|
old_value = getattr(remote_realm, remote_realm_attr)
|
||||||
new_value = getattr(realm, realm_dict_key)
|
new_value = getattr(realm, realm_dict_key)
|
||||||
@@ -659,7 +661,14 @@ def update_remote_realm_data_for_server(
|
|||||||
|
|
||||||
RemoteRealm.objects.bulk_update(
|
RemoteRealm.objects.bulk_update(
|
||||||
remote_realms_to_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)
|
RemoteRealmAuditLog.objects.bulk_create(remote_realm_audit_logs)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user