def do_change_user_role(user_profile: UserProfile, value: int, acting_user: Optional[UserProfile]=None) -> None:
    old_value = user_profile.role
    user_profile.role = value
    user_profile.save(update_fields=['role'])
    RealmAuditLog.objects.create(realm=user_profile.realm, modified_user=user_profile, acting_user=acting_user, event_type=RealmAuditLog.USER_ROLE_CHANGED, event_time=timezone_now(), extra_data=ujson.dumps({RealmAuditLog.OLD_VALUE: old_value, RealmAuditLog.NEW_VALUE: value, RealmAuditLog.ROLE_COUNT: realm_user_count_by_role(user_profile.realm)}))
    event = dict(type='realm_user', op='update', person=dict(user_id=user_profile.id, role=user_profile.role))
    send_event(user_profile.realm, event, active_user_ids(user_profile.realm_id))
def do_change_user_role(user_profile: UserProfile, value: int, acting_user: Optional[UserProfile]=None) -> None:
    old_value = user_profile.role
    user_profile.role = value
    user_profile.save(update_fields=['role'])
    RealmAuditLog.objects.create(realm=user_profile.realm, modified_user=user_profile, acting_user=acting_user, event_type=RealmAuditLog.USER_ROLE_CHANGED, event_time=timezone_now(), extra_data=ujson.dumps({RealmAuditLog.OLD_VALUE: old_value, RealmAuditLog.NEW_VALUE: value, RealmAuditLog.ROLE_COUNT: realm_user_count_by_role(user_profile.realm)}))
    event = dict(type='realm_user', op='update', person=dict(user_id=user_profile.id, role=user_profile.role))
    send_event(user_profile.realm, event, active_user_ids(user_profile.realm_id))