def _is_user_profile_visible(self, user=None):
    """Return whether or not the given user can view this user's profile.

    Profiles are hidden from unauthenticated users. For authenticated users, a
    profile is visible if one of the following is true:

    * The profile is not marked as private.
    * The viewing user owns the profile.
    * The viewing user is a staff member.
    * The viewing user is an administrator on a Local Site which the viewed
      user is a member.

    Args:
        user (django.contrib.auth.models.User, optional):
            The user for which visibility to the profile is to be determined.

    Returns:
        bool:
        Whether or not the given user can view the profile.
    """
    if user is None or user.is_anonymous:
        return False

    if hasattr(self, 'is_private'):
        # This is an optimization used by the web API. It will set
        # is_private on this User instance through a query, saving a
        # lookup for each instance.
        #
        # This must be done because select_related() and
        # prefetch_related() won't cache reverse foreign key relations.
        is_private = self.is_private
    else:
        is_private = self.get_profile().is_private

    return (not is_private or
            user == self or
            user.is_admin_for_user(self))