mirror of
https://github.com/zulip/zulip.git
synced 2026-07-03 21:10:12 +08:00
realm: Create RealmAuditLog entry for removing a realm domain.
Fixes a part of #21268.
This commit is contained in:
parent
ab5567e8c5
commit
07352271b9
@ -8157,6 +8157,23 @@ def do_remove_realm_domain(
|
||||
realm = realm_domain.realm
|
||||
domain = realm_domain.domain
|
||||
realm_domain.delete()
|
||||
|
||||
RealmAuditLog.objects.create(
|
||||
realm=realm,
|
||||
acting_user=acting_user,
|
||||
event_type=RealmAuditLog.REALM_DOMAIN_REMOVED,
|
||||
event_time=timezone_now(),
|
||||
extra_data=orjson.dumps(
|
||||
{
|
||||
"realm_domains": get_realm_domains(realm),
|
||||
"removed_domain": {
|
||||
"domain": realm_domain.domain,
|
||||
"allow_subdomains": realm_domain.allow_subdomains,
|
||||
},
|
||||
}
|
||||
).decode(),
|
||||
)
|
||||
|
||||
if RealmDomain.objects.filter(realm=realm).count() == 0 and realm.emails_restricted_to_domains:
|
||||
# If this was the last realm domain, we mark the realm as no
|
||||
# longer restricted to domain, because the feature doesn't do
|
||||
|
||||
@ -4064,6 +4064,7 @@ class AbstractRealmAuditLog(models.Model):
|
||||
REALM_ORG_TYPE_CHANGED = 217
|
||||
REALM_DOMAIN_ADDED = 218
|
||||
REALM_DOMAIN_CHANGED = 219
|
||||
REALM_DOMAIN_REMOVED = 220
|
||||
|
||||
SUBSCRIPTION_CREATED = 301
|
||||
SUBSCRIPTION_ACTIVATED = 302
|
||||
|
||||
@ -31,6 +31,7 @@ from zerver.lib.actions import (
|
||||
do_reactivate_realm,
|
||||
do_reactivate_user,
|
||||
do_regenerate_api_key,
|
||||
do_remove_realm_domain,
|
||||
do_rename_stream,
|
||||
do_set_realm_authentication_methods,
|
||||
do_set_realm_message_editing,
|
||||
@ -707,3 +708,24 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||
).count(),
|
||||
1,
|
||||
)
|
||||
|
||||
now = timezone_now()
|
||||
do_remove_realm_domain(realm_domain, acting_user=user)
|
||||
removed_domain = {
|
||||
"domain": "zulip.org",
|
||||
"allow_subdomains": True,
|
||||
}
|
||||
expected_extra_data = {
|
||||
"realm_domains": initial_domains,
|
||||
"removed_domain": removed_domain,
|
||||
}
|
||||
self.assertEqual(
|
||||
RealmAuditLog.objects.filter(
|
||||
realm=user.realm,
|
||||
event_type=RealmAuditLog.REALM_DOMAIN_REMOVED,
|
||||
event_time__gte=now,
|
||||
acting_user=user,
|
||||
extra_data=orjson.dumps(expected_extra_data).decode(),
|
||||
).count(),
|
||||
1,
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user