A platform for community discussion. Free, open, simple.
UX: Improve UX when profiles are hidden from anon (#32938)
David Taylor8adb6649fe48
diff --git a/app/assets/javascripts/discourse/app/components/about-page-user.gjs b/app/assets/javascripts/discourse/app/components/about-page-user.gjsindex 2fbd849d592..0279e869684 100644--- a/app/assets/javascripts/discourse/app/components/about-page-user.gjs+++ b/app/assets/javascripts/discourse/app/components/about-page-user.gjs@@ -1,28 +1,19 @@import avatar from "discourse/helpers/avatar";import { prioritizeNameInUx } from "discourse/lib/settings";-import { userPath } from "discourse/lib/url";-import { i18n } from "discourse-i18n";+import UserLink from "./user-link";const AboutPageUser = <template><div data-username={{@user.username}} class="user-info small"><div class="user-image"><div class="user-image-inner">- <a- href={{userPath @user.username}}- data-user-card={{@user.username}}- aria-hidden="true"- >+ <UserLink @username={{@user.username}} @ariaHidden={{true}}>{{avatar @user imageSize="large"}}- </a>+ </UserLink></div></div><div class="user-detail"><div class="name-line">- <a- href={{userPath @user.username}}- data-user-card={{@user.username}}- aria-label={{i18n "user.profile_possessive" [email protected]}}- >+ <UserLink @username={{@user.username}}><span class="username">{{#if (prioritizeNameInUx @user.name)}}{{@user.name}}@@ -37,7 +28,7 @@ const AboutPageUser = <template>{{@user.name}}{{/if}}</span>- </a>+ </UserLink></div><div class="title">{{@user.title}}</div></div>diff --git a/app/assets/javascripts/discourse/app/components/topic-list/item.gjs b/app/assets/javascripts/discourse/app/components/topic-list/item.gjsindex 8243eb36e63..4da94ad1e22 100644--- a/app/assets/javascripts/discourse/app/components/topic-list/item.gjs+++ b/app/assets/javascripts/discourse/app/components/topic-list/item.gjs@@ -12,6 +12,7 @@ import PostCountOrBadges from "discourse/components/topic-list/post-count-or-badimport TopicExcerpt from "discourse/components/topic-list/topic-excerpt";import TopicLink from "discourse/components/topic-list/topic-link";import TopicStatus from "discourse/components/topic-status";+import UserLink from "discourse/components/user-link";import avatar from "discourse/helpers/avatar";import categoryLink from "discourse/helpers/category-link";import concatClass from "discourse/helpers/concat-class";@@ -301,14 +302,17 @@ export default class Item extends Component {@name="topic-list-item-mobile-avatar"@outletArgs={{lazyHash topic=@topic}}>- <a- href={{@topic.lastPostUrl}}- aria-label={{i18n+ <UserLink+ @ariaLabel={{i18n"latest_poster_link"}}- data-user-card={{@topic.lastPosterUser.username}}- >{{avatar @topic.lastPosterUser imageSize="large"}}</a>+ @username={{@topic.lastPosterUser.username}}+ >+ {{avatar+ @topic.lastPosterUser+ imageSize="large"+ }}</UserLink></PluginOutlet>{{/if}}</div>diff --git a/app/assets/javascripts/discourse/app/components/topic-list/item/posters-cell.gjs b/app/assets/javascripts/discourse/app/components/topic-list/item/posters-cell.gjsindex 6f1a69568c7..4c1cbadd1ba 100644--- a/app/assets/javascripts/discourse/app/components/topic-list/item/posters-cell.gjs+++ b/app/assets/javascripts/discourse/app/components/topic-list/item/posters-cell.gjs@@ -1,3 +1,4 @@+import UserLink from "discourse/components/user-link";import avatar from "discourse/helpers/avatar";const PostersCell = <template>@@ -6,17 +7,18 @@ const PostersCell = <template>{{#if poster.moreCount}}<a class="posters-more-count">{{poster.moreCount}}</a>{{else}}- <a- href={{poster.user.path}}- data-user-card={{poster.user.username}}+ <UserLink+ @username={{poster.user.username}}+ @href={{poster.user.path}}class={{poster.extraClasses}}- >{{avatar+ >+ {{avatarposteravatarTemplatePath="user.avatar_template"usernamePath="user.username"namePath="user.name"imageSize="small"- }}</a>+ }}</UserLink>{{/if}}{{/each}}</td>diff --git a/app/assets/javascripts/discourse/app/components/topic-map/topic-participant.gjs b/app/assets/javascripts/discourse/app/components/topic-map/topic-participant.gjsindex b97aad76dbe..3939f5962ec 100644--- a/app/assets/javascripts/discourse/app/components/topic-map/topic-participant.gjs+++ b/app/assets/javascripts/discourse/app/components/topic-map/topic-participant.gjs@@ -3,6 +3,7 @@ import { htmlSafe } from "@ember/template";import { gt } from "truth-helpers";import PluginOutlet from "discourse/components/plugin-outlet";import UserAvatarFlair from "discourse/components/user-avatar-flair";+import UserLink from "discourse/components/user-link";import lazyHash from "discourse/helpers/lazy-hash";import { avatarImg } from "discourse/lib/avatar-utils";import { userPath } from "discourse/lib/url";@@ -59,18 +60,19 @@ export default class TopicParticipant extends Component {@outletArgs={{lazyHash participant=@participant}}><div class={{this.participantClasses}}>- <a+ <UserLink+ @username={{@participant.username}}+ @href={{this.userUrl}}class={{this.linkClasses}}- data-user-card={{@participant.username}}title={{@participant.username}}- href={{this.userUrl}}>+{{this.avatarImage}}{{#if (gt @participant.post_count 1)}}<span class="post-count">{{@participant.post_count}}</span>{{/if}}<UserAvatarFlair @user={{@participant}} />- </a>+ </UserLink></div></PluginOutlet></template>diff --git a/app/assets/javascripts/discourse/app/components/user-link.gjs b/app/assets/javascripts/discourse/app/components/user-link.gjsindex 39494894934..322018481c8 100644--- a/app/assets/javascripts/discourse/app/components/user-link.gjs+++ b/app/assets/javascripts/discourse/app/components/user-link.gjs@@ -18,6 +18,10 @@ export default class UserLink extends Component {}get href() {+ if (this.hideFromAnonUser) {+ return null;+ }+const url = this.args.href || this.args.user?.path;if (url) {return url;diff --git a/app/assets/stylesheets/common/foundation/helpers.scss b/app/assets/stylesheets/common/foundation/helpers.scssindex 40dbce8d026..e3924f19786 100644--- a/app/assets/stylesheets/common/foundation/helpers.scss+++ b/app/assets/stylesheets/common/foundation/helpers.scss@@ -65,3 +65,7 @@.clickable {cursor: pointer;}++.non-clickable {+ cursor: default;+}diff --git a/spec/system/user_page/hide_from_public_spec.rb b/spec/system/user_page/hide_from_public_spec.rbindex c3fb78ef7cb..e64977f2cbf 100644--- a/spec/system/user_page/hide_from_public_spec.rb+++ b/spec/system/user_page/hide_from_public_spec.rb@@ -11,15 +11,20 @@ describe "hide_user_profiles_from_public", type: :system doendit "displays an error when navigating from an internal link" do- Fabricate(:post, user: user)- visit("/latest")- find("[data-user-card='#{user.username}']").click+ post =+ Fabricate(+ :post,+ user: user,+ raw: "Check out my profile at [#{user.username}](/u/#{user.username})",+ )+ visit(post.url)+ find(".cooked a[href='/u/#{user.username}']").clickexpect(page).to have_css(".error-page .reason", text: I18n.t("js.errors.reasons.forbidden"))expect(page).to have_css(".error-page .desc", text: I18n.t("js.user.login_to_view_profile"))expect(page).to have_current_path("/u/#{user.username}")find(".error-page .buttons .btn-primary", text: "Back").click- expect(page).to have_current_path("/latest")+ expect(page).to have_current_path(post.url)endend