Skip to content

Commit

Permalink
Merge pull request #9250 from CitizenLabDotCo/TAN-2917-only-log-updat…
Browse files Browse the repository at this point in the history
…e-activities-when-fields-change

TAN-2917 - Do not try log updates to custom fields when nothing has changed in form editor
  • Loading branch information
jamesspeake authored Oct 31, 2024
2 parents 306cf13 + 12db70d commit 9e887d0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit 9e887d0

Please sign in to comment.