Nascondi il nome completo se non si è connessi

Ciao,

la mia configurazione attuale è tale che Discourse è leggibile anche se non si è loggati. Inoltre, ho impostato “abilita nomi” per vedere il nome completo subito accanto al nickname.

Ma ciò che NON voglio è che gli utenti non loggati possano vedere il nome completo. Esiste un modo per disabilitare questa funzione? Non sono riuscito a trovarlo.

Grazie in anticipo per il tuo aiuto!

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:

È mai stato integrato?

Vorremmo che i nostri forum fossero leggibili pubblicamente e indicizzati dai motori di ricerca, ma non vorremmo mostrare i nomi reali a meno che non si sia loggati (in modo che i nomi reali delle persone non siano esposti ai non membri e ai motori di ricerca).

È possibile? Ho provato il codice sopra ma non sono riuscito a farlo funzionare.

Il codice sopra ha bisogno di un aggiornamento, @tshenry?

Ho appena controllato e il codice funziona ancora. Tutte le note che ho menzionato sono ancora valide.


Ho cercato di individuare tutte le aree in cui il nome completo dell’utente veniva utilizzato come attributo title del suo avatar. Il codice seguente dovrebbe coprire tutte le aree, supponendo che hide_user_profiles_from_public e prioritize_username_in_ux siano abilitati. Purtroppo, si basa sull’override di un paio di template, ma questi non cambiano molto spesso. Ho incluso i link ai file su GitHub nel caso in cui tu voglia verificare se è necessario aggiornare qualche parte del codice. L’unica modifica che ho apportato è stata aggiungere o modificare il namePath in modo che utilizzi il nome utente invece del nome 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>

Questo non dovrebbe essere considerato un metodo sicuro al 100%, ma manterrà le informazioni fuori dalla vista di chiunque non stia cercando attivamente di trovarle.

Prima o poi sarebbe bello avere questa funzionalità come comportamento di base ogni volta che prioritize_username_in_ux è abilitato.

@DavidO, hai letto Beginner's guide to using Discourse Themes? Se hai creato un componente tema e aggiunto il codice alla sezione comune <head>, assicurati di aggiungere il componente al tuo tema principale.

Ok, grazie. Ci lavorerò ancora un po’.

Sono d’accordo che sarebbe bello avere l’opzione per nascondere il nome vero alle persone non loggate (inclusi i motori di ricerca).

Apprezzo il supporto, ragazzi.

Sto pensando di rendere pubblica una parte della mia community. Per proteggere i membri che hanno contribuito a quella specifica categoria, vorrei utilizzare qualcosa come questo script di anonimizzazione. Tuttavia, non vorrei abilitare l’opzione prioritize_username_in_ux. D’altra parte, non mi dispiacerebbe oscurare tutti i nomi: sia i nomi utente che i nomi reali, e forse anche gli avatar. Esiste un modo per ottenere questo risultato modificando lo script?