Fully address AR callback issues
This commit is contained in:
parent
f4c0216812
commit
42518a1323
2 changed files with 9 additions and 16 deletions
|
|
@ -25,7 +25,7 @@ module TrackSavedChanges
|
||||||
# on save
|
# on save
|
||||||
def ts_track_saved_changes
|
def ts_track_saved_changes
|
||||||
# maintain an array of ActiveModel::Dirty.changes
|
# maintain an array of ActiveModel::Dirty.changes
|
||||||
@ts_saved_changes_history << changes.dup
|
@ts_saved_changes_history << previous_changes.dup
|
||||||
# accumulate the most recent changes
|
# accumulate the most recent changes
|
||||||
@ts_saved_changes_history.last.each_pair { |k, v| ts_track_saved_change k, v }
|
@ts_saved_changes_history.last.each_pair { |k, v| ts_track_saved_change k, v }
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -81,15 +81,11 @@ class User < ApplicationRecord
|
||||||
|
|
||||||
after_save :touch_events
|
after_save :touch_events
|
||||||
|
|
||||||
after_create_commit :mailbluster_create_lead
|
# after_create_commit :mailbluster_create_lead
|
||||||
after_destroy_commit :mailbluster_delete_lead
|
after_commit :mailbluster_create_lead, on: :create
|
||||||
# Note that because a commit may cause multiple changes
|
# after_destroy_commit :mailbluster_delete_lead
|
||||||
# which are not fully tracked by ActiveRecord::Dirty,
|
after_commit :mailbluster_delete_lead, on: :destroy
|
||||||
# we must resort to using a ActiveRecord::Concern which accumulates
|
after_commit :mailbluster_update_lead, on: :update, if: ->(user){ ['name','email'].any? { |key| user.ts_saved_changes.key? key } }
|
||||||
# changes from a commit (app/models/concerns/track_saved_changes.rb)
|
|
||||||
# See https://github.com/ccmcbeck/after-commit
|
|
||||||
after_update_commit :mailbluster_update_email, if: ->(obj){ obj.ts_saved_changes.key? 'email' }
|
|
||||||
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)}
|
||||||
|
|
@ -391,12 +387,9 @@ class User < ApplicationRecord
|
||||||
MailblusterDeleteLeadJob.perform_later self
|
MailblusterDeleteLeadJob.perform_later self
|
||||||
end
|
end
|
||||||
|
|
||||||
def mailbluster_update_email
|
def mailbluster_update_lead
|
||||||
MailblusterEditLeadJob.perform_later(self, old_email: saved_changes['email'][0])
|
MailblusterEditLeadJob.perform_later(self, old_email: ts_saved_changes.fetch('email', [nil])[0])
|
||||||
end
|
ts_reset_saved_changes
|
||||||
|
|
||||||
def mailbluster_update_name
|
|
||||||
MailblusterEditLeadJob.perform_later self
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def touch_events
|
def touch_events
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue