Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

bug/60976 Setting the user display format without lastname breaks user CFs with Group values

Kabiru Mwenja221627d4960f
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index 88504e26a01..658fa0c80ce 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -333,8 +333,11 @@ class CustomField < ApplicationRecord
.in_visible_project_or_me(User.current)
end
- scope
- .select(User::USER_FORMATS_STRUCTURE[Setting.user_format].map(&:to_s), "id", "type")
+ user_format_columns = User::USER_FORMATS_STRUCTURE[Setting.user_format].map(&:to_s)
+ # Always include lastname if not already included, as Groups always need a lastname (alias for name)
+ user_format_columns << "lastname" unless user_format_columns.include?("lastname")
+
+ scope.select(*user_format_columns, "id", "type")
end
end
diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb
index 67ecadbe568..88e7f98f98b 100644
--- a/spec/models/custom_field_spec.rb
+++ b/spec/models/custom_field_spec.rb
@@ -260,6 +260,16 @@ RSpec.describe CustomField do
.to contain_exactly([user2.name, user2.id.to_s])
end
end
+
+ context "with user format setting excluding lastname", with_settings: { user_format: :username } do
+ it "always includes lastname for Group#name{:lastname} aliasing" do
+ expect(field.possible_values_options)
+ .to contain_exactly([user2.name, user2.id.to_s])
+
+ expect(in_visible_scope).to have_received(:select)
+ .with("login", "lastname", "id", "type")
+ end
+ end
end
context "for a list custom field" do