def user_is_registrar(user, ra=None):
    """
    This function can be used to check whether a user is associated with ANY Registration Authority or associated with a
    specific Registration Authority.
    :param user: User object.
    :param ra: (Optional) Registration Authority object.
    :return: Boolean
    """
    if user.is_anonymous:
        return False
    if user.is_superuser:
        return True
    elif ra is None:
        return user.registrar_in.count() > 0
    else:
        return user in ra.registrars.all()
