diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 77548ea7..e63842ce 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -270,21 +270,30 @@ class ContentController < ApplicationController unless attribute_value.nil? if existing_value + existing_value.disable_changelog_this_request = true existing_value.update!(value: attribute_value) + existing_value.disable_changelog_this_request = false else - attribute_field.attribute_values.create!( + new_value = attribute_field.attribute_values.new( user_id: current_user.id, entity_type: @content.class.name, entity_id: @content.id, value: attribute_value, privacy: 'private' # todo just make this the default for the column instead ) + + new_value.disable_changelog_this_request = true + new_value.save! + new_value.disable_changelog_this_request = true end end - if delete_model_source_value && attribute_field.old_column_source.present? && attribute_field.field_type != 'name' && @content.send(attribute_field.old_column_source).present? - @content.update_attribute(attribute_field.old_column_source, nil) - end + # Lets leave these columns alone for now so 1) we don't have to mess with disabling changelogs, and 2) why not be safe? + # if delete_model_source_value && attribute_field.old_column_source.present? && attribute_field.field_type != 'name' && @content.send(attribute_field.old_column_source).present? + # @content.disable_changelog_this_request = true + # @content.update_attribute(attribute_field.old_column_source, nil) + # @content.disable_changelog_this_request = false + # end end end diff --git a/app/models/concerns/has_attributes.rb b/app/models/concerns/has_attributes.rb index 166a840b..dfcbb1c4 100644 --- a/app/models/concerns/has_attributes.rb +++ b/app/models/concerns/has_attributes.rb @@ -31,7 +31,7 @@ module HasAttributes user: user, field_type: field[:field_type].presence || "text_area" ) - af_field.save! if user + af_field.save if user af_field end if details.key?(:attributes) diff --git a/app/models/concerns/has_changelog.rb b/app/models/concerns/has_changelog.rb index 0443171c..cf82b475 100644 --- a/app/models/concerns/has_changelog.rb +++ b/app/models/concerns/has_changelog.rb @@ -4,6 +4,8 @@ module HasChangelog extend ActiveSupport::Concern included do + attr_accessor :disable_changelog_this_request + def content_change_events ContentChangeEvent.where( content_id: id, @@ -28,7 +30,7 @@ module HasChangelog content_id: id, content_type: self.class.name, action: :created - ) if changes.any? + ) if changes.any? && !!disable_changelog_this_request end before_update do @@ -39,7 +41,7 @@ module HasChangelog content_id: id, content_type: self.class.name, action: :updated - ) if changes.any? + ) if changes.any? && !!disable_changelog_this_request end before_destroy do @@ -49,7 +51,7 @@ module HasChangelog content_id: id, content_type: self.class.name, action: :deleted - ) + ) if !!disable_changelog_this_request end private