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
fix displaying `multi` toggle in cf form (#9269)
ulferts9edc7244a94e
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rbindex 1ae182ef6cd..2d121527635 100644--- a/app/models/custom_field.rb+++ b/app/models/custom_field.rb@@ -262,13 +262,18 @@ class CustomField < ApplicationRecordmulti_valueend+ def multi_value_possible?+ %w[user list].include?(field_format) &&+ [ProjectCustomField, WorkPackageCustomField].include?(self.class)+ end+### Overrides cache key so that a custom field's representation# is updated correctly when it's mutli_value attribute changes.def cache_keytag = multi_value? ? "mv" : "sv"- super + '/' + tag+ "#{super}/#{tag}"endprivatediff --git a/app/views/custom_fields/_form.html.erb b/app/views/custom_fields/_form.html.erbindex 37ab0420cb8..4f902105850 100644--- a/app/views/custom_fields/_form.html.erb+++ b/app/views/custom_fields/_form.html.erb@@ -60,7 +60,7 @@ See docs/COPYRIGHT.rdoc for more details.</span></div>- <% if @custom_field.new_record? || @custom_field.field_format == 'list' %>+ <% if @custom_field.new_record? || @custom_field.multi_value_possible? %><div class="form--field" id="custom_field_multi_select" style="display:none"><% if EnterpriseToken.allows_to?(:multiselect_custom_fields) %><%= f.check_box :multi_value %>diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rbindex 32603277523..dfead8ad2c3 100644--- a/spec/models/custom_field_spec.rb+++ b/spec/models/custom_field_spec.rb@@ -365,6 +365,80 @@ describe CustomField, type: :model doendend+ describe '#multi_value_possible?' do+ context 'with a wp list cf' do+ let(:field) { FactoryBot.build_stubbed :list_wp_custom_field }++ it 'is true' do+ expect(field)+ .to be_multi_value_possible+ end+ end++ context 'with a wp user cf' do+ let(:field) { FactoryBot.build_stubbed :user_wp_custom_field }++ it 'is true' do+ expect(field)+ .to be_multi_value_possible+ end+ end++ context 'with a wp int cf' do+ let(:field) { FactoryBot.build_stubbed :int_wp_custom_field }++ it 'is true' do+ expect(field)+ .not_to be_multi_value_possible+ end+ end++ context 'with a project list cf' do+ let(:field) { FactoryBot.build_stubbed :list_project_custom_field }++ it 'is true' do+ expect(field)+ .to be_multi_value_possible+ end+ end++ context 'with a project user cf' do+ let(:field) { FactoryBot.build_stubbed :user_project_custom_field }++ it 'is true' do+ expect(field)+ .to be_multi_value_possible+ end+ end++ context 'with a project int cf' do+ let(:field) { FactoryBot.build_stubbed :int_project_custom_field }++ it 'is true' do+ expect(field)+ .not_to be_multi_value_possible+ end+ end++ context 'with a time_entry user cf' do+ let(:field) { FactoryBot.build_stubbed :time_entry_custom_field, field_format: 'user' }++ it 'is true' do+ expect(field)+ .not_to be_multi_value_possible+ end+ end++ context 'with a time_entry list cf' do+ let(:field) { FactoryBot.build_stubbed :time_entry_custom_field, field_format: 'list' }++ it 'is true' do+ expect(field)+ .not_to be_multi_value_possible+ end+ end+ end+describe '#destroy' doit 'removes the cf' dofield.save!