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
[#53704] Visible=false project attribute values are deleted when a non-admin user edits the attributes
Dombi Attila27e8573525c7
diff --git a/app/models/projects/acts_as_customizable_patches.rb b/app/models/projects/acts_as_customizable_patches.rbindex 9fdd53b0b0c..c51939b08ee 100644--- a/app/models/projects/acts_as_customizable_patches.rb+++ b/app/models/projects/acts_as_customizable_patches.rb@@ -108,7 +108,7 @@ module Projects::ActsAsCustomizablePatches# in order to support implicit activation of custom fields when values are provided during an updateself._query_available_custom_fields_on_global_level = trueresult = yield- self._query_available_custom_fields_on_global_level = false+ self._query_available_custom_fields_on_global_level = nilresultend@@ -118,10 +118,21 @@ module Projects::ActsAsCustomizablePatches# in contrast to acts_as_customizable, custom_fields are enabled per project# thus we need to check the project_custom_field_project_mappingscustom_fields = ProjectCustomField- .visible.includes(:project_custom_field_section).order("custom_field_sections.position", :position_in_custom_field_section)+ # Do not hide the invisble fields when accessing via the _query_available_custom_fields_on_global_level+ # flag. Due to the internal working of the acts_as_customizable plugin, when a project admin updates+ # the custom fields, it will clear out all the hidden fields that are not visible for them.+ # This happens because the `#ensure_custom_values_complete` will gather all the `custom_field_values`+ # and assigns them to the custom_fields association. If the `custom_field_values` do not contain the+ # hidden fields, they will be cleared from the association. The `custom_field_values` will contain the+ # hidden fields, only if they are returned from this method. Hence we should not hide them,+ # when accessed with the the _query_available_custom_fields_on_global_level flag on.+ unless _query_available_custom_fields_on_global_level+ custom_fields = custom_fields.visible+ end+# available_custom_fields is called from within the acts_as_customizable module# we don't want to adjust these calls, but need a way to query the available custom fields on a global level in some cases# thus we pass in this parameter as an instance flag implicitly here,@@ -155,8 +166,11 @@ module Projects::ActsAsCustomizablePatcheswith_all_available_custom_fields { super }end- # we need to query the available custom fields on a global level when- # trying to set a custom field which is not enabled via e.g. custom_field_123="foo"+ # We need to query the available custom fields on a global level when+ # trying to set a custom field which is not enabled via the API e.g. custom_field_123="foo"+ # This implies implicit activation of the disabled custom fields via the API. As a side effect,+ # we will have empty CustomValue objects created for each custom field, regardless of its+ # enabled/disabled state in the project.def for_custom_field_accessor(method_symbol)with_all_available_custom_fields { super }enddiff --git a/spec/features/projects/project_custom_fields/overview_page/dialog/update_spec.rb b/spec/features/projects/project_custom_fields/overview_page/dialog/update_spec.rbindex 1e7dbddd4dc..83336ed1d69 100644--- a/spec/features/projects/project_custom_fields/overview_page/dialog/update_spec.rb+++ b/spec/features/projects/project_custom_fields/overview_page/dialog/update_spec.rb@@ -651,5 +651,36 @@ RSpec.describe "Edit project custom fields on project overview page", :js doendendend++ describe "with hidden fields" do+ let(:section) { section_for_input_fields }+ let(:dialog) { Components::Projects::ProjectCustomFields::EditDialog.new(project, section) }+ let(:custom_field) { string_project_custom_field }+ let(:field) { FormFields::Primerized::InputField.new(custom_field) }++ before do+ all_fields.without(string_project_custom_field).each { |cf| cf.update(visible: false) }+ end++ it "does not clears them after a project admin updates" do+ expected_custom_values =+ project.custom_values.where.not(custom_field: string_project_custom_field)+ .pluck(:customized_type, :customized_id, :custom_field_id, :value)++ overview_page.visit_page++ overview_page.open_edit_dialog_for_section(section)++ field.fill_in(with: "new value")+ dialog.submit+ dialog.expect_closed++ custom_values =+ project.custom_values.where.not(custom_field: string_project_custom_field)+ .pluck(:customized_type, :customized_id, :custom_field_id, :value)++ expect(custom_values).to eq(expected_custom_values)+ end+ endendenddiff --git a/spec/features/projects/project_custom_fields/overview_page/shared_context.rb b/spec/features/projects/project_custom_fields/overview_page/shared_context.rbindex 8379cab6607..9b3ca69b1ee 100644--- a/spec/features/projects/project_custom_fields/overview_page/shared_context.rb+++ b/spec/features/projects/project_custom_fields/overview_page/shared_context.rb@@ -225,8 +225,13 @@ RSpec.shared_context "with seeded projects, members and project custom fields" d]end+ let(:all_fields) { input_fields + select_fields + multi_select_fields }+let!(:boolean_project_custom_field_activated_in_other_project) do- create(:boolean_project_custom_field, projects: [other_project], name: "Other Boolean field",- project_custom_field_section: section_for_input_fields)+ field = create(:boolean_project_custom_field, projects: [other_project],+ name: "Other Boolean field",+ project_custom_field_section: section_for_input_fields)+ create(:custom_value, customized: project, custom_field: field, value: true)+ fieldendend