ログインしていない場合はフルネームを非表示にする

こんにちは、

現在の設定では、ログインしていなくても Discourse が閲覧可能です。また、「名前を有効化」を設定して、ニックネームのすぐ隣にフルネームが表示されるようにしています。

しかし、ログインしていないユーザーにフルネームが見えてしまうのは避けたいと考えています。これを無効にする方法はありますか?見つけられませんでした。

お手数ですが、ご教示いただけますと幸いです。

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:

これは統合されましたか?

当社のフォーラムは一般公開で検索エンジンにもインデックスされたいと考えていますが、ログインしていない場合は実名を表示したくありません(非メンバーや検索エンジンに実名が露見しないようにするため)。

これは可能でしょうか?上記のコードを試しましたが、動作させることができませんでした。

上記のコードは更新が必要ですか @tshenry

確認しましたが、コードは引き続き機能しています。私が言及しているすべての注意事項もそのまま適用されます。


ユーザーのフルネームがアバターの title 属性として使用されている箇所をすべて特定しようと試みました。以下のコードは、hide_user_profiles_from_publicprioritize_username_in_ux が有効になっていると仮定すれば、すべての該当箇所をカバーするはずです。残念ながら、いくつかのテンプレートをオーバーライドする必要がありますが、それらは頻繁に変更されるものではありません。コードの更新が必要かどうかを確認したい場合に備え、GitHub 上の該当ファイルへのリンクも記載しました。私が行った変更は、フルネームの代わりにユーザー名を使用するように namePath を追加または変更することのみです。

<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>

これは 100% 安全な方法とは見なすべきではありませんが、情報を必死に探そうとしない人からは隠すことができます。

将来的には、prioritize_username_in_ux が有効になっている場合に、この機能をコアの動作として実装できると良いですね。

@DavidO さん、Beginner's guide to using Discourse Themes をご覧になりましたか?テーマコンポーネントを作成して、Common の <head> セクションにコードを追加した場合は、そのコンポーネントをメインのテーマに追加することを忘れないでください。

OK、ありがとうございます。さらに作業を進めます。

ログインしていない人(検索エンジンを含む)から実名を非表示にするオプションがあれば良いですね。その点に賛成です。

みなさん、ありがとうございます。

コミュニティの一部を公開しようと考えています。特定のカテゴリに貢献したメンバーを保護するため、このような匿名化スクリプトを使用したいと考えています。ただし、prioritize_username_in_ux は有効にしたくありません。一方、すべての名前(ユーザー名も実名も)を難読化すること、さらにアバターさえも隠すことには問題ありません。スクリプトを修正することでこれを達成する方法はありますか?