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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
limit select for user cf value options
ulferts7efed5b277c6
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rbindex 9fc37427bde..ca359cf9196 100644--- a/app/models/custom_field.rb+++ b/app/models/custom_field.rb@@ -326,12 +326,15 @@ class CustomField < ApplicationRecorddef possible_user_values_options(obj)mapped_with_deduced_project(obj) do |project|- if project&.persisted?- project.principals- else- Principal- .in_visible_project_or_me(User.current)- end+ scope = if project&.persisted?+ project.principals+ else+ Principal+ .in_visible_project_or_me(User.current)+ end++ scope+ .select(*(User::USER_FORMATS_STRUCTURE[Setting.user_format].map(&:to_s) << "id"))endenddiff --git a/spec/lib/custom_field_form_builder_spec.rb b/spec/lib/custom_field_form_builder_spec.rbindex 00820ae9037..06337c5ed12 100644--- a/spec/lib/custom_field_form_builder_spec.rb+++ b/spec/lib/custom_field_form_builder_spec.rb@@ -255,6 +255,7 @@ RSpec.describe CustomFieldFormBuilder dolet(:project) { build_stubbed(:project) }let(:user1) { build_stubbed(:user) }let(:user2) { build_stubbed(:user) }+ let(:scope) { instance_double(ActiveRecord::Relation) }let(:resource) { project }@@ -268,8 +269,12 @@ RSpec.describe CustomFieldFormBuilder doendallow(project)- .to(receive(:principals))- .and_return([user1, user2])+ .to receive(:principals)+ .and_return(scope)++ allow(scope)+ .to receive(:select)+ .and_return([user1, user2])endit_behaves_like "wrapped in container", "select-container" dodiff --git a/spec/models/custom_actions/actions/custom_field_spec.rb b/spec/models/custom_actions/actions/custom_field_spec.rbindex 05c68c59438..afc2c54b1f0 100644--- a/spec/models/custom_actions/actions/custom_field_spec.rb+++ b/spec/models/custom_actions/actions/custom_field_spec.rb@@ -441,12 +441,17 @@ RSpec.describe CustomActions::Actions::CustomField dobuild_stubbed(:user),build_stubbed(:user)]end+ let(:scope) { instance_double(ActiveRecord::Relation) }before doallow(Principal).to receive(:in_visible_project_or_me)- .with(User.current)- .and_return(users)+ .with(User.current)+ .and_return(scope)++ allow(scope)+ .to receive(:select)+ .and_return(users)endcontext "for a non required field" do@@ -515,12 +520,17 @@ RSpec.describe CustomActions::Actions::CustomField dobuild_stubbed(:user),build_stubbed(:user)]end+ let(:scope) { instance_double(ActiveRecord::Relation) }before doallow(Principal).to receive(:in_visible_project_or_me)- .with(User.current)- .and_return(users)+ .with(User.current)+ .and_return(scope)++ allow(scope)+ .to receive(:select)+ .and_return(users)endit_behaves_like "associated custom action validations" dodiff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rbindex f448ba74812..67ecadbe568 100644--- a/spec/models/custom_field_spec.rb+++ b/spec/models/custom_field_spec.rb@@ -215,17 +215,27 @@ RSpec.describe CustomField dolet(:project) { build_stubbed(:project) }let(:user1) { build_stubbed(:user) }let(:user2) { build_stubbed(:user) }+ let(:in_visible_scope) { instance_double(ActiveRecord::Relation) }+ let(:principals_scope) { instance_double(ActiveRecord::Relation) }context "for a user custom field" dobefore dofield.field_format = "user"allow(project).to receive(:principals)- .and_return([user1, user2])+ .and_return(principals_scope)++ allow(principals_scope)+ .to receive(:select)+ .and_return([user1, user2])allow(Principal).to receive(:in_visible_project_or_me)- .and_return([user2])+ .and_return(in_visible_scope)++ allow(in_visible_scope)+ .to receive(:select)+ .and_return([user2])endcontext "for a project" do