From 79b68bc32b86c0a18550707addd7c83cbb6b0887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 13 Jan 2025 11:28:29 +0100 Subject: [PATCH] FIX: show both group's full name & name when they differ (#30672) In the groups page (/g) where we list all the groups, we were only showing one group "name" per group. If a full name was set, we would show it, otherwise we would show the group's "display name". This was somewhat inconsistent because we only show the group's names in all the various controls we use to filter/search by group. Plus we used a slightly different logic when displaying the names of a group on the "group page". So I updated the "GroupsInfo" component to show either 1 or 2 names depending on whether a full name is set, and it's different from the display name or the name of the group. I used this component in the "group page" so the names will be consistent between the "groups page" and the "group page". Also renamed the "GroupsInfo" component to "GroupInfo" since it only ever deals with 1 group at a time. Ref - https://meta.discourse.org/t/-/345415 --- ## When "full name" differs from the "group's name" (cf. `@admins`, `@staff`, and `@moderators`) Screenshot 2025-01-09 at 15 56 29 ## When "full name" is the same as the "group's name" When `unicode` is allowed in usernames, then the group's full name is the same as the group's name, so we only show one name. Screenshot 2025-01-09 at 16 25 53 --- .../discourse/app/components/group-info.gjs | 37 +++++++++++++++++++ .../discourse/app/components/groups-info.gjs | 19 ---------- .../discourse/app/templates/group.hbs | 10 +---- .../discourse/app/templates/groups/index.hbs | 2 +- .../stylesheets/common/base/groups.scss | 6 --- app/models/group.rb | 16 +++++++- config/site_settings.yml | 2 +- 7 files changed, 54 insertions(+), 38 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/group-info.gjs delete mode 100644 app/assets/javascripts/discourse/app/components/groups-info.gjs diff --git a/app/assets/javascripts/discourse/app/components/group-info.gjs b/app/assets/javascripts/discourse/app/components/group-info.gjs new file mode 100644 index 00000000000..bbd758108b4 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/group-info.gjs @@ -0,0 +1,37 @@ +import Component from "@glimmer/component"; +import { hash } from "@ember/helper"; +import PluginOutlet from "discourse/components/plugin-outlet"; + +export default class GroupInfo extends Component { + + + get names() { + const { full_name, display_name, name } = this.args.group; + return [...new Set([full_name, display_name, name].filter(Boolean))]; + } + + get name() { + return this.names[0]; + } + + get mentionName() { + return this.names[1] ? `@${this.names[1]}` : null; + } +} diff --git a/app/assets/javascripts/discourse/app/components/groups-info.gjs b/app/assets/javascripts/discourse/app/components/groups-info.gjs deleted file mode 100644 index 052da089068..00000000000 --- a/app/assets/javascripts/discourse/app/components/groups-info.gjs +++ /dev/null @@ -1,19 +0,0 @@ -import { hash } from "@ember/helper"; -import { or } from "truth-helpers"; -import PluginOutlet from "discourse/components/plugin-outlet"; - -const GroupsInfo = ; - -export default GroupsInfo; diff --git a/app/assets/javascripts/discourse/app/templates/group.hbs b/app/assets/javascripts/discourse/app/templates/group.hbs index 5389906d4e4..5f18ffbd5e0 100644 --- a/app/assets/javascripts/discourse/app/templates/group.hbs +++ b/app/assets/javascripts/discourse/app/templates/group.hbs @@ -31,15 +31,7 @@ {{/if}}
- - {{or this.model.full_name this.model.name}} - - - {{#if this.model.full_name}} -
- {{this.model.name}} -
- {{/if}} + {{#if (and this.canManageGroup this.model.automatic)}} diff --git a/app/assets/javascripts/discourse/app/templates/groups/index.hbs b/app/assets/javascripts/discourse/app/templates/groups/index.hbs index 23a05d20527..3784ad45fc5 100644 --- a/app/assets/javascripts/discourse/app/templates/groups/index.hbs +++ b/app/assets/javascripts/discourse/app/templates/groups/index.hbs @@ -65,7 +65,7 @@ {{/if}} - +
{{d-icon "user" }}{{group.user_count}}
diff --git a/app/assets/stylesheets/common/base/groups.scss b/app/assets/stylesheets/common/base/groups.scss index d2037e57040..91d7e4a9d59 100644 --- a/app/assets/stylesheets/common/base/groups.scss +++ b/app/assets/stylesheets/common/base/groups.scss @@ -111,12 +111,6 @@ } } - .groups-info-name { - font-size: var(--font-up-1); - font-weight: bold; - color: var(--primary); - } - $size: 40px; $icon-size: math.div($size, 1.8); diff --git a/app/models/group.rb b/app/models/group.rb index 2b53603b4fa..4ff0cd13c3e 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -502,6 +502,11 @@ class Group < ActiveRecord::Base end end + def self.can_use_name?(name, group) + UsernameValidator.new(name).valid_format? && + (group.name == name || !User.username_exists?(name)) + end + def self.refresh_automatic_group!(name) return unless id = AUTO_GROUPS[name] @@ -519,9 +524,16 @@ class Group < ActiveRecord::Base # don't allow shoddy localization to break this localized_name = I18n.t("groups.default_names.#{name}", locale: SiteSetting.default_locale) - validator = UsernameValidator.new(localized_name) + default_name = I18n.t("groups.default_names.#{name}") - group.name = localized_name if validator.valid_format? && !User.username_exists?(localized_name) + group.name = + if can_use_name?(localized_name, group) + localized_name + elsif can_use_name?(default_name, group) + default_name + else + name.to_s + end # the everyone group is special, it can include non-users so there is no # way to have the membership in a table diff --git a/config/site_settings.yml b/config/site_settings.yml index 35d423d001f..02cd5adad83 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -692,7 +692,7 @@ users: cs: "[ěščřžýáíéóůúďťňĚŠČŘŽÝÁÍÉÓŮÚĎŤŇ]" de: "[äöüßÄÖÜẞ]" fi: "[åäöÅÄÖ]" - ja: '[\p{Han}\p{Katakana}\p{Hiragana}]' + ja: '[\p{Han}\p{Katakana}\p{Hiragana}ー]' ko: '\p{Hangul}' zh_CN: '\p{Han}' zh_TW: '\p{Han}'