def do_deactivate_realm(realm: Realm, acting_user: Optional[UserProfile]=None) -> None:
    "\n    Deactivate this realm. Do NOT deactivate the users -- we need to be able to\n    tell the difference between users that were intentionally deactivated,\n    e.g. by a realm admin, and users who can't currently use Zulip because their\n    realm has been deactivated.\n    "
    if realm.deactivated:
        return
    realm.deactivated = True
    realm.save(update_fields=['deactivated'])
    if settings.BILLING_ENABLED:
        downgrade_now(realm)
    event_time = timezone_now()
    RealmAuditLog.objects.create(realm=realm, event_type=RealmAuditLog.REALM_DEACTIVATED, event_time=event_time, acting_user=acting_user, extra_data=ujson.dumps({RealmAuditLog.ROLE_COUNT: realm_user_count_by_role(realm)}))
    ScheduledEmail.objects.filter(realm=realm).delete()
    for user in active_humans_in_realm(realm):
        delete_user_sessions(user)
    event = dict(type='realm', op='deactivated', realm_id=realm.id)
    send_event(realm, event, active_user_ids(realm.id))
Deactivate this realm. Do NOT deactivate the users -- we need to be able to
tell the difference between users that were intentionally deactivated,
e.g. by a realm admin, and users who can't currently use Zulip because their
realm has been deactivated.
def do_deactivate_realm(realm: Realm, acting_user: Optional[UserProfile]=None) -> None:
    "\n    Deactivate this realm. Do NOT deactivate the users -- we need to be able to\n    tell the difference between users that were intentionally deactivated,\n    e.g. by a realm admin, and users who can't currently use Zulip because their\n    realm has been deactivated.\n    "
    if realm.deactivated:
        return
    realm.deactivated = True
    realm.save(update_fields=['deactivated'])
    if settings.BILLING_ENABLED:
        downgrade_now(realm)
    event_time = timezone_now()
    RealmAuditLog.objects.create(realm=realm, event_type=RealmAuditLog.REALM_DEACTIVATED, event_time=event_time, acting_user=acting_user, extra_data=ujson.dumps({RealmAuditLog.ROLE_COUNT: realm_user_count_by_role(realm)}))
    ScheduledEmail.objects.filter(realm=realm).delete()
    for user in active_humans_in_realm(realm):
        delete_user_sessions(user)
    event = dict(type='realm', op='deactivated', realm_id=realm.id)
    send_event(realm, event, active_user_ids(realm.id))