2019-09-09 10:50:09 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-02-24 23:34:14 +00:00
|
|
|
class Trends::TagBatch
|
2019-09-09 10:50:09 +00:00
|
|
|
include ActiveModel::Model
|
|
|
|
include Authorization
|
|
|
|
|
|
|
|
attr_accessor :tag_ids, :action, :current_account
|
|
|
|
|
|
|
|
def save
|
|
|
|
case action
|
|
|
|
when 'approve'
|
|
|
|
approve!
|
|
|
|
when 'reject'
|
|
|
|
reject!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def tags
|
|
|
|
Tag.where(id: tag_ids)
|
|
|
|
end
|
|
|
|
|
|
|
|
def approve!
|
2022-02-24 23:34:14 +00:00
|
|
|
tags.each { |tag| authorize(tag, :review?) }
|
2021-11-25 12:07:38 +00:00
|
|
|
tags.update_all(trendable: true, reviewed_at: action_time)
|
2019-09-09 10:50:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def reject!
|
2022-02-24 23:34:14 +00:00
|
|
|
tags.each { |tag| authorize(tag, :review?) }
|
2021-11-25 12:07:38 +00:00
|
|
|
tags.update_all(trendable: false, reviewed_at: action_time)
|
|
|
|
end
|
|
|
|
|
|
|
|
def action_time
|
|
|
|
@action_time ||= Time.now.utc
|
2019-09-09 10:50:09 +00:00
|
|
|
end
|
|
|
|
end
|