Skip to content

Commit 9576508

Browse files
authored
Merge pull request #24124 from opf/fix-OP-19698
Ensure the default user attributes section has a name
2 parents 567cc9d + 717c6ec commit 9576508

10 files changed

Lines changed: 42 additions & 37 deletions

File tree

app/components/settings/user_custom_field_sections/show_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
end
1010
content_container.with_column do
1111
render(Primer::Beta::Text.new(font_weight: :bold)) do
12-
@user_custom_field_section.name.presence || t("settings.user_custom_fields.label_untitled_section")
12+
@user_custom_field_section.name
1313
end
1414
end
1515
end

app/components/users/profile/attributes_section_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def attributes
5252
end
5353

5454
def section_title
55-
@section.name.presence || t("settings.user_custom_fields.label_untitled_section")
55+
@section.name
5656
end
5757
end
5858
end

app/forms/custom_fields/details_form.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class DetailsForm < ApplicationForm
5555
required: true
5656
) do |list|
5757
section_class_for_model.all.each do |cs| # rubocop:disable Rails/FindEach -- ordered by default_scope; find_each would override it
58-
list.option(value: cs.id, label: cs.name.presence || I18n.t("settings.user_custom_fields.label_untitled_section"))
58+
list.option(value: cs.id, label: cs.name)
5959
end
6060
end
6161
end

app/forms/users/form/attributes_form.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def render_section(form, section)
105105
end
106106

107107
def section_title(section)
108-
section.name.presence || I18n.t("settings.user_custom_fields.label_untitled_section")
108+
section.name
109109
end
110110

111111
def render_built_in(group, key)

app/models/user_custom_field_section.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,4 @@ def self.with_filled_fields_for(user, visible_on_user_card: nil) # rubocop:disab
7474
[section, ordered] if ordered.any?
7575
end
7676
end
77-
78-
def untitled?
79-
name.blank?
80-
end
8177
end

app/seeders/basic_data/user_custom_field_section_seeder.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,11 @@
3131
module BasicData
3232
class UserCustomFieldSectionSeeder < Seeder
3333
def seed_data!
34-
# The default section is intentionally untitled — it renders the I18n fallback
35-
# label in the UI. The name validation is bypassed to match the migration that
36-
# creates the same section for existing installations.
37-
section = UserCustomFieldSection.new(
34+
UserCustomFieldSection.create!(
35+
name: I18n.t("settings.user_custom_fields.label_default_section", locale: Setting.default_language),
3836
position: 1,
3937
attribute_order: UserCustomFieldSection::BUILT_IN_ATTRIBUTES
4038
)
41-
section.save!(validate: false)
4239
end
4340

4441
def applicable?

config/locales/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5859,7 +5859,7 @@ en:
58595859
heading: "User attributes"
58605860
label_new_attribute: "User attribute"
58615861
label_new_section: "Section"
5862-
label_untitled_section: "User attributes"
5862+
label_default_section: "User attributes"
58635863
new:
58645864
heading: "New attribute"
58655865
tabs:
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
class BackfillDefaultUserCustomFieldSectionName < ActiveRecord::Migration[8.1]
4+
def up
5+
execute(<<~SQL.squish)
6+
UPDATE custom_field_sections
7+
SET name = #{quote(default_section_name)}, updated_at = NOW()
8+
WHERE type = 'UserCustomFieldSection'
9+
AND (name IS NULL OR name = '')
10+
SQL
11+
end
12+
13+
def down
14+
execute(<<~SQL.squish)
15+
UPDATE custom_field_sections
16+
SET name = NULL, updated_at = NOW()
17+
WHERE type = 'UserCustomFieldSection'
18+
AND name = #{quote(default_section_name)}
19+
SQL
20+
end
21+
22+
private
23+
24+
def default_section_name
25+
I18n.t("settings.user_custom_fields.label_default_section", locale: default_language)
26+
end
27+
28+
# Settings may be unavailable when migrating a clean database (e.g. the settings
29+
# table or its seeds are not yet present), so fall back to English.
30+
def default_language
31+
Setting.default_language.presence || "en"
32+
rescue StandardError
33+
"en"
34+
end
35+
end

spec/components/users/profile/attributes_section_component_spec.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,4 @@
9696
expect(component.render?).to be(false)
9797
end
9898
end
99-
100-
context "with an untitled section" do
101-
shared_let(:custom_field) do
102-
create(:user_custom_field, :string, user_custom_field_section: section)
103-
end
104-
let(:user) { create(:user, custom_values: [build(:custom_value, custom_field:, value: "x")]) }
105-
106-
before do
107-
section.update_column(:name, nil)
108-
section.update_column(:attribute_order, [custom_field.column_name])
109-
render_inline(component)
110-
end
111-
112-
it "renders the I18n fallback label" do
113-
expect(page).to have_text(I18n.t("settings.user_custom_fields.label_untitled_section"))
114-
end
115-
end
11699
end

spec/models/user_custom_field_section_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@
3939
end
4040
end
4141

42-
describe "#untitled?" do
43-
it { expect(described_class.new(name: nil)).to be_untitled }
44-
it { expect(described_class.new(name: "")).to be_untitled }
45-
it { expect(described_class.new(name: "My section")).not_to be_untitled }
46-
end
47-
4842
describe "#add_to_order" do
4943
it "appends to the end when no position given" do
5044
section.add_to_order("cf_1")

0 commit comments

Comments
 (0)