support: Create RealmAuditLog when updating realm_subdomain.

This commit is contained in:
Siddharth Asthana
2020-12-07 00:34:33 +05:30
committed by Tim Abbott
parent 80c9243c6a
commit 47e478945b
5 changed files with 25 additions and 7 deletions

View File

@@ -1035,11 +1035,20 @@ def do_reactivate_realm(realm: Realm) -> None:
)
def do_change_realm_subdomain(realm: Realm, new_subdomain: str) -> None:
def do_change_realm_subdomain(
realm: Realm, new_subdomain: str, *, acting_user: Optional[UserProfile]
) -> None:
old_subdomain = realm.subdomain
old_uri = realm.uri
realm.string_id = new_subdomain
realm.save(update_fields=["string_id"])
RealmAuditLog.objects.create(
realm=realm,
event_type=RealmAuditLog.REALM_SUBDOMAIN_CHANGED,
event_time=timezone_now(),
acting_user=acting_user,
extra_data={"old_subdomain": old_subdomain, "new_subdomain": new_subdomain},
)
# If a realm if being renamed multiple times, we should find all the placeholder
# realms and reset their deactivated_redirect field to point to the new realm uri