Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
realm_domains: Type QuerySet.values as RealmDomainDict.
Zixuan James Li8fa94138bc78
diff --git a/zerver/actions/realm_domains.py b/zerver/actions/realm_domains.pyindex 1619d3c4483..13778727ec4 100644--- a/zerver/actions/realm_domains.py+++ b/zerver/actions/realm_domains.py@@ -9,6 +9,7 @@ from zerver.models import (Realm,RealmAuditLog,RealmDomain,+ RealmDomainDict,UserProfile,active_user_ids,get_realm_domains,@@ -23,6 +24,7 @@ def do_add_realm_domain(realm_domain = RealmDomain.objects.create(realm=realm, domain=domain, allow_subdomains=allow_subdomains)+ added_domain = RealmDomainDict(domain=domain, allow_subdomains=allow_subdomains)RealmAuditLog.objects.create(realm=realm,@@ -32,7 +34,7 @@ def do_add_realm_domain(extra_data=orjson.dumps({"realm_domains": get_realm_domains(realm),- "added_domain": {"domain": domain, "allow_subdomains": allow_subdomains},+ "added_domain": added_domain,}).decode(),)@@ -40,7 +42,7 @@ def do_add_realm_domain(event = dict(type="realm_domains",op="add",- realm_domain=dict(+ realm_domain=RealmDomainDict(domain=realm_domain.domain, allow_subdomains=realm_domain.allow_subdomains),)@@ -55,6 +57,10 @@ def do_change_realm_domain() -> None:realm_domain.allow_subdomains = allow_subdomainsrealm_domain.save(update_fields=["allow_subdomains"])+ changed_domain = RealmDomainDict(+ domain=realm_domain.domain,+ allow_subdomains=realm_domain.allow_subdomains,+ )RealmAuditLog.objects.create(realm=realm_domain.realm,@@ -64,10 +70,7 @@ def do_change_realm_domain(extra_data=orjson.dumps({"realm_domains": get_realm_domains(realm_domain.realm),- "changed_domain": {- "domain": realm_domain.domain,- "allow_subdomains": realm_domain.allow_subdomains,- },+ "changed_domain": changed_domain,}).decode(),)@@ -91,6 +94,10 @@ def do_remove_realm_domain(realm = realm_domain.realmdomain = realm_domain.domainrealm_domain.delete()+ removed_domain = RealmDomainDict(+ domain=realm_domain.domain,+ allow_subdomains=realm_domain.allow_subdomains,+ )RealmAuditLog.objects.create(realm=realm,@@ -100,10 +107,7 @@ def do_remove_realm_domain(extra_data=orjson.dumps({"realm_domains": get_realm_domains(realm),- "removed_domain": {- "domain": realm_domain.domain,- "allow_subdomains": realm_domain.allow_subdomains,- },+ "removed_domain": removed_domain,}).decode(),)diff --git a/zerver/models.py b/zerver/models.pyindex f84a8fb5752..ce46f65e468 100644--- a/zerver/models.py+++ b/zerver/models.py@@ -1075,7 +1075,12 @@ class EmailContainsPlusError(Exception):pass-def get_realm_domains(realm: Realm) -> List[Dict[str, Union[str, bool]]]:+class RealmDomainDict(TypedDict):+ domain: str+ allow_subdomains: bool+++def get_realm_domains(realm: Realm) -> List[RealmDomainDict]:return list(realm.realmdomain_set.values("domain", "allow_subdomains"))diff --git a/zerver/tests/test_audit_log.py b/zerver/tests/test_audit_log.pyindex dff95e63ad1..c62b933a98e 100644--- a/zerver/tests/test_audit_log.py+++ b/zerver/tests/test_audit_log.py@@ -58,6 +58,7 @@ from zerver.models import (Message,Realm,RealmAuditLog,+ RealmDomainDict,RealmPlayground,Recipient,Subscription,@@ -684,10 +685,10 @@ class TestRealmAuditLog(ZulipTestCase):now = timezone_now()realm_domain = do_add_realm_domain(user.realm, "zulip.org", False, acting_user=user)- added_domain: Dict[str, Union[str, bool]] = {- "domain": "zulip.org",- "allow_subdomains": False,- }+ added_domain = RealmDomainDict(+ domain="zulip.org",+ allow_subdomains=False,+ )expected_extra_data = {"realm_domains": initial_domains + [added_domain],"added_domain": added_domain,@@ -705,10 +706,10 @@ class TestRealmAuditLog(ZulipTestCase):now = timezone_now()do_change_realm_domain(realm_domain, True, acting_user=user)- changed_domain: Dict[str, Union[str, bool]] = {- "domain": "zulip.org",- "allow_subdomains": True,- }+ changed_domain = RealmDomainDict(+ domain="zulip.org",+ allow_subdomains=True,+ )expected_extra_data = {"realm_domains": initial_domains + [changed_domain],"changed_domain": changed_domain,@@ -726,10 +727,10 @@ class TestRealmAuditLog(ZulipTestCase):now = timezone_now()do_remove_realm_domain(realm_domain, acting_user=user)- removed_domain = {- "domain": "zulip.org",- "allow_subdomains": True,- }+ removed_domain = RealmDomainDict(+ domain="zulip.org",+ allow_subdomains=True,+ )expected_extra_data = {"realm_domains": initial_domains,"removed_domain": removed_domain,