Remove name conflict change which caused PaperTrail to fail
This commit is contained in:
parent
5aa24ee261
commit
f4c0216812
2 changed files with 18 additions and 18 deletions
|
|
@ -4,43 +4,43 @@ module TrackSavedChanges
|
||||||
|
|
||||||
included do
|
included do
|
||||||
# expose the details if consumer wants to do more
|
# expose the details if consumer wants to do more
|
||||||
attr_reader :saved_changes_history, :saved_changes_unfiltered
|
# attr_reader :ts_saved_changes_history, :ts_saved_changes_unfiltered
|
||||||
after_initialize :reset_saved_changes
|
after_initialize :ts_reset_saved_changes
|
||||||
after_save :track_saved_changes
|
after_save :ts_track_saved_changes
|
||||||
end
|
end
|
||||||
|
|
||||||
# on initalize, but useful for fine grain control
|
# on initalize, but useful for fine grain control
|
||||||
def reset_saved_changes
|
def ts_reset_saved_changes
|
||||||
@saved_changes_unfiltered = {}
|
@ts_saved_changes_unfiltered = {}
|
||||||
@saved_changes_history = []
|
@ts_saved_changes_history = []
|
||||||
end
|
end
|
||||||
|
|
||||||
# filter out any changes that result in the original value
|
# filter out any changes that result in the original value
|
||||||
def saved_changes
|
def ts_saved_changes
|
||||||
@saved_changes_unfiltered.reject { |_k, v| v[0] == v[1] }
|
@ts_saved_changes_unfiltered.reject { |_k, v| v[0] == v[1] }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# on save
|
# on save
|
||||||
def track_saved_changes
|
def ts_track_saved_changes
|
||||||
# maintain an array of ActiveModel::Dirty.changes
|
# maintain an array of ActiveModel::Dirty.changes
|
||||||
@saved_changes_history << changes.dup
|
@ts_saved_changes_history << changes.dup
|
||||||
# accumulate the most recent changes
|
# accumulate the most recent changes
|
||||||
@saved_changes_history.last.each_pair { |k, v| track_saved_change k, v }
|
@ts_saved_changes_history.last.each_pair { |k, v| ts_track_saved_change k, v }
|
||||||
end
|
end
|
||||||
|
|
||||||
# v is an an array of [prev, current]
|
# v is an an array of [prev, current]
|
||||||
def track_saved_change(key, value)
|
def ts_track_saved_change(key, value)
|
||||||
if @saved_changes_unfiltered.key? key
|
if @ts_saved_changes_unfiltered.key? key
|
||||||
@saved_changes_unfiltered[key][1] = track_saved_value value[1]
|
@ts_saved_changes_unfiltered[key][1] = ts_track_saved_value value[1]
|
||||||
else
|
else
|
||||||
@saved_changes_unfiltered[key] = value.dup
|
@ts_saved_changes_unfiltered[key] = value.dup
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# type safe dup inspred by http://stackoverflow.com/a/20955038
|
# type safe dup inspred by http://stackoverflow.com/a/20955038
|
||||||
def track_saved_value(value)
|
def ts_track_saved_value(value)
|
||||||
value.dup
|
value.dup
|
||||||
rescue TypeError
|
rescue TypeError
|
||||||
value
|
value
|
||||||
|
|
|
||||||
|
|
@ -88,8 +88,8 @@ class User < ApplicationRecord
|
||||||
# we must resort to using a ActiveRecord::Concern which accumulates
|
# we must resort to using a ActiveRecord::Concern which accumulates
|
||||||
# changes from a commit (app/models/concerns/track_saved_changes.rb)
|
# changes from a commit (app/models/concerns/track_saved_changes.rb)
|
||||||
# See https://github.com/ccmcbeck/after-commit
|
# See https://github.com/ccmcbeck/after-commit
|
||||||
after_update_commit :mailbluster_update_email, if: ->(obj){ obj.saved_changes.key? 'email' }
|
after_update_commit :mailbluster_update_email, if: ->(obj){ obj.ts_saved_changes.key? 'email' }
|
||||||
after_update_commit :mailbluster_update_name, if: ->(obj){ obj.saved_changes.key? 'name' }
|
after_update_commit :mailbluster_update_name, if: ->(obj){ obj.ts_saved_changes.key? 'name' }
|
||||||
|
|
||||||
# add scope
|
# add scope
|
||||||
scope :comment_notifiable, ->(conference) {joins(:roles).where('roles.name IN (?)', [:organizer, :cfp]).where('roles.resource_type = ? AND roles.resource_id = ?', 'Conference', conference.id)}
|
scope :comment_notifiable, ->(conference) {joins(:roles).where('roles.name IN (?)', [:organizer, :cfp]).where('roles.resource_type = ? AND roles.resource_id = ?', 'Conference', conference.id)}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue