From 34bffb3aa1e56e51fbee24a533ae83bc191767a6 Mon Sep 17 00:00:00 2001 From: jamesspeake Date: Tue, 29 Oct 2024 17:35:21 +0000 Subject: [PATCH 1/3] [TAN-2917] Do not try and update fields and options when nothing has changed --- .../web_api/v1/admin/idea_custom_fields_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/back/engines/commercial/idea_custom_fields/app/controllers/idea_custom_fields/web_api/v1/admin/idea_custom_fields_controller.rb b/back/engines/commercial/idea_custom_fields/app/controllers/idea_custom_fields/web_api/v1/admin/idea_custom_fields_controller.rb index 1ac116b79dfc..c73a81ada151 100644 --- a/back/engines/commercial/idea_custom_fields/app/controllers/idea_custom_fields/web_api/v1/admin/idea_custom_fields_controller.rb +++ b/back/engines/commercial/idea_custom_fields/app/controllers/idea_custom_fields/web_api/v1/admin/idea_custom_fields_controller.rb @@ -110,7 +110,7 @@ def update_fields!(page_temp_ids_to_ids_mapping, option_temp_ids_to_ids_mapping, options_params = field_params.delete :options if field_params[:id] && fields_by_id.key?(field_params[:id]) field = fields_by_id[field_params[:id]] - next unless update_field! field, field_params, errors, index + next unless update_field!(field, field_params, errors, index) else field = create_field! field_params, errors, page_temp_ids_to_ids_mapping, index next unless field @@ -164,6 +164,8 @@ def update_field!(field, field_params, errors, index) field_params = idea_custom_field_service.remove_ignored_update_params field_params if field.errors.errors.empty? field.assign_attributes field_params + return true unless field.changed? + SideFxCustomFieldService.new.before_update field, current_user if field.save SideFxCustomFieldService.new.after_update field, current_user @@ -248,6 +250,7 @@ def update_option_image!(option, image_id) def update_option!(option, option_params, errors, field_index, option_index) update_params = option_params.except('image_id') option.assign_attributes update_params + return true unless option.changed? SideFxCustomFieldOptionService.new.before_update option, current_user if option.save From 78721217224c9a6a92ba8da1964f787c57693f3c Mon Sep 17 00:00:00 2001 From: jamesspeake Date: Tue, 29 Oct 2024 18:42:01 +0000 Subject: [PATCH 2/3] [TAN-2917] Added a test --- .../update_all_native_survey_spec.rb | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/back/engines/commercial/idea_custom_fields/spec/acceptance/idea_custom_fields/phase_context/update_all_native_survey_spec.rb b/back/engines/commercial/idea_custom_fields/spec/acceptance/idea_custom_fields/phase_context/update_all_native_survey_spec.rb index da9bb7284c8d..bfb0698e83a9 100644 --- a/back/engines/commercial/idea_custom_fields/spec/acceptance/idea_custom_fields/phase_context/update_all_native_survey_spec.rb +++ b/back/engines/commercial/idea_custom_fields/spec/acceptance/idea_custom_fields/phase_context/update_all_native_survey_spec.rb @@ -3160,6 +3160,31 @@ assert_status 200 end + example 'Updating fields only logs activities when they have changed' do + page = create(:custom_field_page, resource: custom_form) + field1 = create(:custom_field, resource: custom_form, title_multiloc: { 'en' => 'Field 1' }) + field2 = create(:custom_field, resource: custom_form, title_multiloc: { 'en' => 'Field 2' }) + request = { + custom_fields: [ + { + id: page.id, + input_type: 'page', + page_layout: 'default' + }, + { + id: field1.id, + title_multiloc: { 'en' => 'Field 1' } + }, + { + id: field2.id, + title_multiloc: { 'en' => 'Field 2 changed' } + } + ] + } + + expect{do_request(request)}.to enqueue_job(LogActivityJob).exactly(1).times + end + context "Update custom field's map config relation" do let!(:map_config1) { create(:map_config, mappable: nil) } let!(:map_config2) { create(:map_config, mappable: nil) } From 12db70d13dcb60b95e7394331f37dfba20eeb222 Mon Sep 17 00:00:00 2001 From: jamesspeake Date: Thu, 31 Oct 2024 08:51:14 +0000 Subject: [PATCH 3/3] [TAN-2917] Rubocop fixes --- .../phase_context/update_all_native_survey_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/engines/commercial/idea_custom_fields/spec/acceptance/idea_custom_fields/phase_context/update_all_native_survey_spec.rb b/back/engines/commercial/idea_custom_fields/spec/acceptance/idea_custom_fields/phase_context/update_all_native_survey_spec.rb index bfb0698e83a9..38acdee235ad 100644 --- a/back/engines/commercial/idea_custom_fields/spec/acceptance/idea_custom_fields/phase_context/update_all_native_survey_spec.rb +++ b/back/engines/commercial/idea_custom_fields/spec/acceptance/idea_custom_fields/phase_context/update_all_native_survey_spec.rb @@ -3182,7 +3182,7 @@ ] } - expect{do_request(request)}.to enqueue_job(LogActivityJob).exactly(1).times + expect { do_request(request) }.to enqueue_job(LogActivityJob).exactly(1).times end context "Update custom field's map config relation" do