إخفاء الاسم الكامل إذا لم يتم تسجيل الدخول

مرحبًا،

إعداداتي الحالية هي أن 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 لصورة رمزيته (avatar). يجب أن يغطي الكود التالي جميع هذه المناطق بافتراض تفعيل hide_user_profiles_from_public و prioritize_username_in_ux. للأسف، يعتمد هذا الحل على تجاوز عدد قليل من القوالب (templates)، لكنها لا تتغير في كثير من الأحيان. لقد أدرجت روابط إلى الملفات على 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%، لكنها ستبقي المعلومات بعيدة عن الأنظار لأي شخص لا يبذل جهدًا كبيرًا للعثور عليها.

في مرحلة ما، سيكون من الجيد أن تصبح هذه الوظيفة سلوكًا أساسيًا (core behavior) كلما تم تفعيل prioritize_username_in_ux.

@DavidO هل قرأت الدليل المبتدئ لاستخدام سمات Discourse على الرابط التالي؟ Beginner's guide to using Discourse Themes إذا قمت بإنشاء مكون سمة (theme component) وأضفت الكود إلى قسم <head> المشترك، فتأكد من إضافة المكون إلى سمةك الرئيسية.

حسنًا، شكرًا لك. سأعمل على ذلك أكثر.

أتفق على أنه سيكون من الجيد توفير خيار لإخفاء الاسم الحقيقي عن الأشخاص غير المسجلين (بما في ذلك محركات البحث).

أقدر ذلك يا رفاق.

أفكر في جعل جزء من مجتمعي عامًا. لحماية الأعضاء الذين ساهموا في تلك الفئة المحددة، أود استخدام شيء مثل هذا السكربت لإخفاء الهوية. ومع ذلك، لا أريد تمكين prioritize_username_in_ux. من ناحية أخرى، لا بأس بي في تشويش جميع الأسماء - أسماء المستخدمين والأسماء الحقيقية على حد سواء، وربما حتى الصور الرمزية. هل هناك طريقة لتحقيق ذلك من خلال تعديل السكربت؟