The personal finance app for everyone (by everyone)
Ruby
Include newer providers in automatic family sync (#934)
David Gil28d99a2b0d48
diff --git a/app/models/coinbase_item.rb b/app/models/coinbase_item.rbindex f67aeb7534..6641958e61 100644--- a/app/models/coinbase_item.rb+++ b/app/models/coinbase_item.rb@@ -30,6 +30,7 @@ class CoinbaseItem < ApplicationRecordhas_many :accounts, through: :coinbase_accountsscope :active, -> { where(scheduled_for_deletion: false) }+ scope :syncable, -> { active }scope :ordered, -> { order(created_at: :desc) }scope :needs_update, -> { where(status: :requires_update) }diff --git a/app/models/coinstats_item.rb b/app/models/coinstats_item.rbindex c2c9f51fd1..6df76bf704 100644--- a/app/models/coinstats_item.rb+++ b/app/models/coinstats_item.rb@@ -28,6 +28,7 @@ class CoinstatsItem < ApplicationRecordhas_many :accounts, through: :coinstats_accountsscope :active, -> { where(scheduled_for_deletion: false) }+ scope :syncable, -> { active }scope :ordered, -> { order(created_at: :desc) }scope :needs_update, -> { where(status: :requires_update) }diff --git a/app/models/enable_banking_item.rb b/app/models/enable_banking_item.rbindex 7de761bde7..d1e8684c97 100644--- a/app/models/enable_banking_item.rb+++ b/app/models/enable_banking_item.rb@@ -23,6 +23,7 @@ class EnableBankingItem < ApplicationRecordhas_many :accounts, through: :enable_banking_accountsscope :active, -> { where(scheduled_for_deletion: false) }+ scope :syncable, -> { active }scope :ordered, -> { order(created_at: :desc) }scope :needs_update, -> { where(status: :requires_update) }diff --git a/app/models/family/syncer.rb b/app/models/family/syncer.rbindex 80d910cc1d..858ed9bc4a 100644--- a/app/models/family/syncer.rb+++ b/app/models/family/syncer.rb@@ -1,6 +1,25 @@class Family::Syncerattr_reader :family+ # Registry of item association names that participate in family sync.+ # Each model must:+ # 1. Include Syncable+ # 2. Define a `syncable` scope (items ready for auto-sync)+ #+ # To add a new provider: add its association name here.+ # The model handles its own "ready to sync" logic via the syncable scope.+ SYNCABLE_ITEM_ASSOCIATIONS = %i[+ plaid_items+ simplefin_items+ lunchflow_items+ enable_banking_items+ indexa_capital_items+ coinbase_items+ coinstats_items+ mercury_items+ snaptrade_items+ ].freeze+def initialize(family)@family = familyend@@ -25,7 +44,15 @@ class Family::Syncerendprivate++ # Collects all syncable items from registered providers + manual accounts.+ # Each provider model defines its own `syncable` scope that encapsulates+ # the "ready to sync" business logic (active, configured, etc.)def child_syncables- family.plaid_items + family.simplefin_items.active + family.lunchflow_items.active + family.enable_banking_items.active + family.indexa_capital_items + family.accounts.manual+ provider_items = SYNCABLE_ITEM_ASSOCIATIONS.flat_map do |association|+ family.public_send(association).syncable+ end++ provider_items + family.accounts.manualendenddiff --git a/app/models/indexa_capital_item.rb b/app/models/indexa_capital_item.rbindex 8272a256e3..ccea401b46 100644--- a/app/models/indexa_capital_item.rb+++ b/app/models/indexa_capital_item.rb@@ -30,6 +30,7 @@ class IndexaCapitalItem < ApplicationRecordhas_many :accounts, through: :indexa_capital_accountsscope :active, -> { where(scheduled_for_deletion: false) }+ scope :syncable, -> { active }scope :ordered, -> { order(created_at: :desc) }scope :needs_update, -> { where(status: :requires_update) }diff --git a/app/models/lunchflow_item.rb b/app/models/lunchflow_item.rbindex 1165ba8361..ba9830c6b3 100644--- a/app/models/lunchflow_item.rb+++ b/app/models/lunchflow_item.rb@@ -20,6 +20,7 @@ class LunchflowItem < ApplicationRecordhas_many :accounts, through: :lunchflow_accountsscope :active, -> { where(scheduled_for_deletion: false) }+ scope :syncable, -> { active }scope :ordered, -> { order(created_at: :desc) }scope :needs_update, -> { where(status: :requires_update) }diff --git a/app/models/mercury_item.rb b/app/models/mercury_item.rbindex 2c781265ac..eb062b2b91 100644--- a/app/models/mercury_item.rb+++ b/app/models/mercury_item.rb@@ -27,6 +27,7 @@ class MercuryItem < ApplicationRecordhas_many :accounts, through: :mercury_accountsscope :active, -> { where(scheduled_for_deletion: false) }+ scope :syncable, -> { active }scope :ordered, -> { order(created_at: :desc) }scope :needs_update, -> { where(status: :requires_update) }diff --git a/app/models/plaid_item.rb b/app/models/plaid_item.rbindex 4ac59d0cfd..58e39bae24 100644--- a/app/models/plaid_item.rb+++ b/app/models/plaid_item.rb@@ -23,6 +23,7 @@ class PlaidItem < ApplicationRecordhas_many :legacy_accounts, through: :plaid_accounts, source: :accountscope :active, -> { where(scheduled_for_deletion: false) }+ scope :syncable, -> { active }scope :ordered, -> { order(created_at: :desc) }scope :needs_update, -> { where(status: :requires_update) }diff --git a/app/models/simplefin_item.rb b/app/models/simplefin_item.rbindex 253b6098c3..4483393f4c 100644--- a/app/models/simplefin_item.rb+++ b/app/models/simplefin_item.rb@@ -26,6 +26,7 @@ class SimplefinItem < ApplicationRecordhas_many :legacy_accounts, through: :simplefin_accounts, source: :accountscope :active, -> { where(scheduled_for_deletion: false) }+ scope :syncable, -> { active }scope :ordered, -> { order(created_at: :desc) }scope :needs_update, -> { where(status: :requires_update) }diff --git a/app/models/snaptrade_item.rb b/app/models/snaptrade_item.rbindex 0c627d7d3e..f99c763f64 100644--- a/app/models/snaptrade_item.rb+++ b/app/models/snaptrade_item.rb@@ -35,6 +35,9 @@ class SnaptradeItem < ApplicationRecordhas_many :linked_accounts, through: :snaptrade_accountsscope :active, -> { where(scheduled_for_deletion: false) }+ # Syncable = active + fully configured (user registered with SnapTrade API)+ # Items without user registration will fail sync, so exclude them from auto-sync+ scope :syncable, -> { active.where.not(snaptrade_user_id: [ nil, "" ]).where.not(snaptrade_user_secret: [ nil, "" ]) }scope :ordered, -> { order(created_at: :desc) }scope :needs_update, -> { where(status: :requires_update) }