mirror of
https://github.com/we-promise/sure.git
synced 2026-08-05 16:42:18 +00:00
* First pass of Akahu * fix up sync all * conflicts * fix db migration issue? - fix auto selection of akahu account type * Address Akahu PR feedback * Complete provider metadata * Fix PR 1921 CI tests * PR feedback * PR feedback * post merge --------- Co-authored-by: failing <failing@users.noreply.github.com> Co-authored-by: Juan José Mata <jjmata@jjmata.com> Co-authored-by: sure-admin <sure-admin@splashblot.com>
40 lines
1.1 KiB
Ruby
40 lines
1.1 KiB
Ruby
module AkahuItem::Unlinking
|
|
extend ActiveSupport::Concern
|
|
|
|
def unlink_all!(dry_run: false)
|
|
results = []
|
|
|
|
akahu_accounts.find_each do |provider_account|
|
|
links = AccountProvider.joins(:account)
|
|
.where(provider: provider_account, accounts: { family_id: family_id })
|
|
.to_a
|
|
link_ids = links.map(&:id)
|
|
result = {
|
|
provider_account_id: provider_account.id,
|
|
name: provider_account.name,
|
|
provider_link_ids: link_ids
|
|
}
|
|
results << result
|
|
|
|
next if dry_run
|
|
|
|
begin
|
|
ActiveRecord::Base.transaction do
|
|
links.each do |link|
|
|
Holding.where(account_id: link.account_id, account_provider_id: link.id).update_all(account_provider_id: nil)
|
|
link.destroy!
|
|
end
|
|
end
|
|
rescue StandardError => e
|
|
Rails.logger.warn(
|
|
"AkahuItem Unlinker: failed to fully unlink provider account ##{provider_account.id} " \
|
|
"(links=#{link_ids.inspect}): #{e.class} - #{e.message}"
|
|
)
|
|
result[:error] = e.message
|
|
end
|
|
end
|
|
|
|
results
|
|
end
|
|
end
|