e51f0bfee7
Account incineration could leave orphaned records due to missing cascade declarations and async jobs failing when the account was already gone. Cascade fixes: - Add Account::Searchable concern to clean up Search::Query (delete_all) and Search::Record (destroy_all, respects SQLite FTS dependent: :destroy) - Add before_destroy in Account::Storage to delete storage entries - Suppress storage entry recording during incineration so attachment purge callbacks don't create entries or enqueue materialize jobs - Guard Access#clean_inaccessible_data_later with unless user.destroyed? to avoid enqueuing pointless jobs during user cascade Job tenancy: - Extract AccountTenanted concern from the global ActiveJob initializer into ApplicationJob (include) with targeted prepends for ActionMailer::MailDeliveryJob and Turbo broadcast jobs - Defer account resolution from deserialize to perform so that missing accounts raise DeserializationError inside the execution path where discard_on can handle it Tests: - Comprehensive incineration test covering 35 model types with before/after assertions and full enqueued job processing - Mailer deliver_later test verifying account context survives job serialization for multi-account users - Turbo broadcast test verifying account-scoped URLs in rendered partials
25 lines
660 B
Ruby
25 lines
660 B
Ruby
class Access < ApplicationRecord
|
|
belongs_to :account, default: -> { user.account }
|
|
belongs_to :board, touch: true
|
|
belongs_to :user, touch: true
|
|
|
|
enum :involvement, %i[ access_only watching ].index_by(&:itself), default: :access_only
|
|
|
|
scope :ordered_by_recently_accessed, -> { order(accessed_at: :desc) }
|
|
|
|
after_destroy_commit :clean_inaccessible_data_later
|
|
|
|
def accessed
|
|
touch :accessed_at unless recently_accessed?
|
|
end
|
|
|
|
private
|
|
def recently_accessed?
|
|
accessed_at&.> 5.minutes.ago
|
|
end
|
|
|
|
def clean_inaccessible_data_later
|
|
Board::CleanInaccessibleDataJob.perform_later(user, board) unless user.destroyed?
|
|
end
|
|
end
|