def do_set_realm_property(realm: Realm, name: str, value: Any, acting_user: Optional[UserProfile]=None) -> None:
    'Takes in a realm object, the name of an attribute to update, the\n       value to update and and the user who initiated the update.\n    '
    property_type = Realm.property_types[name]
    assert isinstance(value, property_type), f'Cannot update {name}: {value} is not an instance of {property_type}'
    old_value = getattr(realm, name)
    setattr(realm, name, value)
    realm.save(update_fields=[name])
    event = dict(type='realm', op='update', property=name, value=value)
    send_event(realm, event, active_user_ids(realm.id))
    event_time = timezone_now()
    RealmAuditLog.objects.create(realm=realm, event_type=RealmAuditLog.REALM_PROPERTY_CHANGED, event_time=event_time, acting_user=acting_user, extra_data=ujson.dumps({RealmAuditLog.OLD_VALUE: {'property': name, 'value': old_value}, RealmAuditLog.NEW_VALUE: {'property': name, 'value': value}}))
    if (name == 'email_address_visibility'):
        if (Realm.EMAIL_ADDRESS_VISIBILITY_EVERYONE not in [old_value, value]):
            return
        user_profiles = UserProfile.objects.filter(realm=realm, is_bot=False)
        for user_profile in user_profiles:
            user_profile.email = get_display_email_address(user_profile, realm)
            send_user_email_update_event(user_profile)
        UserProfile.objects.bulk_update(user_profiles, ['email'])
        for user_profile in user_profiles:
            flush_user_profile(sender=UserProfile, instance=user_profile)
Takes in a realm object, the name of an attribute to update, the
value to update and and the user who initiated the update.
def do_set_realm_property(realm: Realm, name: str, value: Any, acting_user: Optional[UserProfile]=None) -> None:
    'Takes in a realm object, the name of an attribute to update, the\n       value to update and and the user who initiated the update.\n    '
    property_type = Realm.property_types[name]
    assert isinstance(value, property_type), f'Cannot update {name}: {value} is not an instance of {property_type}'
    old_value = getattr(realm, name)
    setattr(realm, name, value)
    realm.save(update_fields=[name])
    event = dict(type='realm', op='update', property=name, value=value)
    send_event(realm, event, active_user_ids(realm.id))
    event_time = timezone_now()
    RealmAuditLog.objects.create(realm=realm, event_type=RealmAuditLog.REALM_PROPERTY_CHANGED, event_time=event_time, acting_user=acting_user, extra_data=ujson.dumps({RealmAuditLog.OLD_VALUE: {'property': name, 'value': old_value}, RealmAuditLog.NEW_VALUE: {'property': name, 'value': value}}))
    if (name == 'email_address_visibility'):
        if (Realm.EMAIL_ADDRESS_VISIBILITY_EVERYONE not in [old_value, value]):
            return
        user_profiles = UserProfile.objects.filter(realm=realm, is_bot=False)
        for user_profile in user_profiles:
            user_profile.email = get_display_email_address(user_profile, realm)
            send_user_email_update_event(user_profile)
        UserProfile.objects.bulk_update(user_profiles, ['email'])
        for user_profile in user_profiles:
            flush_user_profile(sender=UserProfile, instance=user_profile)