Ocultar nombre completo si no hay sesión iniciada

Hola,

mi configuración actual es que Discourse es legible si no has iniciado sesión. También he establecido “habilitar nombres” para ver el nombre completo justo al lado del apodo.

Pero lo que NO quiero es que los usuarios que no han iniciado sesión puedan ver el nombre completo. ¿Hay alguna manera de desactivar esto? No lo encontré.

¡Gracias de antemano por tu ayuda!

Is this possible with CSS @tshenry? I think we have the anon classes to do it?

I was going to respond to this earlier with some CSS, but remembered the case where username and display name match, resulting in the username being hidden.

In that situation it would present an avatar, with no name whatsoever.

But still better than get crawled by any bots :slight_smile: other forum software (plug-ins) hiding the full name and also anonymze the nick in e.g. to “user 34726”. Would be really perfect if I could hide at least the real name :slight_smile:

I’m going to look into this when I get a chance. It should be doable with a small theme component. I’ve got a decent amount on my plate, so it maybe be a little bit before I get back to you with anything.

Alright, the script for removing the full name for anons is fairly simple. Just create a new theme component and add the following to the Common </head> section:

<script type="text/discourse-plugin" version="0.8">
  api.reopenWidget("poster-name", {
    html(attrs) {
      let contents = this._super(attrs);
      if(contents.length == 2 && !api.getCurrentUser()) {
        return contents.shift();
      }
      return contents;
    }
  });
</script>

Some things to note:

  • To better avoid full names getting out, it would be best to set the site setting hide_user_profiles_from_public
  • This code assumes you have prioritize_username_in_ux enabled
  • A user’s full name will be used as the title attribute for a user avatar, so it will be displayed whenever someone hovers over an avatar. I haven’t found a solution for this yet, but I’ll come back if one is found.

Hope that helps :slightly_smiling_face:

¿Se integró esto alguna vez?

Nos gustaría que nuestros foros fueran legibles públicamente e indexados por los motores de búsqueda, pero que no mostráramos los nombres reales a menos que hayas iniciado sesión (para que los nombres reales de las personas no queden expuestos a los no miembros y a los motores de búsqueda).

¿Es eso posible? Intenté el código anterior y no pude hacerlo funcionar.

¿Necesita el código anterior una actualización @tshenry?

Acabo de verificar y el código sigue funcionando. Todas las notas que menciono siguen siendo válidas.


Intenté rastrear todas las áreas donde el nombre completo del usuario se utilizaba como atributo de título del avatar. El siguiente código debería cubrir todas las áreas, siempre que tengas habilitadas las opciones hide_user_profiles_from_public y prioritize_username_in_ux. Desafortunadamente, depende de sobrescribir algunas plantillas, pero estas no cambian con frecuencia. He incluido enlaces a los archivos en GitHub por si en algún momento quieres verificar si necesitas actualizar alguna parte del código. La única modificación que realicé fue agregar o cambiar el namePath para que utilice el nombre de usuario en lugar del nombre completo.

<script type="text/discourse-plugin" version="0.8">
  api.reopenWidget("poster-name", {
    html(attrs) {
      let contents = this._super(attrs);
      if(contents.length == 2 && api.getCurrentUser()) {
        return contents.shift();
      }
      return contents;
    }
  });
  
  api.reopenWidget("post-avatar", {
    html(attrs) {
      attrs.name = "";
      return  this._super(attrs);
    }
  });
  
  api.reopenWidget("topic-map-summary", {
    html(attrs, state) {
      attrs.createdByName = "";
      attrs.lastPostName = "";
      return  this._super(attrs, state);
    }
  });
  
  api.reopenWidget("topic-participant", {
    html(attrs, state) {
      attrs.name = "";
      return  this._super(attrs, state);
    }
  });

</script>


<!-- https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/templates/components/user-info.hbs -->
<script type="text/x-handlebars" data-template-name="components/user-info">
  <div class="user-image">
    <div class="user-image-inner">
      <a href="{{unbound userPath}}" data-user-card="{{unbound user.username}}">{{avatar user namePath="user.username" imageSize="large"}}</a>
      {{#if user.primary_group_name}}
        {{avatar-flair
          flairURL=user.primary_group_flair_url
          flairBgColor=user.primary_group_flair_bg_color
          flairColor=user.primary_group_flair_color
          groupName=user.primary_group_name}}
      {{/if}}
    </div>
  </div>

  <div class="user-detail">
    <div class='name-line'>
      <span class="username"><a href="{{unbound userPath}}" data-user-card="{{unbound user.username}}">{{format-username user.username}}</a></span>
      <span class="name">{{unbound name}}</span>
    </div>
    <div class="title">{{unbound user.title}}</div>

    {{#if hasBlock}}
      <div class='details'>
        {{yield}}
      </div>
    {{/if}}

  </div>
</script>

<!-- https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/templates/list/posters-column.raw.hbs -->
<script type="text/x-handlebars" data-template-name="list/posters-column.raw">
  <td class='posters'>
  {{#each posters as |poster|}}
  <a href="{{poster.user.path}}" data-user-card="{{poster.user.username}}" class="{{poster.extraClasses}}">{{avatar poster avatarTemplatePath="user.avatar_template" usernamePath="user.username" namePath="user.username" imageSize="small"}}</a>
  {{/each}}
  </td>
</script>

<!-- https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/templates/components/latest-topic-list-item.hbs -->
<script type="text/x-handlebars" data-template-name="components/latest-topic-list-item">
  <div class='topic-poster'>
    {{#user-link user=topic.lastPoster}}
      {{avatar topic.lastPoster namePath="topic.lastPoster" imageSize="large"}}
    {{/user-link}}
  </div>
  <div class='main-link'>
    <div class='top-row'>
      {{raw "topic-status" topic=topic}}
      {{topic-link topic}}
      {{#if topic.featured_link}}
        {{topic-featured-link topic}}
      {{/if}}
      {{topic-post-badges newPosts=topic.totalUnread unseen=topic.unseen url=topic.lastUnreadUrl}}
    </div>
    <div class='bottom-row'>
      {{category-link topic.category}}
      {{discourse-tags topic mode="list"}}
    </div>
  </div>
  <div class='topic-stats'>
    {{raw "list/posts-count-column" topic=topic tagName="div"}}
    <div class="topic-last-activity">
      <a href="{{topic.lastPostUrl}}" title="{{topic.bumpedAtTitle}}">{{format-date topic.bumpedAt format="tiny" noTitle="true"}}</a>
    </div>
  </div>
</script>

Esto no debe considerarse un método 100 % seguro, pero mantendrá la información fuera de la vista de cualquier persona que no esté haciendo un esfuerzo considerable para encontrarla.

En algún momento sería agradable tener esta funcionalidad como comportamiento principal siempre que prioritize_username_in_ux esté habilitado.

@DavidO, ¿has leído Beginner's guide to using Discourse Themes? Si creaste un componente de tema y agregaste el código a la sección común <head>, asegúrate de agregar el componente a tu tema principal.

De acuerdo, gracias. Seguiré trabajando en ello.

Estoy de acuerdo en que sería bueno tenerlo como una opción para ocultar el nombre real a quienes no han iniciado sesión (incluidos los motores de búsqueda).

Gracias, muchachos.

Estoy pensando en hacer pública una parte de mi comunidad. Para proteger a los miembros que han contribuido en esa categoría en particular, me gustaría utilizar algo como este script de anonimización. Sin embargo, no me gustaría habilitar la opción prioritize_username_in_ux. Por otro lado, no me importaría ofuscar todos los nombres: tanto los nombres de usuario como los nombres reales, e incluso quizás las imágenes de perfil. ¿Existe alguna manera de lograr esto con una modificación del script?