Skip to content

Commit 2de1de3

Browse files
authored
Create missing webhook trackers on import (#3294)
The import writes webhooks with insert_all!, so the after_create that gives each webhook its delinquency tracker never runs. An archive with no tracker files left webhooks whose every delivery failed on a nil tracker. The tracker only holds a failure streak, and a new one is the state a new webhook starts in. So after the record sets run, create a tracker for any imported webhook that lacks one, as is done for user settings. Co-authored-by: Kevin McConnell (agent) <348858099+kmc-agent@users.noreply.github.com>
1 parent 3cc736b commit 2de1de3

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎app/models/account/import.rb‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def process(start: nil, callback: nil)
6161

6262
add_importer_to_all_access_boards
6363
create_missing_user_settings
64+
create_missing_webhook_delinquency_trackers
6465
reconcile_cards_count
6566
reconcile_account_storage
6667

@@ -139,6 +140,10 @@ def create_missing_user_settings
139140
account.users.where.not(role: :system).where.missing(:settings).find_each(&:create_settings!)
140141
end
141142

143+
def create_missing_webhook_delinquency_trackers
144+
account.webhooks.where.missing(:delinquency_tracker).find_each(&:create_delinquency_tracker!)
145+
end
146+
142147
def reconcile_account_storage
143148
account.boards.each(&:reconcile_storage)
144149
account.reconcile_storage

‎test/models/account/import_test.rb‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,41 @@ class Account::ImportTest < ActiveSupport::TestCase
102102
stripped_tempfile&.unlink
103103
end
104104

105+
test "import creates delinquency trackers for webhooks whose export carried none" do
106+
source_account = accounts("37s")
107+
exporter = users(:david)
108+
identity = exporter.identity
109+
webhook_ids = source_account.webhooks.ids
110+
111+
export = Account::Export.create!(account: source_account, user: exporter)
112+
export.build
113+
114+
export_tempfile = Tempfile.new([ "export", ".zip" ])
115+
export.file.open { |f| FileUtils.cp(f.path, export_tempfile.path) }
116+
117+
stripped_tempfile = zip_without(export_tempfile.path, "data/webhook_delinquency_trackers/*")
118+
119+
source_account.destroy!
120+
121+
target_account = Account.create_with_owner(account: { name: "Import Test" }, owner: { identity: identity, name: exporter.name })
122+
import = Account::Import.create!(identity: identity, account: target_account)
123+
Current.set(account: target_account) do
124+
import.file.attach(io: File.open(stripped_tempfile.path), filename: "export.zip", content_type: "application/zip")
125+
end
126+
127+
import.check
128+
import.process
129+
130+
assert import.completed?
131+
assert_not_empty webhook_ids
132+
assert_equal webhook_ids.sort, Webhook::DelinquencyTracker.where(account: target_account).pluck(:webhook_id).sort
133+
ensure
134+
export_tempfile&.close
135+
export_tempfile&.unlink
136+
stripped_tempfile&.close
137+
stripped_tempfile&.unlink
138+
end
139+
105140
test "import caps a join code usage limit saved before the cap existed" do
106141
source_account = accounts("37s")
107142
exporter = users(:david)

0 commit comments

Comments
 (0)