2021-11-25 07:07:38 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-02-24 18:34:14 -05:00
|
|
|
class Trends::PreviewCardProviderBatch
|
2021-11-25 07:07:38 -05:00
|
|
|
include ActiveModel::Model
|
|
|
|
include Authorization
|
|
|
|
|
|
|
|
attr_accessor :preview_card_provider_ids, :action, :current_account
|
|
|
|
|
|
|
|
def save
|
|
|
|
case action
|
|
|
|
when 'approve'
|
|
|
|
approve!
|
|
|
|
when 'reject'
|
|
|
|
reject!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def preview_card_providers
|
|
|
|
PreviewCardProvider.where(id: preview_card_provider_ids)
|
|
|
|
end
|
|
|
|
|
|
|
|
def approve!
|
2022-02-24 18:34:14 -05:00
|
|
|
preview_card_providers.each { |provider| authorize(provider, :review?) }
|
2021-11-25 07:07:38 -05:00
|
|
|
preview_card_providers.update_all(trendable: true, reviewed_at: Time.now.utc)
|
|
|
|
end
|
|
|
|
|
|
|
|
def reject!
|
2022-02-24 18:34:14 -05:00
|
|
|
preview_card_providers.each { |provider| authorize(provider, :review?) }
|
2021-11-25 07:07:38 -05:00
|
|
|
preview_card_providers.update_all(trendable: false, reviewed_at: Time.now.utc)
|
|
|
|
end
|
|
|
|
end
|