mirror of https://github.com/mastodon/mastodon
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.6 KiB
Ruby
66 lines
1.6 KiB
Ruby
3 years ago
|
# frozen_string_literal: true
|
||
|
|
||
3 years ago
|
class Trends::PreviewCardBatch
|
||
3 years ago
|
include ActiveModel::Model
|
||
|
include Authorization
|
||
|
|
||
|
attr_accessor :preview_card_ids, :action, :current_account, :precision
|
||
|
|
||
|
def save
|
||
|
case action
|
||
|
when 'approve'
|
||
|
approve!
|
||
3 years ago
|
when 'approve_providers'
|
||
|
approve_providers!
|
||
3 years ago
|
when 'reject'
|
||
|
reject!
|
||
3 years ago
|
when 'reject_providers'
|
||
|
reject_providers!
|
||
3 years ago
|
end
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def preview_cards
|
||
|
@preview_cards ||= PreviewCard.where(id: preview_card_ids)
|
||
|
end
|
||
|
|
||
|
def preview_card_providers
|
||
|
@preview_card_providers ||= preview_cards.map(&:domain).uniq.map { |domain| PreviewCardProvider.matching_domain(domain) || PreviewCardProvider.new(domain: domain) }
|
||
|
end
|
||
|
|
||
|
def approve!
|
||
3 years ago
|
preview_cards.each { |preview_card| authorize(preview_card, :review?) }
|
||
3 years ago
|
preview_cards.update_all(trendable: true)
|
||
|
end
|
||
|
|
||
3 years ago
|
def approve_providers!
|
||
3 years ago
|
preview_card_providers.each do |provider|
|
||
3 years ago
|
authorize(provider, :review?)
|
||
3 years ago
|
provider.update(trendable: true, reviewed_at: action_time)
|
||
|
end
|
||
|
|
||
|
# Reset any individual overrides
|
||
|
preview_cards.update_all(trendable: nil)
|
||
|
end
|
||
|
|
||
|
def reject!
|
||
3 years ago
|
preview_cards.each { |preview_card| authorize(preview_card, :review?) }
|
||
3 years ago
|
preview_cards.update_all(trendable: false)
|
||
|
end
|
||
|
|
||
3 years ago
|
def reject_providers!
|
||
3 years ago
|
preview_card_providers.each do |provider|
|
||
3 years ago
|
authorize(provider, :review?)
|
||
3 years ago
|
provider.update(trendable: false, reviewed_at: action_time)
|
||
|
end
|
||
|
|
||
|
# Reset any individual overrides
|
||
|
preview_cards.update_all(trendable: nil)
|
||
|
end
|
||
|
|
||
|
def action_time
|
||
|
@action_time ||= Time.now.utc
|
||
|
end
|
||
|
end
|