mirror of https://github.com/zulip/zulip.git
realm_domains: Type QuerySet.values as RealmDomainDict.
This ensure that the return type is compatible with the actual type of `realm.realmdomain_set.values`. Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
parent
ab1bbdda65
commit
8fa94138bc
|
@ -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_subdomains
|
||||
realm_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.realm
|
||||
domain = realm_domain.domain
|
||||
realm_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(),
|
||||
)
|
||||
|
|
|
@ -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"))
|
||||
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue